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"
29 #if defined(AFS_LINUX24_ENV)
30 #include "../h/smp_lock.h"
33 extern struct vcache *afs_globalVp;
35 extern struct dentry_operations *afs_dops;
36 #if defined(AFS_LINUX24_ENV)
37 extern struct inode_operations afs_file_iops;
38 extern struct address_space_operations afs_file_aops;
39 struct address_space_operations afs_symlink_aops;
41 extern struct inode_operations afs_dir_iops;
42 extern struct inode_operations afs_symlink_iops;
46 static int afs_linux_lseek(struct inode *ip, struct file *fp, off_t, int) {}
49 static ssize_t afs_linux_read(struct file *fp, char *buf, size_t count,
53 struct vcache *vcp = (struct vcache*)fp->f_dentry->d_inode;
54 cred_t *credp = crref();
58 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
59 ICL_TYPE_INT32, (int)*offp,
60 ICL_TYPE_INT32, count,
61 ICL_TYPE_INT32, 99999);
63 /* get a validated vcache entry */
64 code = afs_InitReq(&treq, credp);
66 code = afs_VerifyVCache(vcp, &treq);
71 osi_FlushPages(vcp, credp); /* ensure stale pages are gone */
73 code = generic_file_read(fp, buf, count, offp);
77 afs_Trace4(afs_iclSetp, CM_TRACE_READOP, ICL_TYPE_POINTER, vcp,
78 ICL_TYPE_INT32, (int)*offp,
79 ICL_TYPE_INT32, count,
80 ICL_TYPE_INT32, code);
88 /* Now we have integrated VM for writes as well as reads. generic_file_write
89 * also takes care of re-positioning the pointer if file is open in append
90 * mode. Call fake open/close to ensure we do writes of core dumps.
92 static ssize_t afs_linux_write(struct file *fp, const char *buf, size_t count,
97 struct vcache *vcp = (struct vcache *)fp->f_dentry->d_inode;
99 cred_t *credp = crref();
103 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
104 ICL_TYPE_INT32, (int)*offp, ICL_TYPE_INT32, count,
105 ICL_TYPE_INT32, (fp->f_flags & O_APPEND) ? 99998 : 99999);
108 /* get a validated vcache entry */
109 code = (ssize_t)afs_InitReq(&treq, credp);
111 code = (ssize_t)afs_VerifyVCache(vcp, &treq);
113 ObtainWriteLock(&vcp->lock, 529);
115 ReleaseWriteLock(&vcp->lock);
120 code = generic_file_write(fp, buf, count, offp);
124 ObtainWriteLock(&vcp->lock, 530);
125 vcp->m.Date = osi_Time(); /* set modification time */
126 afs_FakeClose(vcp, credp);
128 code2 = afs_DoPartialWrite(vcp, &treq);
129 if (code2 && code >=0)
130 code = (ssize_t) -code2;
131 ReleaseWriteLock(&vcp->lock);
133 afs_Trace4(afs_iclSetp, CM_TRACE_WRITEOP, ICL_TYPE_POINTER, vcp,
134 ICL_TYPE_INT32, (int)*offp, ICL_TYPE_INT32, count,
135 ICL_TYPE_INT32, code);
142 /* This is a complete rewrite of afs_readdir, since we can make use of
143 * filldir instead of afs_readdir_move. Note that changes to vcache/dcache
144 * handling and use of bulkstats will need to be reflected here as well.
146 static int afs_linux_readdir(struct file *fp,
147 void *dirbuf, filldir_t filldir)
149 struct vcache *avc = (struct vcache*)FILE_INODE(fp);
150 struct vrequest treq;
151 register struct dcache *tdc;
159 cred_t *credp = crref();
162 AFS_STATCNT(afs_readdir);
164 code = afs_InitReq(&treq, credp);
171 /* update the cache entry */
173 code = afs_VerifyVCache(avc, &treq);
179 /* get a reference to the entire directory */
180 tdc = afs_GetDCache(avc, 0, &treq, &origOffset, &len, 1);
185 ObtainReadLock(&avc->lock);
187 * Make sure that the data in the cache is current. There are two
188 * cases we need to worry about:
189 * 1. The cache data is being fetched by another process.
190 * 2. The cache data is no longer valid
192 while ((avc->states & CStatd)
193 && (tdc->flags & DFFetching)
194 && hsame(avc->m.DataVersion, tdc->f.versionNo)) {
195 tdc->flags |= DFWaiting;
196 ReleaseReadLock(&avc->lock);
197 afs_osi_Sleep(&tdc->validPos);
198 ObtainReadLock(&avc->lock);
200 if (!(avc->states & CStatd)
201 || !hsame(avc->m.DataVersion, tdc->f.versionNo)) {
202 ReleaseReadLock(&avc->lock);
207 /* Fill in until we get an error or we're done. This implementation
208 * takes an offset in units of blobs, rather than bytes.
211 offset = (int)fp->f_pos;
213 dirpos = BlobScan(&tdc->f.inode, offset);
217 de = (struct DirEntry*)afs_dir_GetBlob(&tdc->f.inode, dirpos);
221 ino = (avc->fid.Fid.Volume << 16) + ntohl(de->fid.vnode);
222 ino &= 0x7fffffff; /* Assumes 32 bit ino_t ..... */
223 len = strlen(de->name);
225 /* filldir returns -EINVAL when the buffer is full. */
226 #ifdef AFS_LINUX24_ENV
227 code = (*filldir)(dirbuf, de->name, len, offset, ino, DT_DIR);
229 code = (*filldir)(dirbuf, de->name, len, offset, ino);
234 offset = dirpos + 1 + ((len+16)>>5);
236 /* If filldir didn't fill in the last one this is still pointing to that
239 fp->f_pos = (loff_t)offset;
242 ReleaseReadLock(&avc->lock);
248 int afs_linux_select(struct inode *ip, struct file *fp, int, select_table *);
251 /* in afs_pioctl.c */
252 extern int afs_xioctl(struct inode *ip, struct file *fp,
253 unsigned int com, unsigned long arg);
256 /* We need to detect unmap's after close. To do that, we need our own
257 * vm_operations_struct's. And we need to set them up for both the
258 * private and shared mappings. The fun part is that these are all static
259 * so we'll have to initialize on the fly!
261 static struct vm_operations_struct afs_private_mmap_ops;
262 static int afs_private_mmap_ops_inited = 0;
263 static struct vm_operations_struct afs_shared_mmap_ops;
264 static int afs_shared_mmap_ops_inited = 0;
266 void afs_linux_vma_close(struct vm_area_struct *vmap)
274 vcp = (struct vcache*)FILE_INODE(vmap->vm_file);
279 afs_Trace4(afs_iclSetp, CM_TRACE_VM_CLOSE,
280 ICL_TYPE_POINTER, vcp,
281 ICL_TYPE_INT32, vcp->mapcnt,
282 ICL_TYPE_INT32, vcp->opens,
283 ICL_TYPE_INT32, vcp->execsOrWriters);
284 ObtainWriteLock(&vcp->lock, 532);
287 ReleaseWriteLock(&vcp->lock);
290 (void) afs_close(vcp, vmap->vm_file->f_flags, credp);
291 /* only decrement the execsOrWriters flag if this is not a writable
293 if (! (vmap->vm_file->f_flags & (FWRITE | FTRUNC)))
294 vcp->execsOrWriters--;
296 vcp->states &= ~CMAPPED;
301 ReleaseWriteLock(&vcp->lock);
308 static int afs_linux_mmap(struct file *fp, struct vm_area_struct *vmap)
310 struct vcache *vcp = (struct vcache*)FILE_INODE(fp);
311 cred_t *credp = crref();
312 struct vrequest treq;
316 #if defined(AFS_LINUX24_ENV)
317 afs_Trace3(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
318 ICL_TYPE_POINTER, vmap->vm_start,
319 ICL_TYPE_INT32, vmap->vm_end - vmap->vm_start);
321 afs_Trace4(afs_iclSetp, CM_TRACE_GMAP, ICL_TYPE_POINTER, vcp,
322 ICL_TYPE_POINTER, vmap->vm_start,
323 ICL_TYPE_INT32, vmap->vm_end - vmap->vm_start,
324 ICL_TYPE_INT32, vmap->vm_offset);
327 /* get a validated vcache entry */
328 code = afs_InitReq(&treq, credp);
330 code = afs_VerifyVCache(vcp, &treq);
336 osi_FlushPages(vcp, credp); /* ensure stale pages are gone */
339 code = generic_file_mmap(fp, vmap);
344 ObtainWriteLock(&vcp->lock,531);
345 /* Set out vma ops so we catch the close. The following test should be
346 * the same as used in generic_file_mmap.
348 if ((vmap->vm_flags & VM_SHARED) && (vmap->vm_flags & VM_MAYWRITE)) {
349 if (!afs_shared_mmap_ops_inited) {
350 afs_shared_mmap_ops_inited = 1;
351 afs_shared_mmap_ops = *vmap->vm_ops;
352 afs_shared_mmap_ops.close = afs_linux_vma_close;
354 vmap->vm_ops = &afs_shared_mmap_ops;
357 if (!afs_private_mmap_ops_inited) {
358 afs_private_mmap_ops_inited = 1;
359 afs_private_mmap_ops = *vmap->vm_ops;
360 afs_private_mmap_ops.close = afs_linux_vma_close;
362 vmap->vm_ops = &afs_private_mmap_ops;
366 /* Add an open reference on the first mapping. */
367 if (vcp->mapcnt == 0) {
368 vcp->execsOrWriters++;
370 vcp->states |= CMAPPED;
372 ReleaseWriteLock(&vcp->lock);
381 int afs_linux_open(struct inode *ip, struct file *fp)
384 cred_t *credp = crref();
387 #ifdef AFS_LINUX24_ENV
390 code = afs_open((struct vcache**)&ip, fp->f_flags, credp);
391 #ifdef AFS_LINUX24_ENV
400 /* afs_Close is called from release, since release is used to handle all
401 * file closings. In addition afs_linux_flush is called from sys_close to
402 * handle flushing the data back to the server. The kicker is that we could
403 * ignore flush completely if only sys_close took it's return value from
404 * fput. See afs_linux_flush for notes on interactions between release and
407 static int afs_linux_release(struct inode *ip, struct file *fp)
410 cred_t *credp = crref();
411 struct vcache *vcp = (struct vcache*)ip;
414 #ifdef AFS_LINUX24_ENV
418 vcp->flushcnt--; /* protected by AFS global lock. */
421 code = afs_close(vcp, fp->f_flags, credp);
423 #ifdef AFS_LINUX24_ENV
432 #if defined(AFS_LINUX24_ENV)
433 static int afs_linux_fsync(struct file *fp, struct dentry *dp, int datasync)
435 static int afs_linux_fsync(struct file *fp, struct dentry *dp)
439 struct inode *ip = FILE_INODE(fp);
440 cred_t *credp = crref();
443 #ifdef AFS_LINUX24_ENV
446 code = afs_fsync((struct vcache*)ip, credp);
447 #ifdef AFS_LINUX24_ENV
457 /* No support for async i/o */
458 int afs_linux_fasync(struct inode *ip, struct file *fp, int);
460 /* I don't think it will, at least not as can be detected here. */
461 int afs_linux_check_media_change(kdev_t dev);
463 /* Revalidate media and file system. */
464 int afs_linux_file_revalidate(kdev_t dev);
467 static int afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp)
470 struct vcache *vcp = (struct vcache*)FILE_INODE(fp);
471 cred_t *credp = crref();
474 /* Convert to a lock format afs_lockctl understands. */
475 memset((char*)&flock, 0, sizeof(flock));
476 flock.l_type = flp->fl_type;
477 flock.l_pid = flp->fl_pid;
479 flock.l_start = flp->fl_start;
480 flock.l_len = flp->fl_end - flp->fl_start;
483 code = afs_lockctl(vcp, &flock, cmd, credp);
491 * flush is called from sys_close. We could ignore it, but sys_close return
492 * code comes from flush, not release. We need to use release to keep
493 * the vcache open count correct. Note that flush is called before release
494 * (via fput) in sys_close. vcp->flushcnt is a bit of ugliness to avoid
495 * races and also avoid calling afs_close twice when closing the file.
496 * If we merely checked for opens > 0 in afs_linux_release, then if an
497 * new open occurred when storing back the file, afs_linux_release would
498 * incorrectly close the file and decrement the opens count. Calling afs_close
499 * on the just flushed file is wasteful, since the background daemon will
500 * execute the code that finally decides there is nothing to do.
502 int afs_linux_flush(struct file *fp)
504 struct vcache *vcp = (struct vcache *)FILE_INODE(fp);
508 /* Only do this on the last close of the file pointer. */
509 #if defined(AFS_LINUX24_ENV)
510 if (atomic_read(&fp->f_count) > 1)
519 code = afs_close(vcp, fp->f_flags, credp);
520 vcp->flushcnt++; /* protected by AFS global lock. */
527 /* Not allowed to directly read a directory. */
528 int afs_linux_dir_read(struct file *fp, char *buf, size_t count, loff_t *ppos)
535 #if defined(AFS_LINUX24_ENV)
536 struct file_operations afs_dir_fops = {
537 read: generic_read_dir,
538 readdir: afs_linux_readdir,
540 open: afs_linux_open,
541 release: afs_linux_release,
544 struct file_operations afs_dir_fops = {
545 NULL, /* afs_linux_lseek */
547 NULL, /* afs_linux_write */
549 NULL, /* afs_linux_select */
550 afs_xioctl, /* close enough to use the ported AFS one */
551 NULL, /* afs_linux_mmap */
553 NULL, /* afs_linux_flush */
556 NULL, /* afs_linux_fasync */
557 NULL, /* afs_linux_check_media_change */
558 NULL, /* afs_linux_file_revalidate */
563 #if defined(AFS_LINUX24_ENV)
564 struct file_operations afs_file_fops = {
565 read: afs_linux_read,
566 write: afs_linux_write,
568 mmap: afs_linux_mmap,
569 open: afs_linux_open,
570 flush: afs_linux_flush,
571 release: afs_linux_release,
572 fsync: afs_linux_fsync,
573 lock: afs_linux_lock,
576 struct file_operations afs_file_fops = {
577 NULL, /* afs_linux_lseek */
580 NULL, /* afs_linux_readdir */
581 NULL, /* afs_linux_select */
582 afs_xioctl, /* close enough to use the ported AFS one */
588 NULL, /* afs_linux_fasync */
589 NULL, /* afs_linux_check_media_change */
590 NULL, /* afs_linux_file_revalidate */
596 /**********************************************************************
597 * AFS Linux dentry operations
598 **********************************************************************/
600 /* afs_linux_revalidate
601 * Ensure vcache is stat'd before use. Return 0 if entry is valid.
603 static int afs_linux_revalidate(struct dentry *dp)
607 struct vrequest treq;
608 struct vcache *vcp = (struct vcache*)dp->d_inode;
611 #ifdef AFS_LINUX24_ENV
615 /* If it's a negative dentry, then there's nothing to do. */
617 #ifdef AFS_LINUX24_ENV
624 /* Make this a fast path (no crref), since it's called so often. */
625 if (vcp->states & CStatd) {
626 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
627 check_bad_parent(dp); /* check and correct mvid */
629 #ifdef AFS_LINUX24_ENV
637 code = afs_InitReq(&treq, credp);
639 code = afs_VerifyVCache(vcp, &treq);
641 #ifdef AFS_LINUX24_ENV
650 /* Validate a dentry. Return 0 if unchanged, 1 if VFS layer should re-evaluate.
651 * In kernels 2.2.10 and above, we are passed an additional flags var which
652 * may have either the LOOKUP_FOLLOW OR LOOKUP_DIRECTORY set in which case
653 * we are advised to follow the entry if it is a link or to make sure that
654 * it is a directory. But since the kernel itself checks these possibilities
655 * later on, we shouldn't have to do it until later. Perhaps in the future..
657 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
658 static int afs_linux_dentry_revalidate(struct dentry *dp, int flags)
660 static int afs_linux_dentry_revalidate(struct dentry *dp)
665 struct vrequest treq;
666 struct vcache *vcp = (struct vcache*)dp->d_inode;
669 #ifdef AFS_LINUX24_ENV
673 /* If it's a negative dentry, then there's nothing to do. */
675 #ifdef AFS_LINUX24_ENV
682 /* Make this a fast path (no crref), since it's called so often. */
683 if (vcp->states & CStatd) {
684 if (*dp->d_name.name != '/' && vcp->mvstat == 2) /* root vnode */
685 check_bad_parent(dp); /* check and correct mvid */
687 #ifdef AFS_LINUX24_ENV
695 code = afs_InitReq(&treq, credp);
697 code = afs_VerifyVCache(vcp, &treq);
699 #ifdef AFS_LINUX24_ENV
708 /* afs_dentry_iput */
709 static void afs_dentry_iput(struct dentry *dp, struct inode *ip)
711 #if defined(AFS_LINUX24_ENV)
712 if (atomic_read(&ip->i_count) == 0 || atomic_read(&ip->i_count) & 0xffff0000) {
714 if (ip->i_count == 0 || ip->i_count & 0xffff0000) {
716 osi_Panic("Bad refCount %d on inode 0x%x\n",
717 #if defined(AFS_LINUX24_ENV)
718 atomic_read(&ip->i_count), ip);
723 #if defined(AFS_LINUX24_ENV)
724 atomic_dec(&ip->i_count);
725 if (!atomic_read(&ip->i_count)) {
730 afs_delete_inode(ip);
734 #if defined(AFS_LINUX24_ENV)
735 struct dentry_operations afs_dentry_operations = {
736 d_revalidate: afs_linux_dentry_revalidate,
737 d_iput: afs_dentry_iput,
739 struct dentry_operations *afs_dops = &afs_dentry_operations;
741 struct dentry_operations afs_dentry_operations = {
742 afs_linux_dentry_revalidate, /* d_validate(struct dentry *) */
744 NULL, /* d_compare */
745 NULL, /* d_delete(struct dentry *) */
746 NULL, /* d_release(struct dentry *) */
747 afs_dentry_iput /* d_iput(struct dentry *, struct inode *) */
749 struct dentry_operations *afs_dops = &afs_dentry_operations;
752 /**********************************************************************
753 * AFS Linux inode operations
754 **********************************************************************/
758 * Merely need to set enough of vattr to get us through the create. Note
759 * that the higher level code (open_namei) will take care of any tuncation
760 * explicitly. Exclusive open is also taken care of in open_namei.
762 * name is in kernel space at this point.
764 int afs_linux_create(struct inode *dip, struct dentry *dp, int mode)
767 cred_t *credp = crref();
770 const char *name = dp->d_name.name;
774 vattr.va_mode = mode;
777 code = afs_create((struct vcache*)dip, name, &vattr, NONEXCL, mode,
778 (struct vcache**)&ip, credp);
781 vattr2inode(ip, &vattr);
782 /* Reset ops if symlink or directory. */
783 #if defined(AFS_LINUX24_ENV)
784 if (S_ISREG(ip->i_mode)) {
785 ip->i_op = &afs_file_iops;
786 ip->i_fop = &afs_file_fops;
787 ip->i_data.a_ops = &afs_file_aops;
788 } else if (S_ISDIR(ip->i_mode)) {
789 ip->i_op = &afs_dir_iops;
790 ip->i_fop = &afs_dir_fops;
791 } else if (S_ISLNK(ip->i_mode)) {
792 ip->i_op = &afs_symlink_iops;
793 ip->i_data.a_ops = &afs_symlink_aops;
794 ip->i_mapping = &ip->i_data;
796 printk("afs_linux_create: FIXME\n");
798 if (S_ISDIR(ip->i_mode))
799 ip->i_op = &afs_dir_iops;
800 else if (S_ISLNK(ip->i_mode))
801 ip->i_op = &afs_symlink_iops;
805 d_instantiate(dp, ip);
813 /* afs_linux_lookup */
814 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
815 struct dentry *afs_linux_lookup(struct inode *dip, struct dentry *dp)
817 int afs_linux_lookup(struct inode *dip, struct dentry *dp)
821 cred_t *credp = crref();
822 struct vcache *vcp=NULL;
823 const char *comp = dp->d_name.name;
825 code = afs_lookup((struct vcache *)dip, comp, &vcp, credp);
828 struct inode *ip = (struct inode*)vcp;
829 /* Reset ops if symlink or directory. */
830 #if defined(AFS_LINUX24_ENV)
831 if (S_ISREG(ip->i_mode)) {
832 ip->i_op = &afs_file_iops;
833 ip->i_fop = &afs_file_fops;
834 ip->i_data.a_ops = &afs_file_aops;
835 } else if (S_ISDIR(ip->i_mode)) {
836 ip->i_op = &afs_dir_iops;
837 ip->i_fop = &afs_dir_fops;
838 } else if (S_ISLNK(ip->i_mode)) {
839 ip->i_op = &afs_symlink_iops;
840 ip->i_data.a_ops = &afs_symlink_aops;
841 ip->i_mapping = &ip->i_data;
843 printk("afs_linux_lookup: FIXME\n");
845 if (S_ISDIR(ip->i_mode))
846 ip->i_op = &afs_dir_iops;
847 else if (S_ISLNK(ip->i_mode))
848 ip->i_op = &afs_symlink_iops;
852 d_add(dp, (struct inode*)vcp);
857 /* It's ok for the file to not be found. That's noted by the caller by
858 * seeing that the dp->d_inode field is NULL.
860 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10)
864 return ERR_PTR(-code);
872 int afs_linux_link(struct dentry *olddp, struct inode *dip,
873 struct dentry *newdp)
876 cred_t *credp = crref();
877 const char *name = newdp->d_name.name;
878 struct inode *oldip = olddp->d_inode;
880 /* If afs_link returned the vnode, we could instantiate the
881 * dentry. Since it's not, we drop this one and do a new lookup.
886 code = afs_link((struct vcache*)oldip, (struct vcache*)dip, name, credp);
893 int afs_linux_unlink(struct inode *dip, struct dentry *dp)
896 cred_t *credp = crref();
897 const char *name = dp->d_name.name;
900 if (!list_empty(&dp->d_hash)) {
902 /* Install a definite non-existence if we're the only user. */
903 #if defined(AFS_LINUX24_ENV)
904 if (atomic_read(&dp->d_count) == 1)
906 if (dp->d_count == 1)
912 code = afs_remove((struct vcache*)dip, name, credp);
917 d_add(dp, NULL); /* means definitely does _not_ exist */
924 int afs_linux_symlink(struct inode *dip, struct dentry *dp,
928 cred_t *credp = crref();
930 const char *name = dp->d_name.name;
932 /* If afs_symlink returned the vnode, we could instantiate the
933 * dentry. Since it's not, we drop this one and do a new lookup.
939 code = afs_symlink((struct vcache*)dip, name, &vattr, target, credp);
945 int afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode)
948 cred_t *credp = crref();
949 struct vcache *tvcp = NULL;
951 const char *name = dp->d_name.name;
955 vattr.va_mask = ATTR_MODE;
956 vattr.va_mode = mode;
957 code = afs_mkdir((struct vcache*)dip, name, &vattr, &tvcp, credp);
960 tvcp->v.v_op = &afs_dir_iops;
961 #if defined(AFS_LINUX24_ENV)
962 tvcp->v.v_fop = &afs_dir_fops;
965 d_instantiate(dp, (struct inode*)tvcp);
972 int afs_linux_rmdir(struct inode *dip, struct dentry *dp)
975 cred_t *credp = crref();
976 const char *name = dp->d_name.name;
979 code = afs_rmdir((struct vcache*)dip, name, credp);
981 /* Linux likes to see ENOTDIR returned from an rmdir() syscall
982 * that failed because a directory is not empty. So, we map
983 * EEXIST to ENOTDIR on linux.
985 if (code == EEXIST) {
1000 int afs_linux_rename(struct inode *oldip, struct dentry *olddp,
1001 struct inode *newip, struct dentry *newdp)
1004 cred_t *credp = crref();
1005 const char *oldname = olddp->d_name.name;
1006 const char *newname = newdp->d_name.name;
1008 /* Remove old and new entries from name hash. New one will change below.
1009 * While it's optimal to catch failures and re-insert newdp into hash,
1010 * it's also error prone and in that case we're already dealing with error
1011 * cases. Let another lookup put things right, if need be.
1013 if (!list_empty(&olddp->d_hash)) {
1016 if (!list_empty(&newdp->d_hash)) {
1020 code = afs_rename((struct vcache*)oldip, oldname, (struct vcache*)newip,
1025 d_move(olddp, newdp);
1032 /* afs_linux_ireadlink
1033 * Internal readlink which can return link contents to user or kernel space.
1034 * Note that the buffer is NOT supposed to be null-terminated.
1036 static int afs_linux_ireadlink(struct inode *ip, char *target, int maxlen,
1040 cred_t *credp = crref();
1044 setup_uio(&tuio, &iov, target, 0, maxlen, UIO_READ, seg);
1045 code = afs_readlink((struct vcache*)ip, &tuio, credp);
1049 return maxlen - tuio.uio_resid;
1054 #if !defined(AFS_LINUX24_ENV)
1055 /* afs_linux_readlink
1056 * Fill target (which is in user space) with contents of symlink.
1058 int afs_linux_readlink(struct dentry *dp, char *target, int maxlen)
1061 struct inode *ip = dp->d_inode;
1064 code = afs_linux_ireadlink(ip, target, maxlen, AFS_UIOUSER);
1070 /* afs_linux_follow_link
1071 * a file system dependent link following routine.
1073 struct dentry * afs_linux_follow_link(struct dentry *dp,
1074 struct dentry *basep,
1075 unsigned int follow)
1082 name = osi_Alloc(PATH_MAX+1);
1086 return ERR_PTR(-EIO);
1089 code = afs_linux_ireadlink(dp->d_inode, name, PATH_MAX, AFS_UIOSYS);
1094 res = ERR_PTR(code);
1098 res = lookup_dentry(name, basep, follow);
1102 osi_Free(name, PATH_MAX+1);
1108 /* afs_linux_readpage
1109 * all reads come through here. A strategy-like read call.
1111 int afs_linux_readpage(struct file *fp, struct page *pp)
1114 cred_t *credp = crref();
1115 ulong address = afs_linux_page_address(pp);
1118 struct inode *ip = FILE_INODE(fp);
1119 int cnt = atomic_read(&pp->count);
1122 afs_Trace4(afs_iclSetp, CM_TRACE_READPAGE,
1123 ICL_TYPE_POINTER, ip,
1124 ICL_TYPE_POINTER, pp,
1125 ICL_TYPE_INT32, cnt,
1126 ICL_TYPE_INT32, 99999); /* not a possible code value */
1127 atomic_add(1, &pp->count);
1128 set_bit(PG_locked, &pp->flags); /* other bits? See mm.h */
1129 clear_bit(PG_error, &pp->flags);
1131 #if defined(AFS_LINUX24_ENV)
1132 setup_uio(&tuio, &iovec, (char*)address, pp->index << PAGE_CACHE_SHIFT,
1133 PAGESIZE, UIO_READ, AFS_UIOSYS);
1135 setup_uio(&tuio, &iovec, (char*)address, pp->offset, PAGESIZE,
1136 UIO_READ, AFS_UIOSYS);
1138 #ifdef AFS_LINUX24_ENV
1141 code = afs_rdwr((struct vcache*)ip, &tuio, UIO_READ, 0, credp);
1142 #ifdef AFS_LINUX24_ENV
1147 if (tuio.uio_resid) /* zero remainder of page */
1148 memset((void*)(address+(PAGESIZE-tuio.uio_resid)), 0,
1150 set_bit(PG_uptodate, &pp->flags);
1153 clear_bit(PG_locked, &pp->flags);
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);
1167 #if defined(AFS_LINUX24_ENV)
1168 int afs_linux_writepage(struct file *file, struct page *page)
1170 struct dentry *dentry = file->f_dentry;
1171 struct inode *inode = dentry->d_inode;
1172 unsigned long end_index = inode->i_size >> PAGE_CACHE_SHIFT;
1173 unsigned offset = PAGE_CACHE_SIZE;
1177 if (page->index < end_index)
1179 /* things got complicated... */
1180 offset = inode->i_size & (PAGE_CACHE_SIZE-1);
1181 /* OK, are we completely out? */
1182 if (page->index >= end_index+1 || !offset)
1185 status = afs_linux_updatepage(file, page, 0, offset, 1);
1187 if (status == offset)
1195 /* afs_linux_bmap - supports generic_readpage, but we roll our own. */
1196 int afs_linux_bmap(struct inode *ip, int) { return -EINVAL; }
1198 /* afs_linux_truncate
1199 * Handles discarding disk blocks if this were a device. ext2 indicates we
1200 * may need to zero partial last pages of memory mapped files.
1202 void afs_linux_truncate(struct inode *ip)
1207 /* afs_linux_permission
1208 * Check access rights - returns error if can't check or permission denied.
1210 int afs_linux_permission(struct inode *ip, int mode)
1213 cred_t *credp = crref();
1217 if (mode & MAY_EXEC) tmp |= VEXEC;
1218 if (mode & MAY_READ) tmp |= VREAD;
1219 if (mode & MAY_WRITE) tmp |= VWRITE;
1220 code = afs_access((struct vcache*)ip, tmp, credp);
1229 /* msdos sector mapping hack for memory mapping. */
1230 int afs_linux_smap(struct inode *ip, int) { return -EINVAL; }
1233 /* afs_linux_updatepage
1234 * What one would have thought was writepage - write dirty page to file.
1235 * Called from generic_file_write. buffer is still in user space. pagep
1236 * has been filled in with old data if we're updating less than a page.
1238 int afs_linux_updatepage(struct file *fp, struct page *pp,
1239 unsigned long offset,
1240 unsigned int count, int sync)
1242 struct vcache *vcp = (struct vcache *)FILE_INODE(fp);
1243 u8 *page_addr = (u8*) afs_linux_page_address(pp);
1249 set_bit(PG_locked, &pp->flags);
1253 #ifdef AFS_LINUX24_ENV
1256 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1257 ICL_TYPE_POINTER, pp,
1258 ICL_TYPE_INT32, atomic_read(&pp->count),
1259 ICL_TYPE_INT32, 99999);
1260 #if defined(AFS_LINUX24_ENV)
1261 setup_uio(&tuio, &iovec, page_addr + offset,
1262 (pp->index << PAGE_CACHE_SHIFT) + offset, count,
1263 UIO_WRITE, AFS_UIOSYS);
1265 setup_uio(&tuio, &iovec, page_addr + offset, pp->offset + offset, count,
1266 UIO_WRITE, AFS_UIOSYS);
1269 code = afs_write(vcp, &tuio, fp->f_flags, credp, 0);
1273 code = code ? -code : count - tuio.uio_resid;
1274 afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp,
1275 ICL_TYPE_POINTER, pp,
1276 ICL_TYPE_INT32, atomic_read(&pp->count),
1277 ICL_TYPE_INT32, code);
1279 #ifdef AFS_LINUX24_ENV
1285 clear_bit(PG_locked, &pp->flags);
1289 #if defined(AFS_LINUX24_ENV)
1290 static int afs_linux_commit_write(struct file *file, struct page *page, unsigned offset, unsigned to)
1293 loff_t pos = ((loff_t)page->index<<PAGE_CACHE_SHIFT) + to;
1295 status = afs_linux_updatepage(file, page, offset, to-offset, 1);
1301 static int afs_linux_prepare_write(struct file *file, struct page *page,
1302 unsigned from, unsigned to)
1308 extern int afs_notify_change(struct dentry *dp, struct iattr* iattrp);
1311 #if defined(AFS_LINUX24_ENV)
1312 struct inode_operations afs_file_iops = {
1313 revalidate: afs_linux_revalidate,
1314 setattr: afs_notify_change,
1315 permission: afs_linux_permission,
1317 struct address_space_operations afs_file_aops = {
1318 readpage: afs_linux_readpage,
1319 writepage: afs_linux_writepage,
1320 commit_write: afs_linux_commit_write,
1321 prepare_write: afs_linux_prepare_write,
1324 struct inode_operations *afs_ops = &afs_file_iops;
1326 struct inode_operations afs_iops = {
1327 &afs_file_fops, /* file operations */
1328 NULL, /* afs_linux_create */
1329 NULL, /* afs_linux_lookup */
1330 NULL, /* afs_linux_link */
1331 NULL, /* afs_linux_unlink */
1332 NULL, /* afs_linux_symlink */
1333 NULL, /* afs_linux_mkdir */
1334 NULL, /* afs_linux_rmdir */
1335 NULL, /* afs_linux_mknod */
1336 NULL, /* afs_linux_rename */
1337 NULL, /* afs_linux_readlink */
1338 NULL, /* afs_linux_follow_link */
1340 NULL, /* afs_linux_writepage */
1341 NULL, /* afs_linux_bmap */
1342 NULL, /* afs_linux_truncate */
1343 afs_linux_permission,
1344 NULL, /* afs_linux_smap */
1345 afs_linux_updatepage,
1346 afs_linux_revalidate,
1349 struct inode_operations *afs_ops = &afs_iops;
1352 /* Separate ops vector for directories. Linux 2.2 tests type of inode
1353 * by what sort of operation is allowed.....
1355 #if defined(AFS_LINUX24_ENV)
1356 struct inode_operations afs_dir_iops = {
1357 create: afs_linux_create,
1358 lookup: afs_linux_lookup,
1359 link: afs_linux_link,
1360 unlink: afs_linux_unlink,
1361 symlink: afs_linux_symlink,
1362 mkdir: afs_linux_mkdir,
1363 rmdir: afs_linux_rmdir,
1364 rename: afs_linux_rename,
1365 revalidate: afs_linux_revalidate,
1366 setattr: afs_notify_change,
1367 permission: afs_linux_permission,
1370 struct inode_operations afs_dir_iops = {
1371 &afs_dir_fops, /* file operations for directories */
1379 NULL, /* afs_linux_mknod */
1381 NULL, /* afs_linux_readlink */
1382 NULL, /* afs_linux_follow_link */
1383 NULL, /* afs_linux_readpage */
1384 NULL, /* afs_linux_writepage */
1385 NULL, /* afs_linux_bmap */
1386 NULL, /* afs_linux_truncate */
1387 afs_linux_permission,
1388 NULL, /* afs_linux_smap */
1389 NULL, /* afs_linux_updatepage */
1390 afs_linux_revalidate,
1394 /* We really need a separate symlink set of ops, since do_follow_link()
1395 * determines if it _is_ a link by checking if the follow_link op is set.
1397 #if defined(AFS_LINUX24_ENV)
1398 static int afs_symlink_filler(struct file *file, struct page *page)
1400 struct inode *ip = (struct inode *) page->mapping->host;
1401 char *p = (char *)kmap(page);
1406 code = afs_linux_ireadlink(ip, p, PAGE_SIZE, AFS_UIOSYS);
1412 p[code] = '\0'; /* null terminate? */
1413 SetPageUptodate(page);
1425 struct address_space_operations afs_symlink_aops = {
1426 readpage: afs_symlink_filler
1429 struct inode_operations afs_symlink_iops = {
1430 readlink: page_readlink,
1431 follow_link: page_follow_link,
1432 setattr: afs_notify_change,
1435 struct inode_operations afs_symlink_iops = {
1436 NULL, /* file operations */
1444 NULL, /* afs_linux_mknod */
1447 afs_linux_follow_link,
1448 NULL, /* readpage */
1449 NULL, /* afs_linux_writepage */
1450 NULL, /* afs_linux_bmap */
1451 NULL, /* afs_linux_truncate */
1452 afs_linux_permission, /* tho the code appears to indicate not used? */
1453 NULL, /* afs_linux_smap */
1454 NULL, /* updatepage */
1455 afs_linux_revalidate, /* tho the code appears to indicate not used? */