2 * Copyright 2000, International Business Machines Corporation and others.
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
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.
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
23 #include "../afs/param.h"
24 #include "../afs/sysincludes.h"
25 #include "../afs/afsincludes.h"
26 #include "../afs/afs_stats.h"
28 #include "../h/pagemap.h"
30 extern struct vcache *afs_globalVp;
32 extern struct dentry_operations *afs_dops;
33 extern struct inode_operations afs_dir_iops;
34 extern struct inode_operations afs_symlink_iops;
38 static int afs_linux_lseek(struct inode *ip, struct file *fp, off_t, int) {}
41 static ssize_t afs_linux_read(struct file *fp, char *buf, size_t count,
45 struct vcache *vcp = (struct vcache*)fp->f_dentry->d_inode;
46 cred_t *credp = crref();
50 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
51 ICL_TYPE_INT32, (int)*offp,
52 ICL_TYPE_INT32, count,
53 ICL_TYPE_INT32, 99999);
55 /* get a validated vcache entry */
56 code = afs_InitReq(&treq, credp);
58 code = afs_VerifyVCache(vcp, &treq);
63 osi_FlushPages(vcp, credp); /* ensure stale pages are gone */
65 code = generic_file_read(fp, buf, count, offp);
69 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
70 ICL_TYPE_INT32, (int)*offp,
71 ICL_TYPE_INT32, count,
72 ICL_TYPE_INT32, code);
80 /* Now we have integrated VM for writes as well as reads. generic_file_write
81 * also takes care of re-positioning the pointer if file is open in append
82 * mode. Call fake open/close to ensure we do writes of core dumps.
84 static ssize_t afs_linux_write(struct file *fp, const char *buf, size_t count,
89 struct vcache *vcp = (struct vcache *)fp->f_dentry->d_inode;
91 cred_t *credp = crref();
95 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
96 ICL_TYPE_INT32, (int)*offp, ICL_TYPE_INT32, count,
97 ICL_TYPE_INT32, (fp->f_flags & O_APPEND) ? 99998 : 99999);
100 /* get a validated vcache entry */
101 code = (ssize_t)afs_InitReq(&treq, credp);
103 code = (ssize_t)afs_VerifyVCache(vcp, &treq);
105 ObtainWriteLock(&vcp->lock, 529);
107 ReleaseWriteLock(&vcp->lock);
112 code = generic_file_write(fp, buf, count, offp);
116 ObtainWriteLock(&vcp->lock, 530);
117 vcp->m.Date = osi_Time(); /* set modification time */
118 afs_FakeClose(vcp, credp);
120 code2 = afs_DoPartialWrite(vcp, &treq);
121 if (code2 && code >=0)
122 code = (ssize_t) -code2;
123 ReleaseWriteLock(&vcp->lock);
125 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
126 ICL_TYPE_INT32, (int)*offp, ICL_TYPE_INT32, count,
127 ICL_TYPE_INT32, code);
134 /* This is a complete rewrite of afs_readdir, since we can make use of
135 * filldir instead of afs_readdir_move. Note that changes to vcache/dcache
136 * handling and use of bulkstats will need to be reflected here as well.
138 static int afs_linux_readdir(struct file *fp,
139 void *dirbuf, filldir_t filldir)
141 struct vcache *avc = (struct vcache*)FILE_INODE(fp);
142 struct vrequest treq;
143 register struct dcache *tdc;
151 cred_t *credp = crref();
154 AFS_STATCNT(afs_readdir);
156 code = afs_InitReq(&treq, credp);
163 /* update the cache entry */
165 code = afs_VerifyVCache(avc, &treq);
171 /* get a reference to the entire directory */
172 tdc = afs_GetDCache(avc, 0, &treq, &origOffset, &len, 1);
177 ObtainReadLock(&avc->lock);
179 * Make sure that the data in the cache is current. There are two
180 * cases we need to worry about:
181 * 1. The cache data is being fetched by another process.
182 * 2. The cache data is no longer valid
184 while ((avc->states & CStatd)
185 && (tdc->flags & DFFetching)
186 && hsame(avc->m.DataVersion, tdc->f.versionNo)) {
187 tdc->flags |= DFWaiting;
188 ReleaseReadLock(&avc->lock);
189 afs_osi_Sleep(&tdc->validPos);
190 ObtainReadLock(&avc->lock);
192 if (!(avc->states & CStatd)
193 || !hsame(avc->m.DataVersion, tdc->f.versionNo)) {
194 ReleaseReadLock(&avc->lock);
199 /* Fill in until we get an error or we're done. This implementation
200 * takes an offset in units of blobs, rather than bytes.
203 offset = (int)fp->f_pos;
205 dirpos = BlobScan(&tdc->f.inode, offset);
209 de = (struct DirEntry*)afs_dir_GetBlob(&tdc->f.inode, dirpos);
213 ino = (avc->fid.Fid.Volume << 16) + ntohl(de->fid.vnode);
214 ino &= 0x7fffffff; /* Assumes 32 bit ino_t ..... */
215 len = strlen(de->name);
217 /* filldir returns -EINVAL when the buffer is full. */
218 code = (*filldir)(dirbuf, de->name, len, offset, ino);
222 offset = dirpos + 1 + ((len+16)>>5);
224 /* If filldir didn't fill in the last one this is still pointing to that
227 fp->f_pos = (loff_t)offset;
230 ReleaseReadLock(&avc->lock);
236 int afs_linux_select(struct inode *ip, struct file *fp, int, select_table *);
239 /* in afs_pioctl.c */
240 extern int afs_xioctl(struct inode *ip, struct file *fp,
241 unsigned int com, unsigned long arg);
244 /* We need to detect unmap's after close. To do that, we need our own
245 * vm_operations_struct's. And we need to set them up for both the
246 * private and shared mappings. The fun part is that these are all static
247 * so we'll have to initialize on the fly!
249 static struct vm_operations_struct afs_private_mmap_ops;
250 static int afs_private_mmap_ops_inited = 0;
251 static struct vm_operations_struct afs_shared_mmap_ops;
252 static int afs_shared_mmap_ops_inited = 0;
254 void afs_linux_vma_close(struct vm_area_struct *vmap)
262 vcp = (struct vcache*)FILE_INODE(vmap->vm_file);
267 afs_Trace4(afs_iclSetp, CM_TRACE_VM_CLOSE,
268 ICL_TYPE_POINTER, vcp,
269 ICL_TYPE_INT32, vcp->mapcnt,
270 ICL_TYPE_INT32, vcp->opens,
271 ICL_TYPE_INT32, vcp->execsOrWriters);
272 ObtainWriteLock(&vcp->lock, 532);
275 ReleaseWriteLock(&vcp->lock);
278 (void) afs_close(vcp, vmap->vm_file->f_flags, credp);
279 /* only decrement the execsOrWriters flag if this is not a writable
281 if (! (vmap->vm_file->f_flags & (FWRITE | FTRUNC)))
282 vcp->execsOrWriters--;
284 vcp->states &= ~CMAPPED;
289 ReleaseWriteLock(&vcp->lock);
296 static int afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap)
298 struct vcache *vcp = (struct vcache*)FILE_INODE(fp);
299 cred_t *credp = crref();
300 struct vrequest treq;
304 afs_Trace4(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
305 ICL_TYPE_POINTER, vmap->vm_start,
306 ICL_TYPE_INT32, vmap->vm_end - vmap->vm_start,
307 ICL_TYPE_INT32, vmap->vm_offset);
309 /* get a validated vcache entry */
310 code = afs_InitReq(&treq, credp);
312 code = afs_VerifyVCache(vcp, &treq);
318 osi_FlushPages(vcp, credp); /* ensure stale pages are gone */
321 code = generic_file_mmap(fp, vmap);
325 ObtainWriteLock(&vcp->lock,531);
326 /* Set out vma ops so we catch the close. The following test should be
327 * the same as used in generic_file_mmap.
329 if ((vmap->vm_flags & VM_SHARED) && (vmap->vm_flags & VM_MAYWRITE)) {
330 if (!afs_shared_mmap_ops_inited) {
331 afs_shared_mmap_ops_inited = 1;
332 afs_shared_mmap_ops = *vmap->vm_ops;
333 afs_shared_mmap_ops.close = afs_linux_vma_close;
335 vmap->vm_ops = &afs_shared_mmap_ops;
338 if (!afs_private_mmap_ops_inited) {
339 afs_private_mmap_ops_inited = 1;
340 afs_private_mmap_ops = *vmap->vm_ops;
341 afs_private_mmap_ops.close = afs_linux_vma_close;
343 vmap->vm_ops = &afs_private_mmap_ops;
347 /* Add an open reference on the first mapping. */
348 if (vcp->mapcnt == 0) {
349 vcp->execsOrWriters++;
351 vcp->states |= CMAPPED;
353 ReleaseWriteLock(&vcp->lock);
361 int afs_linux_open(struct inode *ip, struct file *fp)
364 cred_t *credp = crref();
367 code = afs_open((struct vcache**)&ip, fp->f_flags, credp);
374 /* afs_Close is called from release, since release is used to handle all
375 * file closings. In addition afs_linux_flush is called from sys_close to
376 * handle flushing the data back to the server. The kicker is that we could
377 * ignore flush completely if only sys_close took it's return value from
378 * fput. See afs_linux_flush for notes on interactions between release and
381 static int afs_linux_release(struct inode *ip, struct file *fp)
384 cred_t *credp = crref();
385 struct vcache *vcp = (struct vcache*)ip;
389 vcp->flushcnt--; /* protected by AFS global lock. */
392 code = afs_close(vcp, fp->f_flags, credp);
400 static int afs_linux_fsync(struct file *fp, struct dentry *dp)
403 struct inode *ip = FILE_INODE(fp);
404 cred_t *credp = crref();
407 code = afs_fsync((struct vcache*)ip, credp);
415 /* No support for async i/o */
416 int afs_linux_fasync(struct inode *ip, struct file *fp, int);
418 /* I don't think it will, at least not as can be detected here. */
419 int afs_linux_check_media_change(kdev_t dev);
421 /* Revalidate media and file system. */
422 int afs_linux_file_revalidate(kdev_t dev);
425 static int afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp)
428 struct vcache *vcp = (struct vcache*)FILE_INODE(fp);
429 cred_t *credp = crref();
432 /* Convert to a lock format afs_lockctl understands. */
433 memset((char*)&flock, 0, sizeof(flock));
434 flock.l_type = flp->fl_type;
435 flock.l_pid = flp->fl_pid;
437 flock.l_start = flp->fl_start;
438 flock.l_len = flp->fl_end - flp->fl_start;
441 code = afs_lockctl(vcp, &flock, cmd, credp);
449 * flush is called from sys_close. We could ignore it, but sys_close return
450 * code comes from flush, not release. We need to use release to keep
451 * the vcache open count correct. Note that flush is called before release
452 * (via fput) in sys_close. vcp->flushcnt is a bit of ugliness to avoid
453 * races and also avoid calling afs_close twice when closing the file.
454 * If we merely checked for opens > 0 in afs_linux_release, then if an
455 * new open occurred when storing back the file, afs_linux_release would
456 * incorrectly close the file and decrement the opens count. Calling afs_close
457 * on the just flushed file is wasteful, since the background daemon will
458 * execute the code that finally decides there is nothing to do.
460 int afs_linux_flush(struct file *fp)
462 struct vcache *vcp = (struct vcache *)FILE_INODE(fp);
466 /* Only do this on the last close of the file pointer. */
473 code = afs_close(vcp, fp->f_flags, credp);
474 vcp->flushcnt++; /* protected by AFS global lock. */
481 /* Not allowed to directly read a directory. */
482 int afs_linux_dir_read(struct file *fp, char *buf, size_t count, loff_t *ppos)
489 struct file_operations afs_dir_fops = {
490 NULL, /* afs_linux_lseek */
492 NULL, /* afs_linux_write */
494 NULL, /* afs_linux_select */
495 afs_xioctl, /* close enough to use the ported AFS one */
496 NULL, /* afs_linux_mmap */
498 NULL, /* afs_linux_flush */
501 NULL, /* afs_linux_fasync */
502 NULL, /* afs_linux_check_media_change */
503 NULL, /* afs_linux_file_revalidate */
507 struct file_operations afs_file_fops = {
508 NULL, /* afs_linux_lseek */
511 NULL, /* afs_linux_readdir */
512 NULL, /* afs_linux_select */
513 afs_xioctl, /* close enough to use the ported AFS one */
519 NULL, /* afs_linux_fasync */
520 NULL, /* afs_linux_check_media_change */
521 NULL, /* afs_linux_file_revalidate */
526 /**********************************************************************
527 * AFS Linux dentry operations
528 **********************************************************************/
530 /* afs_linux_revalidate
531 * Ensure vcache is stat'd before use. Return 0 if entry is valid.
533 static int afs_linux_revalidate(struct dentry *dp)
537 struct vrequest treq;
538 struct vcache *vcp = (struct vcache*)dp->d_inode;
542 /* If it's a negative dentry, then there's nothing to do. */
548 /* Make this a fast path (no crref), since it's called so often. */
549 if (vcp->states & CStatd) {
550 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
551 check_bad_parent(dp); /* check and correct mvid */
558 code = afs_InitReq(&treq, credp);
560 code = afs_VerifyVCache(vcp, &treq);
568 /* Validate a dentry. Return 0 if unchanged, 1 if VFS layer should re-evaluate.
569 * In kernels 2.2.10 and above, we are passed an additional flags var which
570 * may have either the LOOKUP_FOLLOW OR LOOKUP_DIRECTORY set in which case
571 * we are advised to follow the entry if it is a link or to make sure that
572 * it is a directory. But since the kernel itself checks these possibilities
573 * later on, we shouldn't have to do it until later. Perhaps in the future..
575 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
576 static int afs_linux_dentry_revalidate(struct dentry *dp, int flags)
578 static int afs_linux_dentry_revalidate(struct dentry *dp)
583 struct vrequest treq;
584 struct vcache *vcp = (struct vcache*)dp->d_inode;
588 /* If it's a negative dentry, then there's nothing to do. */
594 /* Make this a fast path (no crref), since it's called so often. */
595 if (vcp->states & CStatd) {
596 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
597 check_bad_parent(dp); /* check and correct mvid */
604 code = afs_InitReq(&treq, credp);
606 code = afs_VerifyVCache(vcp, &treq);
614 /* afs_dentry_iput */
615 static void afs_dentry_iput(struct dentry *dp, struct inode *ip)
617 if (ip->i_count == 0 || ip->i_count & 0xffff0000) {
618 osi_Panic("Bad refCount %d on inode 0x%x\n",
623 afs_delete_inode(ip);
627 struct dentry_operations afs_dentry_operations = {
628 afs_linux_dentry_revalidate, /* d_validate(struct dentry *) */
630 NULL, /* d_compare */
631 NULL, /* d_delete(struct dentry *) */
632 NULL, /* d_release(struct dentry *) */
633 afs_dentry_iput /* d_iput(struct dentry *, struct inode *) */
635 struct dentry_operations *afs_dops = &afs_dentry_operations;
637 /**********************************************************************
638 * AFS Linux inode operations
639 **********************************************************************/
643 * Merely need to set enough of vattr to get us through the create. Note
644 * that the higher level code (open_namei) will take care of any tuncation
645 * explicitly. Exclusive open is also taken care of in open_namei.
647 * name is in kernel space at this point.
649 int afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
652 cred_t *credp = crref();
655 const char *name = dp->d_name.name;
659 vattr.va_mode = mode;
662 code = afs_create((struct vcache*)dip, name, &vattr, NONEXCL, mode,
663 (struct vcache**)&ip, credp);
666 vattr2inode(ip, &vattr);
667 /* Reset ops if symlink or directory. */
668 if (S_ISDIR(ip->i_mode))
669 ip->i_op = &afs_dir_iops;
670 else if (S_ISLNK(ip->i_mode))
671 ip->i_op = &afs_symlink_iops;
674 d_instantiate(dp, ip);
682 /* afs_linux_lookup */
683 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
684 struct dentry *afs_linux_lookup(struct inode *dip, struct dentry *dp)
686 int afs_linux_lookup(struct inode *dip, struct dentry *dp)
690 cred_t *credp = crref();
691 struct vcache *vcp=NULL;
692 const char *comp = dp->d_name.name;
694 code = afs_lookup((struct vcache *)dip, comp, &vcp, credp);
697 struct inode *ip = (struct inode*)vcp;
698 /* Reset ops if symlink or directory. */
699 if (S_ISDIR(ip->i_mode))
700 ip->i_op = &afs_dir_iops;
701 else if (S_ISLNK(ip->i_mode))
702 ip->i_op = &afs_symlink_iops;
705 d_add(dp, (struct inode*)vcp);
710 /* It's ok for the file to not be found. That's noted by the caller by
711 * seeing that the dp->d_inode field is NULL.
713 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
717 return ERR_PTR(-code);
725 int afs_linux_link(struct dentry *olddp, struct inode *dip,
726 struct dentry *newdp)
729 cred_t *credp = crref();
730 const char *name = newdp->d_name.name;
731 struct inode *oldip = olddp->d_inode;
733 /* If afs_link returned the vnode, we could instantiate the
734 * dentry. Since it's not, we drop this one and do a new lookup.
739 code = afs_link((struct vcache*)oldip, (struct vcache*)dip, name, credp);
746 int afs_linux_unlink(struct inode *dip, struct dentry *dp)
749 cred_t *credp = crref();
750 const char *name = dp->d_name.name;
753 if (!list_empty(&dp->d_hash)) {
755 /* Install a definite non-existence if we're the only user. */
756 if (dp->d_count == 1)
761 code = afs_remove((struct vcache*)dip, name, credp);
766 d_add(dp, NULL); /* means definitely does _not_ exist */
773 int afs_linux_symlink(struct inode *dip, struct dentry *dp,
777 cred_t *credp = crref();
779 const char *name = dp->d_name.name;
781 /* If afs_symlink returned the vnode, we could instantiate the
782 * dentry. Since it's not, we drop this one and do a new lookup.
788 code = afs_symlink((struct vcache*)dip, name, &vattr, target, credp);
794 int afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
797 cred_t *credp = crref();
798 struct vcache *tvcp = NULL;
800 const char *name = dp->d_name.name;
804 vattr.va_mask = ATTR_MODE;
805 vattr.va_mode = mode;
806 code = afs_mkdir((struct vcache*)dip, name, &vattr, &tvcp, credp);
809 tvcp->v.v_op = &afs_dir_iops;
811 d_instantiate(dp, (struct inode*)tvcp);
818 int afs_linux_rmdir(struct inode *dip, struct dentry *dp)
821 cred_t *credp = crref();
822 const char *name = dp->d_name.name;
825 code = afs_rmdir((struct vcache*)dip, name, credp);
827 /* Linux likes to see ENOTDIR returned from an rmdir() syscall
828 * that failed because a directory is not empty. So, we map
829 * EEXIST to ENOTDIR on linux.
831 if (code == EEXIST) {
846 int afs_linux_rename(struct inode *oldip, struct dentry *olddp,
847 struct inode *newip, struct dentry *newdp)
850 cred_t *credp = crref();
851 const char *oldname = olddp->d_name.name;
852 const char *newname = newdp->d_name.name;
854 /* Remove old and new entries from name hash. New one will change below.
855 * While it's optimal to catch failures and re-insert newdp into hash,
856 * it's also error prone and in that case we're already dealing with error
857 * cases. Let another lookup put things right, if need be.
859 if (!list_empty(&olddp->d_hash)) {
862 if (!list_empty(&newdp->d_hash)) {
866 code = afs_rename((struct vcache*)oldip, oldname, (struct vcache*)newip,
871 d_move(olddp, newdp);
878 /* afs_linux_ireadlink
879 * Internal readlink which can return link contents to user or kernel space.
880 * Note that the buffer is NOT supposed to be null-terminated.
882 static int afs_linux_ireadlink(struct inode *ip, char *target, int maxlen,
886 cred_t *credp = crref();
890 setup_uio(&tuio, &iov, target, 0, maxlen, UIO_READ, seg);
891 code = afs_readlink((struct vcache*)ip, &tuio, credp);
895 return maxlen - tuio.uio_resid;
900 /* afs_linux_readlink
901 * Fill target (which is in user space) with contents of symlink.
903 int afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
906 struct inode *ip = dp->d_inode;
909 code = afs_linux_ireadlink(ip, target, maxlen, AFS_UIOUSER);
915 /* afs_linux_follow_link
916 * a file system dependent link following routine.
918 struct dentry * afs_linux_follow_link(struct dentry *dp,
919 struct dentry *basep,
928 name = osi_Alloc(PATH_MAX+1);
932 return ERR_PTR(-EIO);
935 code = afs_linux_ireadlink(dp->d_inode, name, PATH_MAX, AFS_UIOSYS);
944 res = lookup_dentry(name, basep, follow);
948 osi_Free(name, PATH_MAX+1);
953 /* afs_linux_readpage
954 * all reads come through here. A strategy-like read call.
956 int afs_linux_readpage(struct file *fp, struct page *pp)
959 cred_t *credp = crref();
960 ulong address = afs_linux_page_address(pp);
963 struct inode *ip = FILE_INODE(fp);
964 int cnt = atomic_read(&pp->count);
967 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE,
968 ICL_TYPE_POINTER, ip,
969 ICL_TYPE_POINTER, pp,
971 ICL_TYPE_INT32, 99999); /* not a possible code value */
972 atomic_add(1, &pp->count);
973 set_bit(PG_locked, &pp->flags); /* other bits? See mm.h */
974 clear_bit(PG_error, &pp->flags);
976 setup_uio(&tuio, &iovec, (char*)address, pp->offset, PAGESIZE,
977 UIO_READ, AFS_UIOSYS);
978 code = afs_rdwr((struct vcache*)ip, &tuio, UIO_READ, 0, credp);
981 if (tuio.uio_resid) /* zero remainder of page */
982 memset((void*)(address+(PAGESIZE-tuio.uio_resid)), 0,
984 set_bit(PG_uptodate, &pp->flags);
987 clear_bit(PG_locked, &pp->flags);
992 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE,
993 ICL_TYPE_POINTER, ip,
994 ICL_TYPE_POINTER, pp,
996 ICL_TYPE_INT32, code);
1002 /* afs_linux_writepage - is this used anywhere? */
1003 int afs_linux_writepage(struct inode *ip, struct page *) { return -EINVAL };
1005 /* afs_linux_bmap - supports generic_readpage, but we roll our own. */
1006 int afs_linux_bmap(struct inode *ip, int) { return -EINVAL; }
1008 /* afs_linux_truncate
1009 * Handles discarding disk blocks if this were a device. ext2 indicates we
1010 * may need to zero partial last pages of memory mapped files.
1012 void afs_linux_truncate(struct inode *ip)
1017 /* afs_linux_permission
1018 * Check access rights - returns error if can't check or permission denied.
1020 int afs_linux_permission(struct inode *ip, int mode)
1023 cred_t *credp = crref();
1027 if (mode & MAY_EXEC) tmp |= VEXEC;
1028 if (mode & MAY_READ) tmp |= VREAD;
1029 if (mode & MAY_WRITE) tmp |= VWRITE;
1030 code = afs_access((struct vcache*)ip, tmp, credp);
1039 /* msdos sector mapping hack for memory mapping. */
1040 int afs_linux_smap(struct inode *ip, int) { return -EINVAL; }
1043 /* afs_linux_updatepage
1044 * What one would have thought was writepage - write dirty page to file.
1045 * Called from generic_file_write. buffer is still in user space. pagep
1046 * has been filled in with old data if we're updating less than a page.
1048 int afs_linux_updatepage(struct file *fp, struct page *pp,
1049 unsigned long offset,
1050 unsigned int count, int sync)
1052 struct vcache *vcp = (struct vcache *)FILE_INODE(fp);
1053 u8 *page_addr = (u8*) afs_linux_page_address(pp);
1059 set_bit(PG_locked, &pp->flags);
1063 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1064 ICL_TYPE_POINTER, pp,
1065 ICL_TYPE_INT32, atomic_read(&pp->count),
1066 ICL_TYPE_INT32, 99999);
1067 setup_uio(&tuio, &iovec, page_addr + offset, pp->offset + offset, count,
1068 UIO_WRITE, AFS_UIOSYS);
1070 code = afs_write(vcp, &tuio, fp->f_flags, credp, 0);
1074 code = code ? -code : count - tuio.uio_resid;
1075 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1076 ICL_TYPE_POINTER, pp,
1077 ICL_TYPE_INT32, atomic_read(&pp->count),
1078 ICL_TYPE_INT32, code);
1083 clear_bit(PG_locked, &pp->flags);
1089 struct inode_operations afs_iops = {
1090 &afs_file_fops, /* file operations */
1091 NULL, /* afs_linux_create */
1092 NULL, /* afs_linux_lookup */
1093 NULL, /* afs_linux_link */
1094 NULL, /* afs_linux_unlink */
1095 NULL, /* afs_linux_symlink */
1096 NULL, /* afs_linux_mkdir */
1097 NULL, /* afs_linux_rmdir */
1098 NULL, /* afs_linux_mknod */
1099 NULL, /* afs_linux_rename */
1100 NULL, /* afs_linux_readlink */
1101 NULL, /* afs_linux_follow_link */
1103 NULL, /* afs_linux_writepage */
1104 NULL, /* afs_linux_bmap */
1105 NULL, /* afs_linux_truncate */
1106 afs_linux_permission,
1107 NULL, /* afs_linux_smap */
1108 afs_linux_updatepage,
1109 afs_linux_revalidate,
1112 /* Separate ops vector for directories. Linux 2.2 tests type of inode
1113 * by what sort of operation is allowed.....
1115 struct inode_operations afs_dir_iops = {
1116 &afs_dir_fops, /* file operations for directories */
1124 NULL, /* afs_linux_mknod */
1126 NULL, /* afs_linux_readlink */
1127 NULL, /* afs_linux_follow_link */
1128 NULL, /* afs_linux_readpage */
1129 NULL, /* afs_linux_writepage */
1130 NULL, /* afs_linux_bmap */
1131 NULL, /* afs_linux_truncate */
1132 afs_linux_permission,
1133 NULL, /* afs_linux_smap */
1134 NULL, /* afs_linux_updatepage */
1135 afs_linux_revalidate,
1138 struct inode_operations *afs_ops = &afs_iops;
1140 /* We really need a separate symlink set of ops, since do_follow_link()
1141 * determines if it _is_ a link by checking if the follow_link op is set.
1143 struct inode_operations afs_symlink_iops = {
1144 NULL, /* file operations */
1152 NULL, /* afs_linux_mknod */
1155 afs_linux_follow_link,
1156 NULL, /* readpage */
1157 NULL, /* afs_linux_writepage */
1158 NULL, /* afs_linux_bmap */
1159 NULL, /* afs_linux_truncate */
1160 afs_linux_permission, /* tho the code appears to indicate not used? */
1161 NULL, /* afs_linux_smap */
1162 NULL, /* updatepage */
1163 afs_linux_revalidate, /* tho the code appears to indicate not used? */