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