rmdir(2) claims
[openafs.git] / src / afs / LINUX / osi_vnodeops.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * Linux specific vnodeops. Also includes the glue routines required to call
12  * AFS vnodeops. The "NOTUSED" #define is used to indicate routines and
13  * calling sequences present in an ops table that we don't actually use.
14  * They are present solely for documentation purposes.
15  *
16  * So far the only truly scary part is that Linux relies on the inode cache
17  * to be up to date. Don't you dare break a callback and expect an fstat
18  * to give you meaningful information. This appears to be fixed in the 2.1
19  * development kernels. As it is we can fix this now by intercepting the 
20  * stat calls.
21  */
22
23 #include "../afs/param.h"
24 #include "../afs/sysincludes.h"
25 #include "../afs/afsincludes.h"
26 #include "../afs/afs_stats.h"
27 #include "../h/mm.h"
28 #include "../h/pagemap.h"
29 #if defined(AFS_LINUX24_ENV)
30 #include "../h/smp_lock.h"
31 #endif
32
33 #ifdef pgoff2loff
34 #define pageoff(pp) pgoff2loff((pp)->index)
35 #else
36 #define pageoff(pp) pp->offset
37 #endif
38
39 extern struct vcache *afs_globalVp;
40
41 extern struct dentry_operations *afs_dops;
42 #if defined(AFS_LINUX24_ENV)
43 extern struct inode_operations afs_file_iops;
44 extern struct address_space_operations afs_file_aops;
45 struct address_space_operations afs_symlink_aops;
46 #endif
47 extern struct inode_operations afs_dir_iops;
48 extern struct inode_operations afs_symlink_iops;
49
50
51 #ifdef NOTUSED
52 static int afs_linux_lseek(struct inode *ip, struct file *fp, off_t, int) {}
53 #endif
54
55 static ssize_t afs_linux_read(struct file *fp, char *buf, size_t count,
56                               loff_t *offp)
57 {
58     ssize_t code;
59     struct vcache *vcp = (struct vcache*)fp->f_dentry->d_inode;
60     cred_t *credp = crref();
61     struct vrequest treq;
62
63     AFS_GLOCK();
64     afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
65                ICL_TYPE_INT32, (int)*offp,
66                ICL_TYPE_INT32, count,
67                ICL_TYPE_INT32, 99999);
68
69     /* get a validated vcache entry */
70     code = afs_InitReq(&treq, credp);
71     if (!code)
72         code = afs_VerifyVCache(vcp, &treq);
73
74     if (code)
75         code = -code;
76     else {
77         osi_FlushPages(vcp, credp);     /* ensure stale pages are gone */
78         AFS_GUNLOCK();
79         code = generic_file_read(fp, buf, count, offp);
80         AFS_GLOCK();
81     }
82
83     afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
84                ICL_TYPE_INT32, (int)*offp,
85                ICL_TYPE_INT32, count,
86                ICL_TYPE_INT32, code);
87
88     AFS_GUNLOCK();
89     crfree(credp);
90     return code;
91 }
92
93
94 /* Now we have integrated VM for writes as well as reads. generic_file_write
95  * also takes care of re-positioning the pointer if file is open in append
96  * mode. Call fake open/close to ensure we do writes of core dumps.
97  */
98 static ssize_t afs_linux_write(struct file *fp, const char *buf, size_t count,
99                            loff_t *offp)
100 {
101     ssize_t code = 0;
102     int code2;
103     struct vcache *vcp = (struct vcache *)fp->f_dentry->d_inode;
104     struct vrequest treq;
105     cred_t *credp = crref();
106
107     AFS_GLOCK();
108
109     afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
110                ICL_TYPE_INT32, (int)*offp, ICL_TYPE_INT32, count,
111                ICL_TYPE_INT32, (fp->f_flags & O_APPEND) ? 99998 : 99999);
112
113
114     /* get a validated vcache entry */
115     code = (ssize_t)afs_InitReq(&treq, credp);
116     if (!code)
117         code = (ssize_t)afs_VerifyVCache(vcp, &treq);
118
119     ObtainWriteLock(&vcp->lock, 529);
120     afs_FakeOpen(vcp);
121     ReleaseWriteLock(&vcp->lock);
122     AFS_GUNLOCK();
123     if (code)
124         code = -code;
125     else {
126         code = generic_file_write(fp, buf, count, offp);
127     }
128     AFS_GLOCK();
129
130     ObtainWriteLock(&vcp->lock, 530);
131     vcp->m.Date = osi_Time(); /* set modification time */
132     afs_FakeClose(vcp, credp);
133     if (code>=0)
134         code2 = afs_DoPartialWrite(vcp, &treq);
135     if (code2 && code >=0)
136         code = (ssize_t) -code2;
137     ReleaseWriteLock(&vcp->lock);
138         
139     afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
140                ICL_TYPE_INT32, (int)*offp, ICL_TYPE_INT32, count,
141                ICL_TYPE_INT32, code);
142
143     AFS_GUNLOCK();
144     crfree(credp);
145     return code;
146 }
147
148 /* This is a complete rewrite of afs_readdir, since we can make use of
149  * filldir instead of afs_readdir_move. Note that changes to vcache/dcache
150  * handling and use of bulkstats will need to be reflected here as well.
151  */
152 static int afs_linux_readdir(struct file *fp,
153                              void *dirbuf, filldir_t filldir)
154 {
155     extern struct DirEntry * afs_dir_GetBlob();
156     struct vcache *avc = (struct vcache*)FILE_INODE(fp);
157     struct vrequest treq;
158     register struct dcache *tdc;
159     int code;
160     int offset;
161     int dirpos;
162     struct DirEntry *de;
163     ino_t ino;
164     int len;
165     int origOffset;
166     cred_t *credp = crref();
167
168     AFS_GLOCK();
169     AFS_STATCNT(afs_readdir);
170
171     code = afs_InitReq(&treq, credp);
172     crfree(credp);
173     if (code) {
174         AFS_GUNLOCK();
175         return -code;
176     }
177
178     /* update the cache entry */
179 tagain:
180     code = afs_VerifyVCache(avc, &treq);
181     if (code) {
182         AFS_GUNLOCK();
183         return -code;
184     }
185
186     /* get a reference to the entire directory */
187     tdc = afs_GetDCache(avc, 0, &treq, &origOffset, &len, 1);
188     if (!tdc) {
189         AFS_GUNLOCK();
190         return -ENOENT;
191     }
192     ObtainReadLock(&avc->lock);
193     /*
194      * Make sure that the data in the cache is current. There are two
195      * cases we need to worry about:
196      * 1. The cache data is being fetched by another process.
197      * 2. The cache data is no longer valid
198      */
199     while ((avc->states & CStatd)
200            && (tdc->flags & DFFetching)
201            && hsame(avc->m.DataVersion, tdc->f.versionNo)) {
202         tdc->flags |= DFWaiting;
203         ReleaseReadLock(&avc->lock);
204         afs_osi_Sleep(&tdc->validPos);
205         ObtainReadLock(&avc->lock);
206     }
207     if (!(avc->states & CStatd)
208         || !hsame(avc->m.DataVersion, tdc->f.versionNo)) {
209         ReleaseReadLock(&avc->lock);
210         afs_PutDCache(tdc);
211         goto tagain;
212     }
213
214     /* Fill in until we get an error or we're done. This implementation
215      * takes an offset in units of blobs, rather than bytes.
216      */
217     code = 0;
218     offset = (int)fp->f_pos;
219     while(1) { 
220         dirpos = BlobScan(&tdc->f.inode, offset);
221         if (!dirpos)
222             break;
223
224         de = (struct DirEntry*)afs_dir_GetBlob(&tdc->f.inode, dirpos);
225         if (!de)
226             break;
227
228         ino = (avc->fid.Fid.Volume << 16) + ntohl(de->fid.vnode);
229         ino &= 0x7fffffff; /* Assumes 32 bit ino_t ..... */
230         len = strlen(de->name);
231
232         /* filldir returns -EINVAL when the buffer is full. */
233 #ifdef AFS_LINUX24_ENV
234         {
235              unsigned int type=DT_UNKNOWN;
236              struct VenusFid afid;
237              struct vcache *tvc;
238              int vtype;
239              afid.Cell=avc->fid.Cell;
240              afid.Fid.Volume=avc->fid.Fid.Volume;
241              afid.Fid.Vnode=ntohl(de->fid.vnode);
242              afid.Fid.Unique=ntohl(de->fid.vunique);
243              if ((avc->states & CForeign) == 0 &&
244                  (ntohl(de->fid.vnode) & 1)) {
245                   type=DT_DIR;
246              } else if ((tvc=afs_FindVCache(&afid,0,0,0,0))) {
247                   if (tvc->mvstat) {
248                        type=DT_DIR;
249                   } else if (((tvc->states) & (CStatd|CTruth))) {
250                        /* CTruth will be set if the object has 
251                         *ever* been statd */
252                        vtype=vType(tvc);
253                        if (vtype == VDIR)
254                             type=DT_DIR;
255                        else if (vtype == VREG)
256                             type=DT_REG;
257                        /* Don't do this until we're sure it can't be a mtpt */
258                        /* else if (vtype == VLNK)
259                           type=DT_LNK; */
260                        /* what other types does AFS support? */
261                   }
262              }
263              code = (*filldir)(dirbuf, de->name, len, offset, ino, type);
264         }
265 #else
266         code = (*filldir)(dirbuf, de->name, len, offset, ino); 
267 #endif
268         DRelease(de, 0);
269         if (code)
270             break;
271         offset = dirpos + 1 + ((len+16)>>5);
272     }
273     /* If filldir didn't fill in the last one this is still pointing to that
274      * last attempt.
275      */
276     fp->f_pos = (loff_t)offset;
277
278     afs_PutDCache(tdc);
279     ReleaseReadLock(&avc->lock);
280     AFS_GUNLOCK();
281     return 0;
282 }
283
284 #ifdef NOTUSED
285 int afs_linux_select(struct inode *ip, struct file *fp, int, select_table *);
286 #endif
287
288 /* in afs_pioctl.c */
289 extern int afs_xioctl(struct inode *ip, struct file *fp,
290                           unsigned int com, unsigned long arg);
291
292
293 /* We need to detect unmap's after close. To do that, we need our own
294  * vm_operations_struct's. And we need to set them up for both the
295  * private and shared mappings. The fun part is that these are all static
296  * so we'll have to initialize on the fly!
297  */
298 static struct vm_operations_struct afs_private_mmap_ops;
299 static int afs_private_mmap_ops_inited = 0;
300 static struct vm_operations_struct afs_shared_mmap_ops;
301 static int afs_shared_mmap_ops_inited = 0;
302
303 void afs_linux_vma_close(struct vm_area_struct *vmap)
304 {
305     struct vcache *vcp;
306     cred_t *credp;
307
308     if (!vmap->vm_file)
309         return;
310
311     vcp = (struct vcache*)FILE_INODE(vmap->vm_file);
312     if (!vcp)
313         return;
314
315     AFS_GLOCK();
316     afs_Trace4(afs_iclSetp, CM_TRACE_VM_CLOSE,
317                ICL_TYPE_POINTER, vcp,
318                ICL_TYPE_INT32, vcp->mapcnt,
319                ICL_TYPE_INT32, vcp->opens,
320                ICL_TYPE_INT32, vcp->execsOrWriters);
321     ObtainWriteLock(&vcp->lock, 532);
322     if (vcp->mapcnt) {
323         vcp->mapcnt--;
324         ReleaseWriteLock(&vcp->lock);
325         if (!vcp->mapcnt) {
326             credp = crref();
327             (void) afs_close(vcp, vmap->vm_file->f_flags, credp);
328             /* only decrement the execsOrWriters flag if this is not a writable
329              * file. */
330             if (! (vmap->vm_file->f_flags & (FWRITE | FTRUNC)))
331                 vcp->execsOrWriters--;
332
333             vcp->states &= ~CMAPPED;
334             crfree(credp);
335         }
336     }
337     else {
338         ReleaseWriteLock(&vcp->lock);
339     }
340
341  unlock_exit:
342     AFS_GUNLOCK();
343 }
344
345 static int afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap)
346 {
347     struct vcache *vcp = (struct vcache*)FILE_INODE(fp);
348     cred_t *credp = crref();
349     struct vrequest treq;
350     int code;
351
352     AFS_GLOCK();
353 #if defined(AFS_LINUX24_ENV)
354     afs_Trace3(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
355                ICL_TYPE_POINTER, vmap->vm_start,
356                ICL_TYPE_INT32, vmap->vm_end - vmap->vm_start);
357 #else
358     afs_Trace4(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
359                ICL_TYPE_POINTER, vmap->vm_start,
360                ICL_TYPE_INT32, vmap->vm_end - vmap->vm_start,
361                ICL_TYPE_INT32, vmap->vm_offset);
362 #endif
363
364     /* get a validated vcache entry */
365     code = afs_InitReq(&treq, credp);
366     if (!code)
367         code = afs_VerifyVCache(vcp, &treq);
368
369
370     if (code)
371         code = -code;
372     else {
373         osi_FlushPages(vcp, credp);     /* ensure stale pages are gone */
374
375         AFS_GUNLOCK();
376         code = generic_file_mmap(fp, vmap);
377         AFS_GLOCK();
378     }
379
380     if (code == 0) {
381         ObtainWriteLock(&vcp->lock,531);
382         /* Set out vma ops so we catch the close. The following test should be
383          * the same as used in generic_file_mmap.
384          */
385         if ((vmap->vm_flags & VM_SHARED) && (vmap->vm_flags & VM_MAYWRITE)) {
386             if (!afs_shared_mmap_ops_inited) {
387                 afs_shared_mmap_ops_inited = 1;
388                 afs_shared_mmap_ops = *vmap->vm_ops;
389                 afs_shared_mmap_ops.close = afs_linux_vma_close;
390             }
391             vmap->vm_ops = &afs_shared_mmap_ops;
392         }
393         else {
394             if (!afs_private_mmap_ops_inited) {
395                 afs_private_mmap_ops_inited = 1;
396                 afs_private_mmap_ops = *vmap->vm_ops;
397                 afs_private_mmap_ops.close = afs_linux_vma_close;
398             }
399             vmap->vm_ops = &afs_private_mmap_ops;
400         }
401     
402     
403         /* Add an open reference on the first mapping. */
404         if (vcp->mapcnt == 0) {
405             vcp->execsOrWriters++;
406             vcp->opens++;
407             vcp->states |= CMAPPED;
408         }
409         ReleaseWriteLock(&vcp->lock);
410         vcp->mapcnt++;
411     }
412
413     AFS_GUNLOCK();
414     crfree(credp);
415     return code;
416 }
417
418 int afs_linux_open(struct inode *ip, struct file *fp)
419 {
420     int code;
421     cred_t *credp = crref();
422
423     AFS_GLOCK();
424 #ifdef AFS_LINUX24_ENV
425     lock_kernel();
426 #endif
427     code = afs_open((struct vcache**)&ip, fp->f_flags, credp);
428 #ifdef AFS_LINUX24_ENV
429     unlock_kernel();
430 #endif
431     AFS_GUNLOCK();
432
433     crfree(credp);
434     return -code;
435 }
436
437 /* afs_Close is called from release, since release is used to handle all
438  * file closings. In addition afs_linux_flush is called from sys_close to
439  * handle flushing the data back to the server. The kicker is that we could
440  * ignore flush completely if only sys_close took it's return value from
441  * fput. See afs_linux_flush for notes on interactions between release and
442  * flush.
443  */
444 static int afs_linux_release(struct inode *ip, struct file *fp)
445 {
446     int code = 0;
447     cred_t *credp = crref();
448     struct vcache *vcp = (struct vcache*)ip;
449
450     AFS_GLOCK();
451 #ifdef AFS_LINUX24_ENV
452     lock_kernel();
453 #endif
454     if (vcp->flushcnt) {
455         vcp->flushcnt--; /* protected by AFS global lock. */
456     }
457     else {
458         code = afs_close(vcp, fp->f_flags, credp);
459     }
460 #ifdef AFS_LINUX24_ENV
461     unlock_kernel();
462 #endif
463     AFS_GUNLOCK();
464
465     crfree(credp);
466     return -code;
467 }
468
469 #if defined(AFS_LINUX24_ENV)
470 static int afs_linux_fsync(struct file *fp, struct dentry *dp, int datasync)
471 #else
472 static int afs_linux_fsync(struct file *fp, struct dentry *dp)
473 #endif
474 {
475     int code;
476     struct inode *ip = FILE_INODE(fp);
477     cred_t *credp = crref();
478
479     AFS_GLOCK();
480 #ifdef AFS_LINUX24_ENV
481     lock_kernel();
482 #endif
483     code = afs_fsync((struct vcache*)ip, credp);
484 #ifdef AFS_LINUX24_ENV
485     unlock_kernel();
486 #endif
487     AFS_GUNLOCK();
488     crfree(credp);
489     return -code;
490     
491 }
492
493 #ifdef NOTUSED
494 /* No support for async i/o */
495 int afs_linux_fasync(struct inode *ip, struct file *fp, int);
496
497 /* I don't think it will, at least not as can be detected here. */
498 int afs_linux_check_media_change(kdev_t dev);
499
500 /* Revalidate media and file system. */
501 int afs_linux_file_revalidate(kdev_t dev);
502 #endif /* NOTUSED */
503
504 static int afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp)
505 {
506     int code = 0;
507     struct vcache *vcp = (struct vcache*)FILE_INODE(fp);
508     cred_t *credp = crref();
509     struct flock flock;
510     
511     /* Convert to a lock format afs_lockctl understands. */
512     memset((char*)&flock, 0, sizeof(flock));
513     flock.l_type = flp->fl_type;
514     flock.l_pid = flp->fl_pid;
515     flock.l_whence = 0;
516     flock.l_start = flp->fl_start;
517     flock.l_len = flp->fl_end - flp->fl_start;
518
519     AFS_GLOCK();
520     code = afs_lockctl(vcp, &flock, cmd, credp);
521     AFS_GUNLOCK();
522     crfree(credp);
523     return -code;
524     
525 }
526
527 /* afs_linux_flush
528  * flush is called from sys_close. We could ignore it, but sys_close return
529  * code comes from flush, not release. We need to use release to keep
530  * the vcache open count correct. Note that flush is called before release
531  * (via fput) in sys_close. vcp->flushcnt is a bit of ugliness to avoid
532  * races and also avoid calling afs_close twice when closing the file.
533  * If we merely checked for opens > 0 in afs_linux_release, then if an
534  * new open occurred when storing back the file, afs_linux_release would
535  * incorrectly close the file and decrement the opens count. Calling afs_close
536  * on the just flushed file is wasteful, since the background daemon will
537  * execute the code that finally decides there is nothing to do.
538  */
539 int afs_linux_flush(struct file *fp)
540 {
541     struct vcache *vcp = (struct vcache *)FILE_INODE(fp);
542     int code = 0;
543     cred_t *credp;
544
545     /* Only do this on the last close of the file pointer. */
546 #if defined(AFS_LINUX24_ENV)
547     if (atomic_read(&fp->f_count) > 1)
548 #else
549     if (fp->f_count > 1)
550 #endif
551         return 0;
552
553     credp = crref();
554
555     AFS_GLOCK();
556     code = afs_close(vcp, fp->f_flags, credp);
557     vcp->flushcnt++; /* protected by AFS global lock. */
558     AFS_GUNLOCK();
559
560     crfree(credp);
561     return -code;
562 }
563
564 /* Not allowed to directly read a directory. */
565 ssize_t afs_linux_dir_read(struct file *fp, char *buf, size_t count, loff_t *ppos)
566 {
567     return -EISDIR;
568 }
569
570
571
572 #if defined(AFS_LINUX24_ENV)
573 struct file_operations afs_dir_fops = {
574     read:      generic_read_dir,
575     readdir:   afs_linux_readdir,
576     ioctl:     afs_xioctl,
577     open:      afs_linux_open,
578     release:   afs_linux_release,
579 };
580 #else
581 struct file_operations afs_dir_fops = {
582     NULL,               /* afs_linux_lseek */
583     afs_linux_dir_read,
584     NULL,               /* afs_linux_write */
585     afs_linux_readdir,
586     NULL,               /* afs_linux_select */
587     afs_xioctl,         /* close enough to use the ported AFS one */
588     NULL,               /* afs_linux_mmap */
589     afs_linux_open,
590     NULL,               /* afs_linux_flush */
591     afs_linux_release,
592     afs_linux_fsync,
593     NULL,               /* afs_linux_fasync */
594     NULL,               /* afs_linux_check_media_change */
595     NULL,               /* afs_linux_file_revalidate */
596     afs_linux_lock,
597 };
598 #endif
599
600 #if defined(AFS_LINUX24_ENV)
601 struct file_operations afs_file_fops = {
602     read:      afs_linux_read,
603     write:     afs_linux_write,
604     ioctl:     afs_xioctl,
605     mmap:      afs_linux_mmap,
606     open:      afs_linux_open,
607     flush:     afs_linux_flush,
608     release:   afs_linux_release,
609     fsync:     afs_linux_fsync,
610     lock:      afs_linux_lock,
611 };
612 #else
613 struct file_operations afs_file_fops = {
614     NULL,               /* afs_linux_lseek */
615     afs_linux_read,
616     afs_linux_write,
617     NULL,               /* afs_linux_readdir */
618     NULL,               /* afs_linux_select */
619     afs_xioctl,         /* close enough to use the ported AFS one */
620     afs_linux_mmap,
621     afs_linux_open,
622     afs_linux_flush,
623     afs_linux_release,
624     afs_linux_fsync,
625     NULL,               /* afs_linux_fasync */
626     NULL,               /* afs_linux_check_media_change */
627     NULL,               /* afs_linux_file_revalidate */
628     afs_linux_lock,
629 };
630 #endif
631    
632
633 /**********************************************************************
634  * AFS Linux dentry operations
635  **********************************************************************/
636
637 /* afs_linux_revalidate
638  * Ensure vcache is stat'd before use. Return 0 if entry is valid.
639  */
640 static int afs_linux_revalidate(struct dentry *dp)
641 {
642     int code;
643     cred_t *credp;
644     struct vrequest treq;
645     struct vcache *vcp = (struct vcache*)dp->d_inode;
646
647     AFS_GLOCK();
648 #ifdef AFS_LINUX24_ENV
649     lock_kernel();
650 #endif
651
652     /* Make this a fast path (no crref), since it's called so often. */
653     if (vcp->states & CStatd) {
654         if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
655             check_bad_parent(dp); /* check and correct mvid */
656         vcache2inode(vcp);
657 #ifdef AFS_LINUX24_ENV
658         unlock_kernel();
659 #endif
660         AFS_GUNLOCK();
661         return 0;
662     }
663
664     credp = crref();
665     code = afs_InitReq(&treq, credp);
666     if (!code)
667         code = afs_VerifyVCache(vcp, &treq);
668
669 #ifdef AFS_LINUX24_ENV
670     unlock_kernel();
671 #endif
672     AFS_GUNLOCK();
673     crfree(credp);
674
675     return -code ;
676 }
677
678 /* Validate a dentry. Return 0 if unchanged, 1 if VFS layer should re-evaluate.
679  * In kernels 2.2.10 and above, we are passed an additional flags var which
680  * may have either the LOOKUP_FOLLOW OR LOOKUP_DIRECTORY set in which case
681  * we are advised to follow the entry if it is a link or to make sure that 
682  * it is a directory. But since the kernel itself checks these possibilities
683  * later on, we shouldn't have to do it until later. Perhaps in the future..
684  */
685 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
686 static int afs_linux_dentry_revalidate(struct dentry *dp, int flags)
687 #else
688 static int afs_linux_dentry_revalidate(struct dentry *dp)
689 #endif
690 {
691     int code;
692     cred_t *credp;
693     struct vrequest treq;
694     struct vcache *vcp = (struct vcache*)dp->d_inode;
695
696     /* If it's a negative dentry, then there's nothing to do. */
697     if (!vcp) {
698         goto out_valid;
699     }
700
701     AFS_GLOCK();
702 #ifdef AFS_LINUX24_ENV
703     lock_kernel();
704 #endif
705
706     /* Drop the dentry if the callback is broken */
707     if (!(vcp->states & CStatd)) {
708         d_drop(dp);
709 #ifdef AFS_LINUX24_ENV
710         unlock_kernel();
711 #endif
712         AFS_GUNLOCK();
713         return 0;
714     }
715
716     /* Make this a fast path (no crref), since it's called so often. */
717     if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
718         check_bad_parent(dp); /* check and correct mvid */
719     vcache2inode(vcp);
720 #ifdef AFS_LINUX24_ENV
721     unlock_kernel();
722 #endif
723     AFS_GUNLOCK();
724
725 out_valid:
726     return 1;
727
728 out_bad:
729     return 0;
730 }
731
732 /* afs_dentry_iput */
733 static void afs_dentry_iput(struct dentry *dp, struct inode *ip)
734 {
735     osi_iput(ip);
736 }
737
738 #if defined(AFS_LINUX24_ENV)
739 struct dentry_operations afs_dentry_operations = {
740        d_revalidate:   afs_linux_dentry_revalidate,
741        d_iput:         afs_dentry_iput,
742 };
743 struct dentry_operations *afs_dops = &afs_dentry_operations;
744 #else
745 struct dentry_operations afs_dentry_operations = {
746         afs_linux_dentry_revalidate,    /* d_validate(struct dentry *) */
747         NULL,                   /* d_hash */
748         NULL,                   /* d_compare */
749         NULL,                   /* d_delete(struct dentry *) */
750         NULL,                   /* d_release(struct dentry *) */
751         afs_dentry_iput         /* d_iput(struct dentry *, struct inode *) */
752 };
753 struct dentry_operations *afs_dops = &afs_dentry_operations;
754 #endif
755
756 /**********************************************************************
757  * AFS Linux inode operations
758  **********************************************************************/
759
760 /* afs_linux_create
761  *
762  * Merely need to set enough of vattr to get us through the create. Note
763  * that the higher level code (open_namei) will take care of any tuncation
764  * explicitly. Exclusive open is also taken care of in open_namei.
765  *
766  * name is in kernel space at this point.
767  */
768 int afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
769 {
770     int code;
771     cred_t *credp = crref();
772     struct vattr vattr;
773     enum vcexcl excl;
774     const char *name = dp->d_name.name;
775     struct inode *ip;
776
777     VATTR_NULL(&vattr);
778     vattr.va_mode = mode;
779
780     AFS_GLOCK();
781     code = afs_create((struct vcache*)dip, name, &vattr, NONEXCL, mode,
782                       (struct vcache**)&ip, credp);
783
784     if (!code) {
785         vattr2inode(ip, &vattr);
786         /* Reset ops if symlink or directory. */
787 #if defined(AFS_LINUX24_ENV)
788        if (S_ISREG(ip->i_mode)) {
789            ip->i_op = &afs_file_iops;
790            ip->i_fop = &afs_file_fops;
791            ip->i_data.a_ops = &afs_file_aops;
792         } else if (S_ISDIR(ip->i_mode)) {
793            ip->i_op = &afs_dir_iops;
794            ip->i_fop = &afs_dir_fops;
795         } else if (S_ISLNK(ip->i_mode)) {
796            ip->i_op = &afs_symlink_iops;
797            ip->i_data.a_ops = &afs_symlink_aops;
798            ip->i_mapping = &ip->i_data;
799         } else
800            printk("afs_linux_create: FIXME\n");
801 #else
802         if (S_ISDIR(ip->i_mode))
803             ip->i_op = &afs_dir_iops;
804         else if (S_ISLNK(ip->i_mode))
805             ip->i_op = &afs_symlink_iops;
806 #endif
807
808         dp->d_op = afs_dops;
809         d_instantiate(dp, ip);
810     }
811
812     AFS_GUNLOCK();
813     crfree(credp);
814     return -code;
815 }
816
817 /* afs_linux_lookup */
818 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
819 struct dentry *afs_linux_lookup(struct inode *dip, struct dentry *dp)
820 #else
821 int afs_linux_lookup(struct inode *dip, struct dentry *dp)
822 #endif
823 {
824     int code = 0;
825     cred_t *credp = crref();
826     struct vcache *vcp=NULL;
827     const char *comp = dp->d_name.name;
828     AFS_GLOCK();
829     code = afs_lookup((struct vcache *)dip, comp, &vcp, credp);
830
831     if (vcp) {
832         struct inode *ip = (struct inode*)vcp;
833         /* Reset ops if symlink or directory. */
834 #if defined(AFS_LINUX24_ENV)
835        if (S_ISREG(ip->i_mode)) {
836            ip->i_op = &afs_file_iops;
837            ip->i_fop = &afs_file_fops;
838            ip->i_data.a_ops = &afs_file_aops;
839         } else if (S_ISDIR(ip->i_mode)) {
840            ip->i_op = &afs_dir_iops;
841            ip->i_fop = &afs_dir_fops;
842         } else if (S_ISLNK(ip->i_mode)) {
843            ip->i_op = &afs_symlink_iops;
844            ip->i_data.a_ops = &afs_symlink_aops;
845            ip->i_mapping = &ip->i_data;
846         } else
847            printk("afs_linux_lookup: FIXME\n");
848 #else
849         if (S_ISDIR(ip->i_mode))
850             ip->i_op = &afs_dir_iops;
851         else if (S_ISLNK(ip->i_mode))
852             ip->i_op = &afs_symlink_iops;
853 #endif
854     }
855     dp->d_op = afs_dops;
856     d_add(dp, (struct inode*)vcp);
857
858     AFS_GUNLOCK();
859     crfree(credp);
860
861     /* It's ok for the file to not be found. That's noted by the caller by
862      * seeing that the dp->d_inode field is NULL.
863      */
864 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
865     if (code == ENOENT)
866         return ERR_PTR(0);
867     else
868         return ERR_PTR(-code);
869 #else
870     if (code == ENOENT)
871         code = 0;
872     return -code;
873 #endif
874 }
875
876 int afs_linux_link(struct dentry *olddp, struct inode *dip,
877                    struct dentry *newdp)
878 {
879     int code;
880     cred_t *credp = crref();
881     const char *name = newdp->d_name.name;
882     struct inode *oldip = olddp->d_inode;
883
884     /* If afs_link returned the vnode, we could instantiate the
885      * dentry. Since it's not, we drop this one and do a new lookup.
886      */
887     d_drop(newdp);
888
889     AFS_GLOCK();
890     code = afs_link((struct vcache*)oldip, (struct vcache*)dip, name, credp);
891
892     AFS_GUNLOCK();
893     crfree(credp);
894     return -code;
895 }
896
897 int afs_linux_unlink(struct inode *dip, struct dentry *dp)
898 {
899     int code;
900     cred_t *credp = crref();
901     const char *name = dp->d_name.name;
902     int putback = 0;
903
904     if (!list_empty(&dp->d_hash)) {
905         d_drop(dp);
906         /* Install a definite non-existence if we're the only user. */
907 #if defined(AFS_LINUX24_ENV)
908         if (atomic_read(&dp->d_count) == 1)
909 #else
910         if (dp->d_count == 1)
911 #endif
912             putback = 1;
913     }
914
915     AFS_GLOCK();
916     code = afs_remove((struct vcache*)dip, name, credp);
917     AFS_GUNLOCK();
918     if (!code) {
919         d_delete(dp);
920         if (putback)
921             d_add(dp, NULL); /* means definitely does _not_ exist */
922     }
923     crfree(credp);
924     return -code;
925 }
926
927
928 int afs_linux_symlink(struct inode *dip, struct dentry *dp,
929                       const char *target)
930 {
931     int code;
932     cred_t *credp = crref();
933     struct vattr vattr;
934     const char *name = dp->d_name.name;
935
936     /* If afs_symlink returned the vnode, we could instantiate the
937      * dentry. Since it's not, we drop this one and do a new lookup.
938      */
939     d_drop(dp);
940
941     AFS_GLOCK();
942     VATTR_NULL(&vattr);
943     code = afs_symlink((struct vcache*)dip, name, &vattr, target, credp);
944     AFS_GUNLOCK();
945     crfree(credp);
946     return -code;
947 }
948
949 int afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
950 {
951     int code;
952     cred_t *credp = crref();
953     struct vcache *tvcp = NULL;
954     struct vattr vattr;
955     const char *name = dp->d_name.name;
956
957     AFS_GLOCK();
958     VATTR_NULL(&vattr);
959     vattr.va_mask = ATTR_MODE;
960     vattr.va_mode = mode;
961     code = afs_mkdir((struct vcache*)dip, name, &vattr, &tvcp, credp);
962
963     if (tvcp) {
964         tvcp->v.v_op = &afs_dir_iops;
965 #if defined(AFS_LINUX24_ENV)
966         tvcp->v.v_fop = &afs_dir_fops;
967 #endif
968         dp->d_op = afs_dops;
969         d_instantiate(dp, (struct inode*)tvcp);
970     }
971     AFS_GUNLOCK();
972     crfree(credp);
973     return -code;
974 }
975
976 int afs_linux_rmdir(struct inode *dip, struct dentry *dp)
977 {
978     int code;
979     cred_t *credp = crref();
980     const char *name = dp->d_name.name;
981
982     AFS_GLOCK();
983     code = afs_rmdir((struct vcache*)dip, name, credp);
984
985     /* Linux likes to see ENOTEMPTY returned from an rmdir() syscall
986      * that failed because a directory is not empty. So, we map
987      * EEXIST to ENOTEMPTY on linux.
988      */
989     if (code == EEXIST) {
990         code = ENOTEMPTY;
991     }
992     
993     if (!code) {
994         d_delete(dp);
995     }
996
997     AFS_GUNLOCK();
998     crfree(credp);
999     return -code;
1000 }
1001
1002
1003
1004 int afs_linux_rename(struct inode *oldip, struct dentry *olddp,
1005                      struct inode *newip, struct dentry *newdp)
1006 {
1007     int code;
1008     cred_t *credp = crref();
1009     const char *oldname = olddp->d_name.name;
1010     const char *newname = newdp->d_name.name;
1011
1012     /* Remove old and new entries from name hash. New one will change below.
1013      * While it's optimal to catch failures and re-insert newdp into hash,
1014      * it's also error prone and in that case we're already dealing with error
1015      * cases. Let another lookup put things right, if need be.
1016      */
1017     if (!list_empty(&olddp->d_hash)) {
1018         d_drop(olddp);
1019     }
1020     if (!list_empty(&newdp->d_hash)) {
1021         d_drop(newdp);
1022     }
1023     AFS_GLOCK();
1024     code = afs_rename((struct vcache*)oldip, oldname, (struct vcache*)newip,
1025                       newname, credp);
1026     AFS_GUNLOCK();
1027
1028     if (!code)
1029         d_move(olddp, newdp);
1030
1031     crfree(credp);
1032     return -code;
1033 }
1034
1035
1036 /* afs_linux_ireadlink 
1037  * Internal readlink which can return link contents to user or kernel space.
1038  * Note that the buffer is NOT supposed to be null-terminated.
1039  */
1040 static int afs_linux_ireadlink(struct inode *ip, char *target, int maxlen,
1041                         uio_seg_t seg)
1042 {
1043     int code;
1044     cred_t *credp = crref();
1045     uio_t tuio;
1046     struct iovec iov;
1047
1048     setup_uio(&tuio, &iov, target, 0, maxlen, UIO_READ, seg);
1049     code = afs_readlink((struct vcache*)ip, &tuio, credp);
1050     crfree(credp);
1051
1052     if (!code)
1053         return maxlen - tuio.uio_resid;
1054     else
1055         return -code;
1056 }
1057
1058 #if !defined(AFS_LINUX24_ENV)
1059 /* afs_linux_readlink 
1060  * Fill target (which is in user space) with contents of symlink.
1061  */
1062 int afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
1063 {
1064     int code;
1065     struct inode *ip = dp->d_inode;
1066
1067     AFS_GLOCK();
1068     code = afs_linux_ireadlink(ip, target, maxlen, AFS_UIOUSER);
1069     AFS_GUNLOCK();
1070     return code;
1071 }
1072
1073
1074 /* afs_linux_follow_link
1075  * a file system dependent link following routine.
1076  */
1077 struct dentry * afs_linux_follow_link(struct dentry *dp,
1078                                       struct dentry *basep,
1079                                       unsigned int follow)
1080 {
1081     int code = 0;
1082     char *name;
1083     struct dentry *res;
1084
1085     AFS_GLOCK();
1086     name = osi_Alloc(PATH_MAX+1);
1087     if (!name) {
1088         AFS_GUNLOCK();
1089         dput(basep);
1090         return ERR_PTR(-EIO);
1091     }
1092
1093     code = afs_linux_ireadlink(dp->d_inode, name, PATH_MAX, AFS_UIOSYS);
1094     AFS_GUNLOCK();
1095
1096     if (code<0) {
1097         dput(basep);
1098         res = ERR_PTR(code);
1099     }
1100     else {
1101         name[code] = '\0';
1102         res = lookup_dentry(name, basep, follow);
1103     }
1104
1105     AFS_GLOCK();
1106     osi_Free(name, PATH_MAX+1);
1107     AFS_GUNLOCK();
1108     return res;
1109 }
1110 #endif
1111
1112 /* afs_linux_readpage
1113  * all reads come through here. A strategy-like read call.
1114  */
1115 int afs_linux_readpage(struct file *fp, struct page *pp)
1116 {
1117     int code;
1118     cred_t *credp = crref();
1119 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1120     char *address;
1121     loff_t offset = pp->index << PAGE_CACHE_SHIFT;
1122 #else
1123     ulong address = afs_linux_page_address(pp);
1124     loff_t offset = pageoff(pp);
1125 #endif
1126     uio_t tuio;
1127     struct iovec iovec;
1128     struct inode *ip = FILE_INODE(fp);
1129     int cnt = atomic_read(&pp->count);
1130
1131     AFS_GLOCK();
1132     afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE,
1133                ICL_TYPE_POINTER, ip,
1134                ICL_TYPE_POINTER, pp,
1135                ICL_TYPE_INT32, cnt,
1136                ICL_TYPE_INT32, 99999); /* not a possible code value */
1137
1138 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1139     address = kmap(pp);
1140     ClearPageError(pp);
1141
1142     lock_kernel();
1143 #else
1144     atomic_add(1, &pp->count);
1145     set_bit(PG_locked, &pp->flags); /* other bits? See mm.h */
1146     clear_bit(PG_error, &pp->flags);
1147 #endif
1148
1149     setup_uio(&tuio, &iovec, (char*)address, offset, PAGESIZE,
1150               UIO_READ, AFS_UIOSYS);
1151     code = afs_rdwr((struct vcache*)ip, &tuio, UIO_READ, 0, credp);
1152 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1153     unlock_kernel();
1154 #endif
1155
1156     if (!code) {
1157         if (tuio.uio_resid) /* zero remainder of page */
1158             memset((void*)(address+(PAGESIZE-tuio.uio_resid)), 0,
1159                    tuio.uio_resid);
1160 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1161         flush_dcache_page(pp);
1162         SetPageUptodate(pp);
1163 #else
1164         set_bit(PG_uptodate, &pp->flags);
1165 #endif
1166     }
1167
1168 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
1169     kunmap(pp);
1170     UnlockPage(pp);
1171 #else
1172     clear_bit(PG_locked, &pp->flags);
1173     wake_up(&pp->wait);
1174     free_page(address);
1175 #endif
1176
1177     crfree(credp);
1178     afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE,
1179                ICL_TYPE_POINTER, ip,
1180                ICL_TYPE_POINTER, pp,
1181                ICL_TYPE_INT32, cnt,
1182                ICL_TYPE_INT32, code);
1183     AFS_GUNLOCK();
1184     return -code;
1185 }
1186
1187 #if defined(AFS_LINUX24_ENV)
1188 int afs_linux_writepage(struct page *pp)
1189 {
1190     struct address_space *mapping = pp->mapping;
1191     struct inode *inode;
1192     unsigned long end_index;
1193     unsigned offset = PAGE_CACHE_SIZE;
1194     long status;
1195  
1196     inode = (struct inode *) mapping->host;
1197     end_index = inode->i_size >> PAGE_CACHE_SHIFT;
1198
1199     /* easy case */
1200     if (pp->index < end_index)
1201         goto do_it;
1202     /* things got complicated... */
1203     offset = inode->i_size & (PAGE_CACHE_SIZE-1);
1204     /* OK, are we completely out? */
1205     if (pp->index >= end_index+1 || !offset)
1206         return -EIO;
1207 do_it:
1208     AFS_GLOCK();
1209     status = afs_linux_writepage_sync(inode, pp, 0, offset);
1210     AFS_GUNLOCK();
1211     SetPageUptodate(pp);
1212     UnlockPage(pp);
1213     if (status == offset)
1214         return 0;
1215     else
1216         return status;
1217 }
1218 #endif
1219
1220 #ifdef NOTUSED
1221 /* afs_linux_bmap - supports generic_readpage, but we roll our own. */
1222 int afs_linux_bmap(struct inode *ip, int) { return -EINVAL; }
1223
1224 /* afs_linux_truncate
1225  * Handles discarding disk blocks if this were a device. ext2 indicates we
1226  * may need to zero partial last pages of memory mapped files.
1227  */
1228 void afs_linux_truncate(struct inode *ip)
1229 {
1230 }
1231 #endif
1232
1233 /* afs_linux_permission
1234  * Check access rights - returns error if can't check or permission denied.
1235  */
1236 int afs_linux_permission(struct inode *ip, int mode)
1237 {
1238     int code;
1239     cred_t *credp = crref();
1240     int tmp = 0;
1241
1242     AFS_GLOCK();
1243     if (mode & MAY_EXEC) tmp |= VEXEC;
1244     if (mode & MAY_READ) tmp |= VREAD;
1245     if (mode & MAY_WRITE) tmp |= VWRITE;
1246     code = afs_access((struct vcache*)ip, tmp, credp);
1247
1248     AFS_GUNLOCK();
1249     crfree(credp);
1250     return -code;
1251 }
1252
1253
1254 #ifdef NOTUSED
1255 /* msdos sector mapping hack for memory mapping. */
1256 int afs_linux_smap(struct inode *ip, int) { return -EINVAL; }
1257 #endif
1258
1259 #if defined(AFS_LINUX24_ENV)
1260 int afs_linux_writepage_sync(struct inode *ip, struct page *pp,
1261                         unsigned long offset,
1262                         unsigned int count)
1263 {
1264     struct vcache *vcp = (struct vcache *) ip;
1265     char *buffer;
1266     loff_t base;
1267     int code = 0;
1268     cred_t *credp;
1269     uio_t tuio;
1270     struct iovec iovec;
1271     int f_flags = 0;
1272
1273     buffer = kmap(pp) + offset;
1274     base = (pp->index << PAGE_CACHE_SHIFT) + offset;
1275
1276     credp = crref();
1277     afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1278               ICL_TYPE_POINTER, pp,
1279               ICL_TYPE_INT32, atomic_read(&pp->count),
1280               ICL_TYPE_INT32, 99999);
1281     setup_uio(&tuio, &iovec, buffer, base, count, UIO_WRITE, AFS_UIOSYS);
1282
1283     code = afs_write(vcp, &tuio, f_flags, credp, 0);
1284
1285     vcache2inode(vcp);
1286
1287     code = code ? -code : count - tuio.uio_resid;
1288     afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1289               ICL_TYPE_POINTER, pp,
1290               ICL_TYPE_INT32, atomic_read(&pp->count),
1291               ICL_TYPE_INT32, code);
1292
1293     crfree(credp);
1294     kunmap(pp);
1295
1296     return code;
1297 }
1298
1299 static int
1300 afs_linux_updatepage(struct file *file, struct page *page, 
1301                      unsigned long offset, unsigned int count)
1302 {
1303     struct dentry *dentry = file->f_dentry;
1304
1305     return afs_linux_writepage_sync(dentry->d_inode, page, offset, count);
1306 }
1307 #else
1308 /* afs_linux_updatepage
1309  * What one would have thought was writepage - write dirty page to file.
1310  * Called from generic_file_write. buffer is still in user space. pagep
1311  * has been filled in with old data if we're updating less than a page.
1312  */
1313 int afs_linux_updatepage(struct file *fp, struct page *pp,
1314                          unsigned long offset,
1315                          unsigned int count, int sync)
1316 {
1317     struct vcache *vcp = (struct vcache *)FILE_INODE(fp);
1318     u8 *page_addr = (u8*) afs_linux_page_address(pp);
1319     int code = 0;
1320     cred_t *credp;
1321     uio_t tuio;
1322     struct iovec iovec;
1323     
1324     set_bit(PG_locked, &pp->flags);
1325
1326     credp = crref();
1327     AFS_GLOCK();
1328     afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1329                ICL_TYPE_POINTER, pp,
1330                ICL_TYPE_INT32, atomic_read(&pp->count),
1331                ICL_TYPE_INT32, 99999);
1332     setup_uio(&tuio, &iovec, page_addr + offset, pp->offset + offset, count,
1333               UIO_WRITE, AFS_UIOSYS);
1334
1335     code = afs_write(vcp, &tuio, fp->f_flags, credp, 0);
1336
1337     vcache2inode(vcp);
1338
1339     code = code ? -code : count - tuio.uio_resid;
1340     afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1341                ICL_TYPE_POINTER, pp,
1342                ICL_TYPE_INT32, atomic_read(&pp->count),
1343                ICL_TYPE_INT32, code);
1344
1345     AFS_GUNLOCK();
1346     crfree(credp);
1347
1348     clear_bit(PG_locked, &pp->flags);
1349     return code;
1350 }
1351 #endif
1352
1353 #if defined(AFS_LINUX24_ENV)
1354 static int afs_linux_commit_write(struct file *file, struct page *page, unsigned offset, unsigned to)
1355 {
1356     int code;
1357
1358     AFS_GLOCK();
1359     lock_kernel();
1360     code = afs_linux_updatepage(file, page, offset, to-offset);
1361     unlock_kernel();
1362     AFS_GUNLOCK();
1363     kunmap(page);
1364
1365     return code;
1366 }
1367
1368 static int afs_linux_prepare_write(struct file *file, struct page *page,
1369                                    unsigned from, unsigned to)
1370 {
1371     kmap(page);
1372     return 0;
1373 }
1374
1375 extern int afs_notify_change(struct dentry *dp, struct iattr* iattrp);
1376 #endif
1377
1378 #if defined(AFS_LINUX24_ENV)
1379 struct inode_operations afs_file_iops = {
1380     revalidate:                afs_linux_revalidate,
1381     setattr:           afs_notify_change,
1382     permission:                afs_linux_permission,
1383 };
1384 struct address_space_operations afs_file_aops = {
1385         readpage: afs_linux_readpage,
1386         writepage: afs_linux_writepage,
1387         commit_write: afs_linux_commit_write,
1388         prepare_write: afs_linux_prepare_write,
1389 };
1390
1391 struct inode_operations *afs_ops = &afs_file_iops;
1392 #else
1393 struct inode_operations afs_iops = {
1394     &afs_file_fops,     /* file operations */
1395     NULL,               /* afs_linux_create */
1396     NULL,               /* afs_linux_lookup */
1397     NULL,               /* afs_linux_link */
1398     NULL,               /* afs_linux_unlink */
1399     NULL,               /* afs_linux_symlink */
1400     NULL,               /* afs_linux_mkdir */
1401     NULL,               /* afs_linux_rmdir */
1402     NULL,               /* afs_linux_mknod */
1403     NULL,               /* afs_linux_rename */
1404     NULL,               /* afs_linux_readlink */
1405     NULL,               /* afs_linux_follow_link */
1406     afs_linux_readpage,
1407     NULL,               /* afs_linux_writepage */
1408     NULL,               /* afs_linux_bmap */
1409     NULL,               /* afs_linux_truncate */
1410     afs_linux_permission,
1411     NULL,               /* afs_linux_smap */
1412     afs_linux_updatepage,
1413     afs_linux_revalidate,
1414 };
1415
1416 struct inode_operations *afs_ops = &afs_iops;
1417 #endif
1418
1419 /* Separate ops vector for directories. Linux 2.2 tests type of inode
1420  * by what sort of operation is allowed.....
1421  */
1422 #if defined(AFS_LINUX24_ENV)
1423 struct inode_operations afs_dir_iops = {
1424     create:    afs_linux_create,
1425     lookup:    afs_linux_lookup,
1426     link:      afs_linux_link,
1427     unlink:    afs_linux_unlink,
1428     symlink:   afs_linux_symlink,
1429     mkdir:     afs_linux_mkdir,
1430     rmdir:     afs_linux_rmdir,
1431     rename:    afs_linux_rename,
1432     revalidate:        afs_linux_revalidate,
1433     setattr:   afs_notify_change,
1434     permission:        afs_linux_permission,
1435 };
1436 #else
1437 struct inode_operations afs_dir_iops = {
1438     &afs_dir_fops,      /* file operations for directories */
1439     afs_linux_create,
1440     afs_linux_lookup,
1441     afs_linux_link,
1442     afs_linux_unlink,
1443     afs_linux_symlink,
1444     afs_linux_mkdir,
1445     afs_linux_rmdir,
1446     NULL,               /* afs_linux_mknod */
1447     afs_linux_rename,
1448     NULL,               /* afs_linux_readlink */
1449     NULL,               /* afs_linux_follow_link */
1450     NULL,               /* afs_linux_readpage */
1451     NULL,               /* afs_linux_writepage */
1452     NULL,               /* afs_linux_bmap */
1453     NULL,               /* afs_linux_truncate */
1454     afs_linux_permission,
1455     NULL,               /* afs_linux_smap */
1456     NULL,               /* afs_linux_updatepage */
1457     afs_linux_revalidate,
1458 };
1459 #endif
1460
1461 /* We really need a separate symlink set of ops, since do_follow_link()
1462  * determines if it _is_ a link by checking if the follow_link op is set.
1463  */
1464 #if defined(AFS_LINUX24_ENV)
1465 static int afs_symlink_filler(struct file *file, struct page *page)
1466 {
1467     struct inode *ip = (struct inode *) page->mapping->host;
1468     char *p = (char *)kmap(page);
1469     int code;
1470
1471     AFS_GLOCK();
1472     lock_kernel();
1473     code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS);
1474
1475     if (code<0)
1476            goto fail;
1477     p[code] = '\0';            /* null terminate? */
1478     unlock_kernel();
1479     AFS_GUNLOCK();
1480
1481     SetPageUptodate(page);
1482     kunmap(page);
1483     UnlockPage(page);
1484     return 0;
1485
1486 fail:
1487     unlock_kernel();
1488     AFS_GUNLOCK();
1489
1490     SetPageError(page);
1491     kunmap(page);
1492     UnlockPage(page);
1493     return code;
1494 }
1495
1496 struct address_space_operations afs_symlink_aops = {
1497        readpage:       afs_symlink_filler
1498 };
1499
1500 struct inode_operations afs_symlink_iops = {
1501     readlink:          page_readlink,
1502     follow_link:       page_follow_link,
1503     setattr:           afs_notify_change,
1504 };
1505 #else
1506 struct inode_operations afs_symlink_iops = {
1507     NULL,               /* file operations */
1508     NULL,               /* create */
1509     NULL,               /* lookup */
1510     NULL,               /* link */
1511     NULL,               /* unlink */
1512     NULL,               /* symlink */
1513     NULL,               /* mkdir */
1514     NULL,               /* rmdir */
1515     NULL,               /* afs_linux_mknod */
1516     NULL,               /* rename */
1517     afs_linux_readlink,
1518     afs_linux_follow_link,
1519     NULL,               /* readpage */
1520     NULL,               /* afs_linux_writepage */
1521     NULL,               /* afs_linux_bmap */
1522     NULL,               /* afs_linux_truncate */
1523     afs_linux_permission, /* tho the code appears to indicate not used? */
1524     NULL,               /* afs_linux_smap */
1525     NULL,               /* updatepage */
1526     afs_linux_revalidate, /* tho the code appears to indicate not used? */
1527 };
1528 #endif