1 /* Copyright (C) 1995, 1989, 1998 Transarc Corporation - All rights reserved */
3 * (C) COPYRIGHT IBM CORPORATION 1987, 1988
4 * LICENSED MATERIALS - PROPERTY OF IBM
8 * Linux specific vnodeops. Also includes the glue routines required to call
9 * AFS vnodeops. The "NOTUSED" #define is used to indicate routines and
10 * calling sequences present in an ops table that we don't actually use.
11 * They are present solely for documentation purposes.
13 * So far the only truly scary part is that Linux relies on the inode cache
14 * to be up to date. Don't you dare break a callback and expect an fstat
15 * to give you meaningful information. This appears to be fixed in the 2.1
16 * development kernels. As it is we can fix this now by intercepting the
20 #include "../afs/param.h"
21 #include "../afs/sysincludes.h"
22 #include "../afs/afsincludes.h"
23 #include "../afs/afs_stats.h"
25 #include "../h/pagemap.h"
27 extern struct vcache *afs_globalVp;
29 extern struct dentry_operations *afs_dops;
30 extern struct inode_operations afs_dir_iops;
31 extern struct inode_operations afs_symlink_iops;
35 static int afs_linux_lseek(struct inode *ip, struct file *fp, off_t, int) {}
38 static ssize_t afs_linux_read(struct file *fp, char *buf, size_t count,
42 struct vcache *vcp = (struct vcache*)fp->f_dentry->d_inode;
43 cred_t *credp = crref();
47 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
48 ICL_TYPE_INT32, (int)*offp,
49 ICL_TYPE_INT32, count,
50 ICL_TYPE_INT32, 99999);
52 /* get a validated vcache entry */
53 code = afs_InitReq(&treq, credp);
55 code = afs_VerifyVCache(vcp, &treq);
60 osi_FlushPages(vcp, credp); /* ensure stale pages are gone */
62 code = generic_file_read(fp, buf, count, offp);
66 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
67 ICL_TYPE_INT32, (int)*offp,
68 ICL_TYPE_INT32, count,
69 ICL_TYPE_INT32, code);
77 /* Now we have integrated VM for writes as well as reads. generic_file_write
78 * also takes care of re-positioning the pointer if file is open in append
79 * mode. Call fake open/close to ensure we do writes of core dumps.
81 static ssize_t afs_linux_write(struct file *fp, const char *buf, size_t count,
86 struct vcache *vcp = (struct vcache *)fp->f_dentry->d_inode;
88 cred_t *credp = crref();
92 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
93 ICL_TYPE_INT32, (int)*offp, ICL_TYPE_INT32, count,
94 ICL_TYPE_INT32, (fp->f_flags & O_APPEND) ? 99998 : 99999);
97 /* get a validated vcache entry */
98 code = (ssize_t)afs_InitReq(&treq, credp);
100 code = (ssize_t)afs_VerifyVCache(vcp, &treq);
102 ObtainWriteLock(&vcp->lock, 529);
104 ReleaseWriteLock(&vcp->lock);
109 code = generic_file_write(fp, buf, count, offp);
113 ObtainWriteLock(&vcp->lock, 530);
114 vcp->m.Date = osi_Time(); /* set modification time */
115 afs_FakeClose(vcp, credp);
117 code2 = afs_DoPartialWrite(vcp, &treq);
118 if (code2 && code >=0)
119 code = (ssize_t) -code2;
120 ReleaseWriteLock(&vcp->lock);
122 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
123 ICL_TYPE_INT32, (int)*offp, ICL_TYPE_INT32, count,
124 ICL_TYPE_INT32, code);
131 /* This is a complete rewrite of afs_readdir, since we can make use of
132 * filldir instead of afs_readdir_move. Note that changes to vcache/dcache
133 * handling and use of bulkstats will need to be reflected here as well.
135 static int afs_linux_readdir(struct file *fp,
136 void *dirbuf, filldir_t filldir)
138 struct vcache *avc = (struct vcache*)FILE_INODE(fp);
139 struct vrequest treq;
140 register struct dcache *tdc;
148 cred_t *credp = crref();
151 AFS_STATCNT(afs_readdir);
153 code = afs_InitReq(&treq, credp);
160 /* update the cache entry */
162 code = afs_VerifyVCache(avc, &treq);
168 /* get a reference to the entire directory */
169 tdc = afs_GetDCache(avc, 0, &treq, &origOffset, &len, 1);
174 ObtainReadLock(&avc->lock);
176 * Make sure that the data in the cache is current. There are two
177 * cases we need to worry about:
178 * 1. The cache data is being fetched by another process.
179 * 2. The cache data is no longer valid
181 while ((avc->states & CStatd)
182 && (tdc->flags & DFFetching)
183 && hsame(avc->m.DataVersion, tdc->f.versionNo)) {
184 tdc->flags |= DFWaiting;
185 ReleaseReadLock(&avc->lock);
186 afs_osi_Sleep(&tdc->validPos);
187 ObtainReadLock(&avc->lock);
189 if (!(avc->states & CStatd)
190 || !hsame(avc->m.DataVersion, tdc->f.versionNo)) {
191 ReleaseReadLock(&avc->lock);
196 /* Fill in until we get an error or we're done. This implementation
197 * takes an offset in units of blobs, rather than bytes.
200 offset = (int)fp->f_pos;
202 dirpos = BlobScan(&tdc->f.inode, offset);
206 de = (struct DirEntry*)afs_dir_GetBlob(&tdc->f.inode, dirpos);
210 ino = (avc->fid.Fid.Volume << 16) + ntohl(de->fid.vnode);
211 ino &= 0x7fffffff; /* Assumes 32 bit ino_t ..... */
212 len = strlen(de->name);
214 /* filldir returns -EINVAL when the buffer is full. */
215 code = (*filldir)(dirbuf, de->name, len, offset, ino);
219 offset = dirpos + 1 + ((len+16)>>5);
221 /* If filldir didn't fill in the last one this is still pointing to that
224 fp->f_pos = (loff_t)offset;
227 ReleaseReadLock(&avc->lock);
233 int afs_linux_select(struct inode *ip, struct file *fp, int, select_table *);
236 /* in afs_pioctl.c */
237 extern int afs_xioctl(struct inode *ip, struct file *fp,
238 unsigned int com, unsigned long arg);
241 /* We need to detect unmap's after close. To do that, we need our own
242 * vm_operations_struct's. And we need to set them up for both the
243 * private and shared mappings. The fun part is that these are all static
244 * so we'll have to initialize on the fly!
246 static struct vm_operations_struct afs_private_mmap_ops;
247 static int afs_private_mmap_ops_inited = 0;
248 static struct vm_operations_struct afs_shared_mmap_ops;
249 static int afs_shared_mmap_ops_inited = 0;
251 void afs_linux_vma_close(struct vm_area_struct *vmap)
259 vcp = (struct vcache*)FILE_INODE(vmap->vm_file);
264 afs_Trace4(afs_iclSetp, CM_TRACE_VM_CLOSE,
265 ICL_TYPE_POINTER, vcp,
266 ICL_TYPE_INT32, vcp->mapcnt,
267 ICL_TYPE_INT32, vcp->opens,
268 ICL_TYPE_INT32, vcp->execsOrWriters);
269 ObtainWriteLock(&vcp->lock, 532);
272 ReleaseWriteLock(&vcp->lock);
275 (void) afs_close(vcp, vmap->vm_file->f_flags, credp);
276 /* only decrement the execsOrWriters flag if this is not a writable
278 if (! (vmap->vm_file->f_flags & (FWRITE | FTRUNC)))
279 vcp->execsOrWriters--;
281 vcp->states &= ~CMAPPED;
286 ReleaseWriteLock(&vcp->lock);
293 static int afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap)
295 struct vcache *vcp = (struct vcache*)FILE_INODE(fp);
296 cred_t *credp = crref();
297 struct vrequest treq;
301 afs_Trace4(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
302 ICL_TYPE_POINTER, vmap->vm_start,
303 ICL_TYPE_INT32, vmap->vm_end - vmap->vm_start,
304 ICL_TYPE_INT32, vmap->vm_offset);
306 /* get a validated vcache entry */
307 code = afs_InitReq(&treq, credp);
309 code = afs_VerifyVCache(vcp, &treq);
315 osi_FlushPages(vcp, credp); /* ensure stale pages are gone */
318 code = generic_file_mmap(fp, vmap);
322 ObtainWriteLock(&vcp->lock,531);
323 /* Set out vma ops so we catch the close. The following test should be
324 * the same as used in generic_file_mmap.
326 if ((vmap->vm_flags & VM_SHARED) && (vmap->vm_flags & VM_MAYWRITE)) {
327 if (!afs_shared_mmap_ops_inited) {
328 afs_shared_mmap_ops_inited = 1;
329 afs_shared_mmap_ops = *vmap->vm_ops;
330 afs_shared_mmap_ops.close = afs_linux_vma_close;
332 vmap->vm_ops = &afs_shared_mmap_ops;
335 if (!afs_private_mmap_ops_inited) {
336 afs_private_mmap_ops_inited = 1;
337 afs_private_mmap_ops = *vmap->vm_ops;
338 afs_private_mmap_ops.close = afs_linux_vma_close;
340 vmap->vm_ops = &afs_private_mmap_ops;
344 /* Add an open reference on the first mapping. */
345 if (vcp->mapcnt == 0) {
346 vcp->execsOrWriters++;
348 vcp->states |= CMAPPED;
350 ReleaseWriteLock(&vcp->lock);
358 int afs_linux_open(struct inode *ip, struct file *fp)
361 cred_t *credp = crref();
364 code = afs_open((struct vcache**)&ip, fp->f_flags, credp);
371 /* afs_Close is called from release, since release is used to handle all
372 * file closings. In addition afs_linux_flush is called from sys_close to
373 * handle flushing the data back to the server. The kicker is that we could
374 * ignore flush completely if only sys_close took it's return value from
375 * fput. See afs_linux_flush for notes on interactions between release and
378 static int afs_linux_release(struct inode *ip, struct file *fp)
381 cred_t *credp = crref();
382 struct vcache *vcp = (struct vcache*)ip;
386 vcp->flushcnt--; /* protected by AFS global lock. */
389 code = afs_close(vcp, fp->f_flags, credp);
397 static int afs_linux_fsync(struct file *fp, struct dentry *dp)
400 struct inode *ip = FILE_INODE(fp);
401 cred_t *credp = crref();
404 code = afs_fsync((struct vcache*)ip, credp);
412 /* No support for async i/o */
413 int afs_linux_fasync(struct inode *ip, struct file *fp, int);
415 /* I don't think it will, at least not as can be detected here. */
416 int afs_linux_check_media_change(kdev_t dev);
418 /* Revalidate media and file system. */
419 int afs_linux_file_revalidate(kdev_t dev);
422 static int afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp)
425 struct vcache *vcp = (struct vcache*)FILE_INODE(fp);
426 cred_t *credp = crref();
429 /* Convert to a lock format afs_lockctl understands. */
430 memset((char*)&flock, 0, sizeof(flock));
431 flock.l_type = flp->fl_type;
432 flock.l_pid = flp->fl_pid;
434 flock.l_start = flp->fl_start;
435 flock.l_len = flp->fl_end - flp->fl_start;
438 code = afs_lockctl(vcp, &flock, cmd, credp);
446 * flush is called from sys_close. We could ignore it, but sys_close return
447 * code comes from flush, not release. We need to use release to keep
448 * the vcache open count correct. Note that flush is called before release
449 * (via fput) in sys_close. vcp->flushcnt is a bit of ugliness to avoid
450 * races and also avoid calling afs_close twice when closing the file.
451 * If we merely checked for opens > 0 in afs_linux_release, then if an
452 * new open occurred when storing back the file, afs_linux_release would
453 * incorrectly close the file and decrement the opens count. Calling afs_close
454 * on the just flushed file is wasteful, since the background daemon will
455 * execute the code that finally decides there is nothing to do.
457 int afs_linux_flush(struct file *fp)
459 struct vcache *vcp = (struct vcache *)FILE_INODE(fp);
463 /* Only do this on the last close of the file pointer. */
470 code = afs_close(vcp, fp->f_flags, credp);
471 vcp->flushcnt++; /* protected by AFS global lock. */
478 /* Not allowed to directly read a directory. */
479 int afs_linux_dir_read(struct file *fp, char *buf, size_t count, loff_t *ppos)
486 struct file_operations afs_dir_fops = {
487 NULL, /* afs_linux_lseek */
489 NULL, /* afs_linux_write */
491 NULL, /* afs_linux_select */
492 afs_xioctl, /* close enough to use the ported AFS one */
493 NULL, /* afs_linux_mmap */
495 NULL, /* afs_linux_flush */
498 NULL, /* afs_linux_fasync */
499 NULL, /* afs_linux_check_media_change */
500 NULL, /* afs_linux_file_revalidate */
504 struct file_operations afs_file_fops = {
505 NULL, /* afs_linux_lseek */
508 NULL, /* afs_linux_readdir */
509 NULL, /* afs_linux_select */
510 afs_xioctl, /* close enough to use the ported AFS one */
516 NULL, /* afs_linux_fasync */
517 NULL, /* afs_linux_check_media_change */
518 NULL, /* afs_linux_file_revalidate */
523 /**********************************************************************
524 * AFS Linux dentry operations
525 **********************************************************************/
527 /* afs_linux_revalidate
528 * Ensure vcache is stat'd before use. Return 0 if entry is valid.
530 static int afs_linux_revalidate(struct dentry *dp)
534 struct vrequest treq;
535 struct vcache *vcp = (struct vcache*)dp->d_inode;
539 /* If it's a negative dentry, then there's nothing to do. */
545 /* Make this a fast path (no crref), since it's called so often. */
546 if (vcp->states & CStatd) {
547 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
548 check_bad_parent(dp); /* check and correct mvid */
555 code = afs_InitReq(&treq, credp);
557 code = afs_VerifyVCache(vcp, &treq);
565 /* Validate a dentry. Return 0 if unchanged, 1 if VFS layer should re-evaluate.
566 * In kernels 2.2.10 and above, we are passed an additional flags var which
567 * may have either the LOOKUP_FOLLOW OR LOOKUP_DIRECTORY set in which case
568 * we are advised to follow the entry if it is a link or to make sure that
569 * it is a directory. But since the kernel itself checks these possibilities
570 * later on, we shouldn't have to do it until later. Perhaps in the future..
572 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
573 static int afs_linux_dentry_revalidate(struct dentry *dp, int flags)
575 static int afs_linux_dentry_revalidate(struct dentry *dp)
580 struct vrequest treq;
581 struct vcache *vcp = (struct vcache*)dp->d_inode;
585 /* If it's a negative dentry, then there's nothing to do. */
591 /* Make this a fast path (no crref), since it's called so often. */
592 if (vcp->states & CStatd) {
593 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
594 check_bad_parent(dp); /* check and correct mvid */
601 code = afs_InitReq(&treq, credp);
603 code = afs_VerifyVCache(vcp, &treq);
611 /* afs_dentry_iput */
612 static void afs_dentry_iput(struct dentry *dp, struct inode *ip)
614 if (ip->i_count == 0 || ip->i_count & 0xffff0000) {
615 osi_Panic("Bad refCount %d on inode 0x%x\n",
620 afs_delete_inode(ip);
624 struct dentry_operations afs_dentry_operations = {
625 afs_linux_dentry_revalidate, /* d_validate(struct dentry *) */
627 NULL, /* d_compare */
628 NULL, /* d_delete(struct dentry *) */
629 NULL, /* d_release(struct dentry *) */
630 afs_dentry_iput /* d_iput(struct dentry *, struct inode *) */
632 struct dentry_operations *afs_dops = &afs_dentry_operations;
634 /**********************************************************************
635 * AFS Linux inode operations
636 **********************************************************************/
640 * Merely need to set enough of vattr to get us through the create. Note
641 * that the higher level code (open_namei) will take care of any tuncation
642 * explicitly. Exclusive open is also taken care of in open_namei.
644 * name is in kernel space at this point.
646 int afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
649 cred_t *credp = crref();
652 const char *name = dp->d_name.name;
656 vattr.va_mode = mode;
659 code = afs_create((struct vcache*)dip, name, &vattr, NONEXCL, mode,
660 (struct vcache**)&ip, credp);
663 vattr2inode(ip, &vattr);
664 /* Reset ops if symlink or directory. */
665 if (S_ISDIR(ip->i_mode))
666 ip->i_op = &afs_dir_iops;
667 else if (S_ISLNK(ip->i_mode))
668 ip->i_op = &afs_symlink_iops;
671 d_instantiate(dp, ip);
679 /* afs_linux_lookup */
680 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
681 struct dentry *afs_linux_lookup(struct inode *dip, struct dentry *dp)
683 int afs_linux_lookup(struct inode *dip, struct dentry *dp)
687 cred_t *credp = crref();
688 struct vcache *vcp=NULL;
689 const char *comp = dp->d_name.name;
691 code = afs_lookup((struct vcache *)dip, comp, &vcp, credp);
694 struct inode *ip = (struct inode*)vcp;
695 /* Reset ops if symlink or directory. */
696 if (S_ISDIR(ip->i_mode))
697 ip->i_op = &afs_dir_iops;
698 else if (S_ISLNK(ip->i_mode))
699 ip->i_op = &afs_symlink_iops;
702 d_add(dp, (struct inode*)vcp);
707 /* It's ok for the file to not be found. That's noted by the caller by
708 * seeing that the dp->d_inode field is NULL.
710 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
714 return ERR_PTR(-code);
722 int afs_linux_link(struct dentry *olddp, struct inode *dip,
723 struct dentry *newdp)
726 cred_t *credp = crref();
727 const char *name = newdp->d_name.name;
728 struct inode *oldip = olddp->d_inode;
730 /* If afs_link returned the vnode, we could instantiate the
731 * dentry. Since it's not, we drop this one and do a new lookup.
736 code = afs_link((struct vcache*)oldip, (struct vcache*)dip, name, credp);
743 int afs_linux_unlink(struct inode *dip, struct dentry *dp)
746 cred_t *credp = crref();
747 const char *name = dp->d_name.name;
750 if (!list_empty(&dp->d_hash)) {
752 /* Install a definite non-existence if we're the only user. */
753 if (dp->d_count == 1)
758 code = afs_remove((struct vcache*)dip, name, credp);
763 d_add(dp, NULL); /* means definitely does _not_ exist */
770 int afs_linux_symlink(struct inode *dip, struct dentry *dp,
774 cred_t *credp = crref();
776 const char *name = dp->d_name.name;
778 /* If afs_symlink returned the vnode, we could instantiate the
779 * dentry. Since it's not, we drop this one and do a new lookup.
785 code = afs_symlink((struct vcache*)dip, name, &vattr, target, credp);
791 int afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
794 cred_t *credp = crref();
795 struct vcache *tvcp = NULL;
797 const char *name = dp->d_name.name;
801 vattr.va_mask = ATTR_MODE;
802 vattr.va_mode = mode;
803 code = afs_mkdir((struct vcache*)dip, name, &vattr, &tvcp, credp);
806 tvcp->v.v_op = &afs_dir_iops;
808 d_instantiate(dp, (struct inode*)tvcp);
815 int afs_linux_rmdir(struct inode *dip, struct dentry *dp)
818 cred_t *credp = crref();
819 const char *name = dp->d_name.name;
822 code = afs_rmdir((struct vcache*)dip, name, credp);
824 /* Linux likes to see ENOTDIR returned from an rmdir() syscall
825 * that failed because a directory is not empty. So, we map
826 * EEXIST to ENOTDIR on linux.
828 if (code == EEXIST) {
843 int afs_linux_rename(struct inode *oldip, struct dentry *olddp,
844 struct inode *newip, struct dentry *newdp)
847 cred_t *credp = crref();
848 const char *oldname = olddp->d_name.name;
849 const char *newname = newdp->d_name.name;
851 /* Remove old and new entries from name hash. New one will change below.
852 * While it's optimal to catch failures and re-insert newdp into hash,
853 * it's also error prone and in that case we're already dealing with error
854 * cases. Let another lookup put things right, if need be.
856 if (!list_empty(&olddp->d_hash)) {
859 if (!list_empty(&newdp->d_hash)) {
863 code = afs_rename((struct vcache*)oldip, oldname, (struct vcache*)newip,
868 d_move(olddp, newdp);
875 /* afs_linux_ireadlink
876 * Internal readlink which can return link contents to user or kernel space.
877 * Note that the buffer is NOT supposed to be null-terminated.
879 static int afs_linux_ireadlink(struct inode *ip, char *target, int maxlen,
883 cred_t *credp = crref();
887 setup_uio(&tuio, &iov, target, 0, maxlen, UIO_READ, seg);
888 code = afs_readlink((struct vcache*)ip, &tuio, credp);
892 return maxlen - tuio.uio_resid;
897 /* afs_linux_readlink
898 * Fill target (which is in user space) with contents of symlink.
900 int afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
903 struct inode *ip = dp->d_inode;
906 code = afs_linux_ireadlink(ip, target, maxlen, AFS_UIOUSER);
912 /* afs_linux_follow_link
913 * a file system dependent link following routine.
915 struct dentry * afs_linux_follow_link(struct dentry *dp,
916 struct dentry *basep,
925 name = osi_Alloc(PATH_MAX+1);
929 return ERR_PTR(-EIO);
932 code = afs_linux_ireadlink(dp->d_inode, name, PATH_MAX, AFS_UIOSYS);
941 res = lookup_dentry(name, basep, follow);
945 osi_Free(name, PATH_MAX+1);
950 /* afs_linux_readpage
951 * all reads come through here. A strategy-like read call.
953 int afs_linux_readpage(struct file *fp, struct page *pp)
956 cred_t *credp = crref();
957 ulong address = afs_linux_page_address(pp);
960 struct inode *ip = FILE_INODE(fp);
961 int cnt = atomic_read(&pp->count);
964 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE,
965 ICL_TYPE_POINTER, ip,
966 ICL_TYPE_POINTER, pp,
968 ICL_TYPE_INT32, 99999); /* not a possible code value */
969 atomic_add(1, &pp->count);
970 set_bit(PG_locked, &pp->flags); /* other bits? See mm.h */
971 clear_bit(PG_error, &pp->flags);
973 setup_uio(&tuio, &iovec, (char*)address, pp->offset, PAGESIZE,
974 UIO_READ, AFS_UIOSYS);
975 code = afs_rdwr((struct vcache*)ip, &tuio, UIO_READ, 0, credp);
978 if (tuio.uio_resid) /* zero remainder of page */
979 memset((void*)(address+(PAGESIZE-tuio.uio_resid)), 0,
981 set_bit(PG_uptodate, &pp->flags);
984 clear_bit(PG_locked, &pp->flags);
989 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE,
990 ICL_TYPE_POINTER, ip,
991 ICL_TYPE_POINTER, pp,
993 ICL_TYPE_INT32, code);
999 /* afs_linux_writepage - is this used anywhere? */
1000 int afs_linux_writepage(struct inode *ip, struct page *) { return -EINVAL };
1002 /* afs_linux_bmap - supports generic_readpage, but we roll our own. */
1003 int afs_linux_bmap(struct inode *ip, int) { return -EINVAL; }
1005 /* afs_linux_truncate
1006 * Handles discarding disk blocks if this were a device. ext2 indicates we
1007 * may need to zero partial last pages of memory mapped files.
1009 void afs_linux_truncate(struct inode *ip)
1014 /* afs_linux_permission
1015 * Check access rights - returns error if can't check or permission denied.
1017 int afs_linux_permission(struct inode *ip, int mode)
1020 cred_t *credp = crref();
1024 if (mode & MAY_EXEC) tmp |= VEXEC;
1025 if (mode & MAY_READ) tmp |= VREAD;
1026 if (mode & MAY_WRITE) tmp |= VWRITE;
1027 code = afs_access((struct vcache*)ip, tmp, credp);
1036 /* msdos sector mapping hack for memory mapping. */
1037 int afs_linux_smap(struct inode *ip, int) { return -EINVAL; }
1040 /* afs_linux_updatepage
1041 * What one would have thought was writepage - write dirty page to file.
1042 * Called from generic_file_write. buffer is still in user space. pagep
1043 * has been filled in with old data if we're updating less than a page.
1045 int afs_linux_updatepage(struct file *fp, struct page *pp,
1046 unsigned long offset,
1047 unsigned int count, int sync)
1049 struct vcache *vcp = (struct vcache *)FILE_INODE(fp);
1050 u8 *page_addr = (u8*) afs_linux_page_address(pp);
1056 set_bit(PG_locked, &pp->flags);
1060 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1061 ICL_TYPE_POINTER, pp,
1062 ICL_TYPE_INT32, atomic_read(&pp->count),
1063 ICL_TYPE_INT32, 99999);
1064 setup_uio(&tuio, &iovec, page_addr + offset, pp->offset + offset, count,
1065 UIO_WRITE, AFS_UIOSYS);
1067 code = afs_write(vcp, &tuio, fp->f_flags, credp, 0);
1071 code = code ? -code : count - tuio.uio_resid;
1072 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1073 ICL_TYPE_POINTER, pp,
1074 ICL_TYPE_INT32, atomic_read(&pp->count),
1075 ICL_TYPE_INT32, code);
1080 clear_bit(PG_locked, &pp->flags);
1086 struct inode_operations afs_iops = {
1087 &afs_file_fops, /* file operations */
1088 NULL, /* afs_linux_create */
1089 NULL, /* afs_linux_lookup */
1090 NULL, /* afs_linux_link */
1091 NULL, /* afs_linux_unlink */
1092 NULL, /* afs_linux_symlink */
1093 NULL, /* afs_linux_mkdir */
1094 NULL, /* afs_linux_rmdir */
1095 NULL, /* afs_linux_mknod */
1096 NULL, /* afs_linux_rename */
1097 NULL, /* afs_linux_readlink */
1098 NULL, /* afs_linux_follow_link */
1100 NULL, /* afs_linux_writepage */
1101 NULL, /* afs_linux_bmap */
1102 NULL, /* afs_linux_truncate */
1103 afs_linux_permission,
1104 NULL, /* afs_linux_smap */
1105 afs_linux_updatepage,
1106 afs_linux_revalidate,
1109 /* Separate ops vector for directories. Linux 2.2 tests type of inode
1110 * by what sort of operation is allowed.....
1112 struct inode_operations afs_dir_iops = {
1113 &afs_dir_fops, /* file operations for directories */
1121 NULL, /* afs_linux_mknod */
1123 NULL, /* afs_linux_readlink */
1124 NULL, /* afs_linux_follow_link */
1125 NULL, /* afs_linux_readpage */
1126 NULL, /* afs_linux_writepage */
1127 NULL, /* afs_linux_bmap */
1128 NULL, /* afs_linux_truncate */
1129 afs_linux_permission,
1130 NULL, /* afs_linux_smap */
1131 NULL, /* afs_linux_updatepage */
1132 afs_linux_revalidate,
1135 struct inode_operations *afs_ops = &afs_iops;
1137 /* We really need a separate symlink set of ops, since do_follow_link()
1138 * determines if it _is_ a link by checking if the follow_link op is set.
1140 struct inode_operations afs_symlink_iops = {
1141 NULL, /* file operations */
1149 NULL, /* afs_linux_mknod */
1152 afs_linux_follow_link,
1153 NULL, /* readpage */
1154 NULL, /* afs_linux_writepage */
1155 NULL, /* afs_linux_bmap */
1156 NULL, /* afs_linux_truncate */
1157 afs_linux_permission, /* tho the code appears to indicate not used? */
1158 NULL, /* afs_linux_smap */
1159 NULL, /* updatepage */
1160 afs_linux_revalidate, /* tho the code appears to indicate not used? */