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