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