2 * linux/fs/9p/vfs_inode.c
4 * This file contains vfs inode ops for the 9P2000 protocol.
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to:
20 * Free Software Foundation
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02111-1301 USA
26 #include <linux/module.h>
27 #include <linux/errno.h>
29 #include <linux/file.h>
30 #include <linux/pagemap.h>
31 #include <linux/stat.h>
32 #include <linux/string.h>
33 #include <linux/smp_lock.h>
34 #include <linux/inet.h>
35 #include <linux/namei.h>
36 #include <linux/idr.h>
44 static struct inode_operations v9fs_dir_inode_operations
;
45 static struct inode_operations v9fs_dir_inode_operations_ext
;
46 static struct inode_operations v9fs_file_inode_operations
;
47 static struct inode_operations v9fs_symlink_inode_operations
;
50 * unixmode2p9mode - convert unix mode bits to plan 9
51 * @v9ses: v9fs session information
52 * @mode: mode to convert
56 static int unixmode2p9mode(struct v9fs_session_info
*v9ses
, int mode
)
62 if (v9ses
->extended
) {
64 res
|= V9FS_DMSYMLINK
;
65 if (v9ses
->nodev
== 0) {
69 res
|= V9FS_DMNAMEDPIPE
;
76 if ((mode
& S_ISUID
) == S_ISUID
)
78 if ((mode
& S_ISGID
) == S_ISGID
)
80 if ((mode
& V9FS_DMLINK
))
88 * p9mode2unixmode- convert plan9 mode bits to unix mode bits
89 * @v9ses: v9fs session information
90 * @mode: mode to convert
94 static int p9mode2unixmode(struct v9fs_session_info
*v9ses
, int mode
)
100 if ((mode
& V9FS_DMDIR
) == V9FS_DMDIR
)
102 else if ((mode
& V9FS_DMSYMLINK
) && (v9ses
->extended
))
104 else if ((mode
& V9FS_DMSOCKET
) && (v9ses
->extended
)
105 && (v9ses
->nodev
== 0))
107 else if ((mode
& V9FS_DMNAMEDPIPE
) && (v9ses
->extended
)
108 && (v9ses
->nodev
== 0))
110 else if ((mode
& V9FS_DMDEVICE
) && (v9ses
->extended
)
111 && (v9ses
->nodev
== 0))
116 if (v9ses
->extended
) {
117 if ((mode
& V9FS_DMSETUID
) == V9FS_DMSETUID
)
120 if ((mode
& V9FS_DMSETGID
) == V9FS_DMSETGID
)
127 int v9fs_uflags2omode(int uflags
)
150 if (uflags
& O_TRUNC
)
153 if (uflags
& O_APPEND
)
160 * v9fs_blank_wstat - helper function to setup a 9P stat structure
161 * @v9ses: 9P session info (for determining extended mode)
162 * @wstat: structure to initialize
167 v9fs_blank_wstat(struct v9fs_wstat
*wstat
)
171 wstat
->qid
.type
= ~0;
172 wstat
->qid
.version
= ~0;
173 *((long long *)&wstat
->qid
.path
) = ~0;
185 wstat
->extension
= NULL
;
189 * v9fs_get_inode - helper function to setup an inode
191 * @mode: mode to setup inode with
195 struct inode
*v9fs_get_inode(struct super_block
*sb
, int mode
)
198 struct v9fs_session_info
*v9ses
= sb
->s_fs_info
;
200 dprintk(DEBUG_VFS
, "super block: %p mode: %o\n", sb
, mode
);
202 inode
= new_inode(sb
);
204 inode
->i_mode
= mode
;
205 inode
->i_uid
= current
->fsuid
;
206 inode
->i_gid
= current
->fsgid
;
209 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
210 inode
->i_mapping
->a_ops
= &v9fs_addr_operations
;
212 switch (mode
& S_IFMT
) {
217 if(!v9ses
->extended
) {
218 dprintk(DEBUG_ERROR
, "special files without extended mode\n");
219 return ERR_PTR(-EINVAL
);
221 init_special_inode(inode
, inode
->i_mode
,
225 inode
->i_op
= &v9fs_file_inode_operations
;
226 inode
->i_fop
= &v9fs_file_operations
;
229 if(!v9ses
->extended
) {
230 dprintk(DEBUG_ERROR
, "extended modes used w/o 9P2000.u\n");
231 return ERR_PTR(-EINVAL
);
233 inode
->i_op
= &v9fs_symlink_inode_operations
;
238 inode
->i_op
= &v9fs_dir_inode_operations_ext
;
240 inode
->i_op
= &v9fs_dir_inode_operations
;
241 inode
->i_fop
= &v9fs_dir_operations
;
244 dprintk(DEBUG_ERROR
, "BAD mode 0x%x S_IFMT 0x%x\n",
245 mode
, mode
& S_IFMT
);
246 return ERR_PTR(-EINVAL
);
249 eprintk(KERN_WARNING
, "Problem allocating inode\n");
250 return ERR_PTR(-ENOMEM
);
256 v9fs_create(struct v9fs_session_info
*v9ses
, u32 pfid
, char *name
, u32 perm
,
257 u8 mode
, char *extension
, u32
*fidp
, struct v9fs_qid
*qid
, u32
*iounit
)
261 struct v9fs_fcall
*fcall
;
263 fid
= v9fs_get_idpool(&v9ses
->fidpool
);
265 eprintk(KERN_WARNING
, "no free fids available\n");
269 err
= v9fs_t_walk(v9ses
, pfid
, fid
, NULL
, &fcall
);
271 PRINT_FCALL_ERROR("clone error", fcall
);
272 if (fcall
&& fcall
->id
== RWALK
)
279 err
= v9fs_t_create(v9ses
, fid
, name
, perm
, mode
, extension
, &fcall
);
281 PRINT_FCALL_ERROR("create fails", fcall
);
286 *iounit
= fcall
->params
.rcreate
.iounit
;
289 *qid
= fcall
->params
.rcreate
.qid
;
298 v9fs_t_clunk(v9ses
, fid
);
302 if (fid
!= V9FS_NOFID
)
303 v9fs_put_idpool(fid
, &v9ses
->fidpool
);
309 static struct v9fs_fid
*
310 v9fs_clone_walk(struct v9fs_session_info
*v9ses
, u32 fid
, struct dentry
*dentry
)
314 struct v9fs_fid
*ret
;
315 struct v9fs_fcall
*fcall
;
317 nfid
= v9fs_get_idpool(&v9ses
->fidpool
);
319 eprintk(KERN_WARNING
, "no free fids available\n");
320 return ERR_PTR(-ENOSPC
);
323 err
= v9fs_t_walk(v9ses
, fid
, nfid
, (char *) dentry
->d_name
.name
,
327 if (fcall
&& fcall
->id
== RWALK
)
330 PRINT_FCALL_ERROR("walk error", fcall
);
331 v9fs_put_idpool(nfid
, &v9ses
->fidpool
);
337 ret
= v9fs_fid_create(v9ses
, nfid
);
343 err
= v9fs_fid_insert(ret
, dentry
);
345 v9fs_fid_destroy(ret
);
352 v9fs_t_clunk(v9ses
, nfid
);
359 static struct inode
*
360 v9fs_inode_from_fid(struct v9fs_session_info
*v9ses
, u32 fid
,
361 struct super_block
*sb
)
365 struct v9fs_fcall
*fcall
;
368 err
= v9fs_t_stat(v9ses
, fid
, &fcall
);
370 PRINT_FCALL_ERROR("stat error", fcall
);
374 umode
= p9mode2unixmode(v9ses
, fcall
->params
.rstat
.stat
.mode
);
375 ret
= v9fs_get_inode(sb
, umode
);
382 v9fs_stat2inode(&fcall
->params
.rstat
.stat
, ret
, sb
);
395 * v9fs_remove - helper function to remove files and directories
396 * @dir: directory inode that is being deleted
397 * @file: dentry that is being deleted
398 * @rmdir: removing a directory
402 static int v9fs_remove(struct inode
*dir
, struct dentry
*file
, int rmdir
)
404 struct v9fs_fcall
*fcall
= NULL
;
405 struct super_block
*sb
= NULL
;
406 struct v9fs_session_info
*v9ses
= NULL
;
407 struct v9fs_fid
*v9fid
= NULL
;
408 struct inode
*file_inode
= NULL
;
412 dprintk(DEBUG_VFS
, "inode: %p dentry: %p rmdir: %d\n", dir
, file
,
415 file_inode
= file
->d_inode
;
416 sb
= file_inode
->i_sb
;
417 v9ses
= v9fs_inode2v9ses(file_inode
);
418 v9fid
= v9fs_fid_lookup(file
);
420 return PTR_ERR(v9fid
);
424 dprintk(DEBUG_ERROR
, "inode #%lu, no fid!\n",
429 result
= v9fs_t_remove(v9ses
, fid
, &fcall
);
431 PRINT_FCALL_ERROR("remove fails", fcall
);
435 v9fs_put_idpool(fid
, &v9ses
->fidpool
);
436 v9fs_fid_destroy(v9fid
);
444 v9fs_open_created(struct inode
*inode
, struct file
*file
)
450 * v9fs_vfs_create - VFS hook to create files
451 * @inode: directory inode that is being deleted
452 * @dentry: dentry that is being deleted
453 * @mode: create permissions
454 * @nd: path information
459 v9fs_vfs_create(struct inode
*dir
, struct dentry
*dentry
, int mode
,
460 struct nameidata
*nd
)
463 u32 fid
, perm
, iounit
;
465 struct v9fs_session_info
*v9ses
;
466 struct v9fs_fid
*dfid
, *vfid
, *ffid
;
473 v9ses
= v9fs_inode2v9ses(dir
);
474 dfid
= v9fs_fid_clone(dentry
->d_parent
);
480 perm
= unixmode2p9mode(v9ses
, mode
);
481 if (nd
&& nd
->flags
& LOOKUP_OPEN
)
482 flags
= nd
->intent
.open
.flags
- 1;
486 err
= v9fs_create(v9ses
, dfid
->fid
, (char *) dentry
->d_name
.name
,
487 perm
, v9fs_uflags2omode(flags
), NULL
, &fid
, &qid
, &iounit
);
492 vfid
= v9fs_clone_walk(v9ses
, dfid
->fid
, dentry
);
493 v9fs_fid_clunk(v9ses
, dfid
);
500 inode
= v9fs_inode_from_fid(v9ses
, vfid
->fid
, dir
->i_sb
);
502 err
= PTR_ERR(inode
);
507 dentry
->d_op
= &v9fs_dentry_operations
;
508 d_instantiate(dentry
, inode
);
510 if (nd
&& nd
->flags
& LOOKUP_OPEN
) {
511 ffid
= v9fs_fid_create(v9ses
, fid
);
515 filp
= lookup_instantiate_filp(nd
, dentry
, v9fs_open_created
);
517 v9fs_fid_destroy(ffid
);
518 return PTR_ERR(filp
);
522 ffid
->rdir_fcall
= NULL
;
524 ffid
->iounit
= iounit
;
526 filp
->private_data
= ffid
;
532 v9fs_fid_clunk(v9ses
, dfid
);
536 v9fs_fid_destroy(vfid
);
542 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
543 * @inode: inode that is being unlinked
544 * @dentry: dentry that is being unlinked
545 * @mode: mode for new directory
549 static int v9fs_vfs_mkdir(struct inode
*dir
, struct dentry
*dentry
, int mode
)
553 struct v9fs_session_info
*v9ses
;
554 struct v9fs_fid
*dfid
, *vfid
;
559 v9ses
= v9fs_inode2v9ses(dir
);
560 dfid
= v9fs_fid_clone(dentry
->d_parent
);
566 perm
= unixmode2p9mode(v9ses
, mode
| S_IFDIR
);
568 err
= v9fs_create(v9ses
, dfid
->fid
, (char *) dentry
->d_name
.name
,
569 perm
, V9FS_OREAD
, NULL
, &fid
, NULL
, NULL
);
572 dprintk(DEBUG_ERROR
, "create error %d\n", err
);
576 vfid
= v9fs_clone_walk(v9ses
, dfid
->fid
, dentry
);
583 v9fs_fid_clunk(v9ses
, dfid
);
584 inode
= v9fs_inode_from_fid(v9ses
, vfid
->fid
, dir
->i_sb
);
586 err
= PTR_ERR(inode
);
591 dentry
->d_op
= &v9fs_dentry_operations
;
592 d_instantiate(dentry
, inode
);
597 v9fs_fid_destroy(vfid
);
600 v9fs_fid_clunk(v9ses
, dfid
);
607 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
608 * @dir: inode that is being walked from
609 * @dentry: dentry that is being walked to?
610 * @nameidata: path data
614 static struct dentry
*v9fs_vfs_lookup(struct inode
*dir
, struct dentry
*dentry
,
615 struct nameidata
*nameidata
)
617 struct super_block
*sb
;
618 struct v9fs_session_info
*v9ses
;
619 struct v9fs_fid
*dirfid
;
620 struct v9fs_fid
*fid
;
622 struct v9fs_fcall
*fcall
= NULL
;
627 dprintk(DEBUG_VFS
, "dir: %p dentry: (%s) %p nameidata: %p\n",
628 dir
, dentry
->d_name
.name
, dentry
, nameidata
);
631 v9ses
= v9fs_inode2v9ses(dir
);
632 dentry
->d_op
= &v9fs_dentry_operations
;
633 dirfid
= v9fs_fid_lookup(dentry
->d_parent
);
636 return ERR_PTR(PTR_ERR(dirfid
));
638 dirfidnum
= dirfid
->fid
;
640 newfid
= v9fs_get_idpool(&v9ses
->fidpool
);
642 eprintk(KERN_WARNING
, "newfid fails!\n");
647 result
= v9fs_t_walk(v9ses
, dirfidnum
, newfid
,
648 (char *)dentry
->d_name
.name
, &fcall
);
653 if (fcall
&& fcall
->id
== RWALK
)
654 v9fs_t_clunk(v9ses
, newfid
);
656 v9fs_put_idpool(newfid
, &v9ses
->fidpool
);
658 if (result
== -ENOENT
) {
661 "Return negative dentry %p count %d\n",
662 dentry
, atomic_read(&dentry
->d_count
));
666 dprintk(DEBUG_ERROR
, "walk error:%d\n", result
);
671 result
= v9fs_t_stat(v9ses
, newfid
, &fcall
);
673 dprintk(DEBUG_ERROR
, "stat error\n");
677 inode
= v9fs_get_inode(sb
, p9mode2unixmode(v9ses
,
678 fcall
->params
.rstat
.stat
.mode
));
680 if (IS_ERR(inode
) && (PTR_ERR(inode
) == -ENOSPC
)) {
681 eprintk(KERN_WARNING
, "inode alloc failes, returns %ld\n",
688 inode
->i_ino
= v9fs_qid2ino(&fcall
->params
.rstat
.stat
.qid
);
690 fid
= v9fs_fid_create(v9ses
, newfid
);
692 dprintk(DEBUG_ERROR
, "couldn't insert\n");
697 result
= v9fs_fid_insert(fid
, dentry
);
701 fid
->qid
= fcall
->params
.rstat
.stat
.qid
;
702 v9fs_stat2inode(&fcall
->params
.rstat
.stat
, inode
, inode
->i_sb
);
704 d_add(dentry
, inode
);
715 return ERR_PTR(result
);
719 * v9fs_vfs_unlink - VFS unlink hook to delete an inode
720 * @i: inode that is being unlinked
721 * @d: dentry that is being unlinked
725 static int v9fs_vfs_unlink(struct inode
*i
, struct dentry
*d
)
727 return v9fs_remove(i
, d
, 0);
731 * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
732 * @i: inode that is being unlinked
733 * @d: dentry that is being unlinked
737 static int v9fs_vfs_rmdir(struct inode
*i
, struct dentry
*d
)
739 return v9fs_remove(i
, d
, 1);
743 * v9fs_vfs_rename - VFS hook to rename an inode
744 * @old_dir: old dir inode
745 * @old_dentry: old dentry
746 * @new_dir: new dir inode
747 * @new_dentry: new dentry
752 v9fs_vfs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
753 struct inode
*new_dir
, struct dentry
*new_dentry
)
755 struct inode
*old_inode
= old_dentry
->d_inode
;
756 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(old_inode
);
757 struct v9fs_fid
*oldfid
= v9fs_fid_lookup(old_dentry
);
758 struct v9fs_fid
*olddirfid
;
759 struct v9fs_fid
*newdirfid
;
760 struct v9fs_wstat wstat
;
761 struct v9fs_fcall
*fcall
= NULL
;
763 int olddirfidnum
= -1;
764 int newdirfidnum
= -1;
767 dprintk(DEBUG_VFS
, "\n");
770 return PTR_ERR(oldfid
);
772 olddirfid
= v9fs_fid_clone(old_dentry
->d_parent
);
773 if(IS_ERR(olddirfid
)) {
774 retval
= PTR_ERR(olddirfid
);
778 newdirfid
= v9fs_fid_clone(new_dentry
->d_parent
);
779 if(IS_ERR(newdirfid
)) {
780 retval
= PTR_ERR(newdirfid
);
784 /* 9P can only handle file rename in the same directory */
785 if (memcmp(&olddirfid
->qid
, &newdirfid
->qid
, sizeof(newdirfid
->qid
))) {
786 dprintk(DEBUG_ERROR
, "old dir and new dir are different\n");
792 olddirfidnum
= olddirfid
->fid
;
793 newdirfidnum
= newdirfid
->fid
;
796 dprintk(DEBUG_ERROR
, "no fid for old file #%lu\n",
802 v9fs_blank_wstat(&wstat
);
803 wstat
.muid
= v9ses
->name
;
804 wstat
.name
= (char *) new_dentry
->d_name
.name
;
806 retval
= v9fs_t_wstat(v9ses
, fid
, &wstat
, &fcall
);
809 PRINT_FCALL_ERROR("wstat error", fcall
);
814 v9fs_fid_clunk(v9ses
, newdirfid
);
817 v9fs_fid_clunk(v9ses
, olddirfid
);
826 * v9fs_vfs_getattr - retrieve file metadata
827 * @mnt - mount information
828 * @dentry - file to get attributes on
829 * @stat - metadata structure to populate
834 v9fs_vfs_getattr(struct vfsmount
*mnt
, struct dentry
*dentry
,
837 struct v9fs_fcall
*fcall
= NULL
;
838 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
839 struct v9fs_fid
*fid
= v9fs_fid_clone(dentry
);
842 dprintk(DEBUG_VFS
, "dentry: %p\n", dentry
);
846 err
= v9fs_t_stat(v9ses
, fid
->fid
, &fcall
);
849 dprintk(DEBUG_ERROR
, "stat error\n");
851 v9fs_stat2inode(&fcall
->params
.rstat
.stat
, dentry
->d_inode
,
852 dentry
->d_inode
->i_sb
);
853 generic_fillattr(dentry
->d_inode
, stat
);
857 v9fs_fid_clunk(v9ses
, fid
);
862 * v9fs_vfs_setattr - set file metadata
863 * @dentry: file whose metadata to set
864 * @iattr: metadata assignment structure
868 static int v9fs_vfs_setattr(struct dentry
*dentry
, struct iattr
*iattr
)
870 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
871 struct v9fs_fid
*fid
= v9fs_fid_clone(dentry
);
872 struct v9fs_fcall
*fcall
= NULL
;
873 struct v9fs_wstat wstat
;
876 dprintk(DEBUG_VFS
, "\n");
880 v9fs_blank_wstat(&wstat
);
881 if (iattr
->ia_valid
& ATTR_MODE
)
882 wstat
.mode
= unixmode2p9mode(v9ses
, iattr
->ia_mode
);
884 if (iattr
->ia_valid
& ATTR_MTIME
)
885 wstat
.mtime
= iattr
->ia_mtime
.tv_sec
;
887 if (iattr
->ia_valid
& ATTR_ATIME
)
888 wstat
.atime
= iattr
->ia_atime
.tv_sec
;
890 if (iattr
->ia_valid
& ATTR_SIZE
)
891 wstat
.length
= iattr
->ia_size
;
893 if (v9ses
->extended
) {
894 if (iattr
->ia_valid
& ATTR_UID
)
895 wstat
.n_uid
= iattr
->ia_uid
;
897 if (iattr
->ia_valid
& ATTR_GID
)
898 wstat
.n_gid
= iattr
->ia_gid
;
901 res
= v9fs_t_wstat(v9ses
, fid
->fid
, &wstat
, &fcall
);
904 PRINT_FCALL_ERROR("wstat error", fcall
);
908 res
= inode_setattr(dentry
->d_inode
, iattr
);
910 v9fs_fid_clunk(v9ses
, fid
);
915 * v9fs_stat2inode - populate an inode structure with mistat info
916 * @stat: Plan 9 metadata (mistat) structure
917 * @inode: inode to populate
918 * @sb: superblock of filesystem
923 v9fs_stat2inode(struct v9fs_stat
*stat
, struct inode
*inode
,
924 struct super_block
*sb
)
928 struct v9fs_session_info
*v9ses
= sb
->s_fs_info
;
932 inode
->i_atime
.tv_sec
= stat
->atime
;
933 inode
->i_mtime
.tv_sec
= stat
->mtime
;
934 inode
->i_ctime
.tv_sec
= stat
->mtime
;
936 inode
->i_uid
= v9ses
->uid
;
937 inode
->i_gid
= v9ses
->gid
;
939 if (v9ses
->extended
) {
940 inode
->i_uid
= stat
->n_uid
;
941 inode
->i_gid
= stat
->n_gid
;
944 inode
->i_mode
= p9mode2unixmode(v9ses
, stat
->mode
);
945 if ((S_ISBLK(inode
->i_mode
)) || (S_ISCHR(inode
->i_mode
))) {
950 n
= stat
->extension
.len
;
951 if (n
> sizeof(ext
)-1)
953 memmove(ext
, stat
->extension
.str
, n
);
955 sscanf(ext
, "%c %u %u", &type
, &major
, &minor
);
958 inode
->i_mode
&= ~S_IFBLK
;
959 inode
->i_mode
|= S_IFCHR
;
964 dprintk(DEBUG_ERROR
, "Unknown special type %c (%.*s)\n",
965 type
, stat
->extension
.len
, stat
->extension
.str
);
967 inode
->i_rdev
= MKDEV(major
, minor
);
971 inode
->i_size
= stat
->length
;
974 (inode
->i_size
+ sb
->s_blocksize
- 1) >> sb
->s_blocksize_bits
;
978 * v9fs_qid2ino - convert qid into inode number
981 * BUG: potential for inode number collisions?
984 ino_t
v9fs_qid2ino(struct v9fs_qid
*qid
)
986 u64 path
= qid
->path
+ 2;
989 if (sizeof(ino_t
) == sizeof(path
))
990 memcpy(&i
, &path
, sizeof(ino_t
));
992 i
= (ino_t
) (path
^ (path
>> 32));
998 * v9fs_readlink - read a symlink's location (internal version)
999 * @dentry: dentry for symlink
1000 * @buffer: buffer to load symlink location into
1001 * @buflen: length of buffer
1005 static int v9fs_readlink(struct dentry
*dentry
, char *buffer
, int buflen
)
1007 int retval
= -EPERM
;
1009 struct v9fs_fcall
*fcall
= NULL
;
1010 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
1011 struct v9fs_fid
*fid
= v9fs_fid_clone(dentry
);
1014 return PTR_ERR(fid
);
1016 if (!v9ses
->extended
) {
1018 dprintk(DEBUG_ERROR
, "not extended\n");
1022 dprintk(DEBUG_VFS
, " %s\n", dentry
->d_name
.name
);
1023 retval
= v9fs_t_stat(v9ses
, fid
->fid
, &fcall
);
1026 dprintk(DEBUG_ERROR
, "stat error\n");
1035 if (!(fcall
->params
.rstat
.stat
.mode
& V9FS_DMSYMLINK
)) {
1040 /* copy extension buffer into buffer */
1041 if (fcall
->params
.rstat
.stat
.extension
.len
< buflen
)
1042 buflen
= fcall
->params
.rstat
.stat
.extension
.len
+ 1;
1044 memmove(buffer
, fcall
->params
.rstat
.stat
.extension
.str
, buflen
- 1);
1045 buffer
[buflen
-1] = 0;
1047 dprintk(DEBUG_ERROR
, "%s -> %.*s (%s)\n", dentry
->d_name
.name
, fcall
->params
.rstat
.stat
.extension
.len
,
1048 fcall
->params
.rstat
.stat
.extension
.str
, buffer
);
1055 v9fs_fid_clunk(v9ses
, fid
);
1061 * v9fs_vfs_readlink - read a symlink's location
1062 * @dentry: dentry for symlink
1063 * @buf: buffer to load symlink location into
1064 * @buflen: length of buffer
1068 static int v9fs_vfs_readlink(struct dentry
*dentry
, char __user
* buffer
,
1073 char *link
= __getname();
1075 if (unlikely(!link
))
1078 if (buflen
> PATH_MAX
)
1081 dprintk(DEBUG_VFS
, " dentry: %s (%p)\n", dentry
->d_iname
, dentry
);
1083 retval
= v9fs_readlink(dentry
, link
, buflen
);
1086 if ((ret
= copy_to_user(buffer
, link
, retval
)) != 0) {
1087 dprintk(DEBUG_ERROR
, "problem copying to user: %d\n",
1098 * v9fs_vfs_follow_link - follow a symlink path
1099 * @dentry: dentry for symlink
1104 static void *v9fs_vfs_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
1107 char *link
= __getname();
1109 dprintk(DEBUG_VFS
, "%s n", dentry
->d_name
.name
);
1112 link
= ERR_PTR(-ENOMEM
);
1114 len
= v9fs_readlink(dentry
, link
, PATH_MAX
);
1118 link
= ERR_PTR(len
);
1122 nd_set_link(nd
, link
);
1128 * v9fs_vfs_put_link - release a symlink path
1129 * @dentry: dentry for symlink
1134 static void v9fs_vfs_put_link(struct dentry
*dentry
, struct nameidata
*nd
, void *p
)
1136 char *s
= nd_get_link(nd
);
1138 dprintk(DEBUG_VFS
, " %s %s\n", dentry
->d_name
.name
, s
);
1143 static int v9fs_vfs_mkspecial(struct inode
*dir
, struct dentry
*dentry
,
1144 int mode
, const char *extension
)
1148 struct v9fs_session_info
*v9ses
;
1149 struct v9fs_fid
*dfid
, *vfid
= NULL
;
1150 struct inode
*inode
= NULL
;
1152 v9ses
= v9fs_inode2v9ses(dir
);
1153 if (!v9ses
->extended
) {
1154 dprintk(DEBUG_ERROR
, "not extended\n");
1158 dfid
= v9fs_fid_clone(dentry
->d_parent
);
1160 err
= PTR_ERR(dfid
);
1164 perm
= unixmode2p9mode(v9ses
, mode
);
1166 err
= v9fs_create(v9ses
, dfid
->fid
, (char *) dentry
->d_name
.name
,
1167 perm
, V9FS_OREAD
, (char *) extension
, &fid
, NULL
, NULL
);
1172 err
= v9fs_t_clunk(v9ses
, fid
);
1176 vfid
= v9fs_clone_walk(v9ses
, dfid
->fid
, dentry
);
1178 err
= PTR_ERR(vfid
);
1183 inode
= v9fs_inode_from_fid(v9ses
, vfid
->fid
, dir
->i_sb
);
1184 if (IS_ERR(inode
)) {
1185 err
= PTR_ERR(inode
);
1190 dentry
->d_op
= &v9fs_dentry_operations
;
1191 d_instantiate(dentry
, inode
);
1195 v9fs_fid_destroy(vfid
);
1198 v9fs_fid_clunk(v9ses
, dfid
);
1206 * v9fs_vfs_symlink - helper function to create symlinks
1207 * @dir: directory inode containing symlink
1208 * @dentry: dentry for symlink
1209 * @symname: symlink data
1211 * See 9P2000.u RFC for more information
1216 v9fs_vfs_symlink(struct inode
*dir
, struct dentry
*dentry
, const char *symname
)
1218 dprintk(DEBUG_VFS
, " %lu,%s,%s\n", dir
->i_ino
, dentry
->d_name
.name
,
1221 return v9fs_vfs_mkspecial(dir
, dentry
, S_IFLNK
, symname
);
1225 * v9fs_vfs_link - create a hardlink
1226 * @old_dentry: dentry for file to link to
1227 * @dir: inode destination for new link
1228 * @dentry: dentry for link
1232 /* XXX - lots of code dup'd from symlink and creates,
1233 * figure out a better reuse strategy
1237 v9fs_vfs_link(struct dentry
*old_dentry
, struct inode
*dir
,
1238 struct dentry
*dentry
)
1241 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(dir
);
1242 struct v9fs_fid
*oldfid
;
1245 dprintk(DEBUG_VFS
, " %lu,%s,%s\n", dir
->i_ino
, dentry
->d_name
.name
,
1246 old_dentry
->d_name
.name
);
1248 oldfid
= v9fs_fid_clone(old_dentry
);
1250 return PTR_ERR(oldfid
);
1253 if (unlikely(!name
)) {
1258 sprintf(name
, "%d\n", oldfid
->fid
);
1259 retval
= v9fs_vfs_mkspecial(dir
, dentry
, V9FS_DMLINK
, name
);
1263 v9fs_fid_clunk(v9ses
, oldfid
);
1268 * v9fs_vfs_mknod - create a special file
1269 * @dir: inode destination for new link
1270 * @dentry: dentry for file
1271 * @mode: mode for creation
1272 * @dev_t: device associated with special file
1277 v9fs_vfs_mknod(struct inode
*dir
, struct dentry
*dentry
, int mode
, dev_t rdev
)
1282 dprintk(DEBUG_VFS
, " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir
->i_ino
,
1283 dentry
->d_name
.name
, mode
, MAJOR(rdev
), MINOR(rdev
));
1285 if (!new_valid_dev(rdev
))
1291 /* build extension */
1293 sprintf(name
, "b %u %u", MAJOR(rdev
), MINOR(rdev
));
1294 else if (S_ISCHR(mode
))
1295 sprintf(name
, "c %u %u", MAJOR(rdev
), MINOR(rdev
));
1296 else if (S_ISFIFO(mode
))
1303 retval
= v9fs_vfs_mkspecial(dir
, dentry
, mode
, name
);
1309 static struct inode_operations v9fs_dir_inode_operations_ext
= {
1310 .create
= v9fs_vfs_create
,
1311 .lookup
= v9fs_vfs_lookup
,
1312 .symlink
= v9fs_vfs_symlink
,
1313 .link
= v9fs_vfs_link
,
1314 .unlink
= v9fs_vfs_unlink
,
1315 .mkdir
= v9fs_vfs_mkdir
,
1316 .rmdir
= v9fs_vfs_rmdir
,
1317 .mknod
= v9fs_vfs_mknod
,
1318 .rename
= v9fs_vfs_rename
,
1319 .readlink
= v9fs_vfs_readlink
,
1320 .getattr
= v9fs_vfs_getattr
,
1321 .setattr
= v9fs_vfs_setattr
,
1324 static struct inode_operations v9fs_dir_inode_operations
= {
1325 .create
= v9fs_vfs_create
,
1326 .lookup
= v9fs_vfs_lookup
,
1327 .unlink
= v9fs_vfs_unlink
,
1328 .mkdir
= v9fs_vfs_mkdir
,
1329 .rmdir
= v9fs_vfs_rmdir
,
1330 .mknod
= v9fs_vfs_mknod
,
1331 .rename
= v9fs_vfs_rename
,
1332 .getattr
= v9fs_vfs_getattr
,
1333 .setattr
= v9fs_vfs_setattr
,
1336 static struct inode_operations v9fs_file_inode_operations
= {
1337 .getattr
= v9fs_vfs_getattr
,
1338 .setattr
= v9fs_vfs_setattr
,
1341 static struct inode_operations v9fs_symlink_inode_operations
= {
1342 .readlink
= v9fs_vfs_readlink
,
1343 .follow_link
= v9fs_vfs_follow_link
,
1344 .put_link
= v9fs_vfs_put_link
,
1345 .getattr
= v9fs_vfs_getattr
,
1346 .setattr
= v9fs_vfs_setattr
,