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
;
207 inode
->i_blksize
= sb
->s_blocksize
;
210 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
211 inode
->i_mapping
->a_ops
= &v9fs_addr_operations
;
213 switch (mode
& S_IFMT
) {
218 if(!v9ses
->extended
) {
219 dprintk(DEBUG_ERROR
, "special files without extended mode\n");
220 return ERR_PTR(-EINVAL
);
222 init_special_inode(inode
, inode
->i_mode
,
226 inode
->i_op
= &v9fs_file_inode_operations
;
227 inode
->i_fop
= &v9fs_file_operations
;
230 if(!v9ses
->extended
) {
231 dprintk(DEBUG_ERROR
, "extended modes used w/o 9P2000.u\n");
232 return ERR_PTR(-EINVAL
);
234 inode
->i_op
= &v9fs_symlink_inode_operations
;
239 inode
->i_op
= &v9fs_dir_inode_operations_ext
;
241 inode
->i_op
= &v9fs_dir_inode_operations
;
242 inode
->i_fop
= &v9fs_dir_operations
;
245 dprintk(DEBUG_ERROR
, "BAD mode 0x%x S_IFMT 0x%x\n",
246 mode
, mode
& S_IFMT
);
247 return ERR_PTR(-EINVAL
);
250 eprintk(KERN_WARNING
, "Problem allocating inode\n");
251 return ERR_PTR(-ENOMEM
);
257 v9fs_create(struct v9fs_session_info
*v9ses
, u32 pfid
, char *name
, u32 perm
,
258 u8 mode
, char *extension
, u32
*fidp
, struct v9fs_qid
*qid
, u32
*iounit
)
262 struct v9fs_fcall
*fcall
;
264 fid
= v9fs_get_idpool(&v9ses
->fidpool
);
266 eprintk(KERN_WARNING
, "no free fids available\n");
270 err
= v9fs_t_walk(v9ses
, pfid
, fid
, NULL
, &fcall
);
272 PRINT_FCALL_ERROR("clone error", fcall
);
273 if (fcall
&& fcall
->id
== RWALK
)
280 err
= v9fs_t_create(v9ses
, fid
, name
, perm
, mode
, extension
, &fcall
);
282 PRINT_FCALL_ERROR("create fails", fcall
);
287 *iounit
= fcall
->params
.rcreate
.iounit
;
290 *qid
= fcall
->params
.rcreate
.qid
;
299 v9fs_t_clunk(v9ses
, fid
);
304 v9fs_put_idpool(fid
, &v9ses
->fidpool
);
310 static struct v9fs_fid
*
311 v9fs_clone_walk(struct v9fs_session_info
*v9ses
, u32 fid
, struct dentry
*dentry
)
315 struct v9fs_fid
*ret
;
316 struct v9fs_fcall
*fcall
;
318 nfid
= v9fs_get_idpool(&v9ses
->fidpool
);
320 eprintk(KERN_WARNING
, "no free fids available\n");
321 return ERR_PTR(-ENOSPC
);
324 err
= v9fs_t_walk(v9ses
, fid
, nfid
, (char *) dentry
->d_name
.name
,
328 if (fcall
&& fcall
->id
== RWALK
)
331 PRINT_FCALL_ERROR("walk error", fcall
);
332 v9fs_put_idpool(nfid
, &v9ses
->fidpool
);
338 ret
= v9fs_fid_create(v9ses
, nfid
);
344 err
= v9fs_fid_insert(ret
, dentry
);
346 v9fs_fid_destroy(ret
);
353 v9fs_t_clunk(v9ses
, nfid
);
360 static struct inode
*
361 v9fs_inode_from_fid(struct v9fs_session_info
*v9ses
, u32 fid
,
362 struct super_block
*sb
)
366 struct v9fs_fcall
*fcall
;
369 err
= v9fs_t_stat(v9ses
, fid
, &fcall
);
371 PRINT_FCALL_ERROR("stat error", fcall
);
375 umode
= p9mode2unixmode(v9ses
, fcall
->params
.rstat
.stat
.mode
);
376 ret
= v9fs_get_inode(sb
, umode
);
383 v9fs_stat2inode(&fcall
->params
.rstat
.stat
, ret
, sb
);
396 * v9fs_remove - helper function to remove files and directories
397 * @dir: directory inode that is being deleted
398 * @file: dentry that is being deleted
399 * @rmdir: removing a directory
403 static int v9fs_remove(struct inode
*dir
, struct dentry
*file
, int rmdir
)
405 struct v9fs_fcall
*fcall
= NULL
;
406 struct super_block
*sb
= NULL
;
407 struct v9fs_session_info
*v9ses
= NULL
;
408 struct v9fs_fid
*v9fid
= NULL
;
409 struct inode
*file_inode
= NULL
;
413 dprintk(DEBUG_VFS
, "inode: %p dentry: %p rmdir: %d\n", dir
, file
,
416 file_inode
= file
->d_inode
;
417 sb
= file_inode
->i_sb
;
418 v9ses
= v9fs_inode2v9ses(file_inode
);
419 v9fid
= v9fs_fid_lookup(file
);
429 dprintk(DEBUG_ERROR
, "inode #%lu, no fid!\n",
434 result
= v9fs_t_remove(v9ses
, fid
, &fcall
);
436 PRINT_FCALL_ERROR("remove fails", fcall
);
438 v9fs_put_idpool(fid
, &v9ses
->fidpool
);
439 v9fs_fid_destroy(v9fid
);
447 v9fs_open_created(struct inode
*inode
, struct file
*file
)
453 * v9fs_vfs_create - VFS hook to create files
454 * @inode: directory inode that is being deleted
455 * @dentry: dentry that is being deleted
456 * @mode: create permissions
457 * @nd: path information
462 v9fs_vfs_create(struct inode
*dir
, struct dentry
*dentry
, int mode
,
463 struct nameidata
*nd
)
466 u32 fid
, perm
, iounit
;
468 struct v9fs_session_info
*v9ses
;
469 struct v9fs_fid
*dfid
, *vfid
, *ffid
;
476 v9ses
= v9fs_inode2v9ses(dir
);
477 dfid
= v9fs_fid_lookup(dentry
->d_parent
);
478 perm
= unixmode2p9mode(v9ses
, mode
);
480 if (nd
&& nd
->flags
& LOOKUP_OPEN
)
481 flags
= nd
->intent
.open
.flags
- 1;
485 err
= v9fs_create(v9ses
, dfid
->fid
, (char *) dentry
->d_name
.name
,
486 perm
, v9fs_uflags2omode(flags
), NULL
, &fid
, &qid
, &iounit
);
491 vfid
= v9fs_clone_walk(v9ses
, dfid
->fid
, dentry
);
498 inode
= v9fs_inode_from_fid(v9ses
, vfid
->fid
, dir
->i_sb
);
500 err
= PTR_ERR(inode
);
505 dentry
->d_op
= &v9fs_dentry_operations
;
506 d_instantiate(dentry
, inode
);
508 if (nd
&& nd
->flags
& LOOKUP_OPEN
) {
509 ffid
= v9fs_fid_create(v9ses
, fid
);
513 filp
= lookup_instantiate_filp(nd
, dentry
, v9fs_open_created
);
515 v9fs_fid_destroy(ffid
);
516 return PTR_ERR(filp
);
520 ffid
->rdir_fcall
= NULL
;
522 ffid
->iounit
= iounit
;
524 filp
->private_data
= ffid
;
531 v9fs_fid_destroy(vfid
);
540 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
541 * @inode: inode that is being unlinked
542 * @dentry: dentry that is being unlinked
543 * @mode: mode for new directory
547 static int v9fs_vfs_mkdir(struct inode
*dir
, struct dentry
*dentry
, int mode
)
551 struct v9fs_session_info
*v9ses
;
552 struct v9fs_fid
*dfid
, *vfid
;
557 v9ses
= v9fs_inode2v9ses(dir
);
558 dfid
= v9fs_fid_lookup(dentry
->d_parent
);
559 perm
= unixmode2p9mode(v9ses
, mode
| S_IFDIR
);
561 err
= v9fs_create(v9ses
, dfid
->fid
, (char *) dentry
->d_name
.name
,
562 perm
, V9FS_OREAD
, NULL
, &fid
, NULL
, NULL
);
565 dprintk(DEBUG_ERROR
, "create error %d\n", err
);
569 err
= v9fs_t_clunk(v9ses
, fid
);
571 dprintk(DEBUG_ERROR
, "clunk error %d\n", err
);
575 vfid
= v9fs_clone_walk(v9ses
, dfid
->fid
, dentry
);
582 inode
= v9fs_inode_from_fid(v9ses
, vfid
->fid
, dir
->i_sb
);
584 err
= PTR_ERR(inode
);
589 dentry
->d_op
= &v9fs_dentry_operations
;
590 d_instantiate(dentry
, inode
);
595 v9fs_fid_destroy(vfid
);
601 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
602 * @dir: inode that is being walked from
603 * @dentry: dentry that is being walked to?
604 * @nameidata: path data
608 static struct dentry
*v9fs_vfs_lookup(struct inode
*dir
, struct dentry
*dentry
,
609 struct nameidata
*nameidata
)
611 struct super_block
*sb
;
612 struct v9fs_session_info
*v9ses
;
613 struct v9fs_fid
*dirfid
;
614 struct v9fs_fid
*fid
;
616 struct v9fs_fcall
*fcall
= NULL
;
621 dprintk(DEBUG_VFS
, "dir: %p dentry: (%s) %p nameidata: %p\n",
622 dir
, dentry
->d_name
.name
, dentry
, nameidata
);
625 v9ses
= v9fs_inode2v9ses(dir
);
626 dentry
->d_op
= &v9fs_dentry_operations
;
627 dirfid
= v9fs_fid_lookup(dentry
->d_parent
);
630 dprintk(DEBUG_ERROR
, "no dirfid\n");
631 return ERR_PTR(-EINVAL
);
634 dirfidnum
= dirfid
->fid
;
637 dprintk(DEBUG_ERROR
, "no dirfid for inode %p, #%lu\n",
639 return ERR_PTR(-EBADF
);
642 newfid
= v9fs_get_idpool(&v9ses
->fidpool
);
644 eprintk(KERN_WARNING
, "newfid fails!\n");
645 return ERR_PTR(-ENOSPC
);
648 result
= v9fs_t_walk(v9ses
, dirfidnum
, newfid
,
649 (char *)dentry
->d_name
.name
, &fcall
);
652 if (fcall
&& fcall
->id
== RWALK
)
653 v9fs_t_clunk(v9ses
, newfid
);
655 v9fs_put_idpool(newfid
, &v9ses
->fidpool
);
657 if (result
== -ENOENT
) {
660 "Return negative dentry %p count %d\n",
661 dentry
, atomic_read(&dentry
->d_count
));
665 dprintk(DEBUG_ERROR
, "walk error:%d\n", result
);
670 result
= v9fs_t_stat(v9ses
, newfid
, &fcall
);
672 dprintk(DEBUG_ERROR
, "stat error\n");
676 inode
= v9fs_get_inode(sb
, p9mode2unixmode(v9ses
,
677 fcall
->params
.rstat
.stat
.mode
));
679 if (IS_ERR(inode
) && (PTR_ERR(inode
) == -ENOSPC
)) {
680 eprintk(KERN_WARNING
, "inode alloc failes, returns %ld\n",
687 inode
->i_ino
= v9fs_qid2ino(&fcall
->params
.rstat
.stat
.qid
);
689 fid
= v9fs_fid_create(v9ses
, newfid
);
691 dprintk(DEBUG_ERROR
, "couldn't insert\n");
696 result
= v9fs_fid_insert(fid
, dentry
);
700 fid
->qid
= fcall
->params
.rstat
.stat
.qid
;
701 v9fs_stat2inode(&fcall
->params
.rstat
.stat
, inode
, inode
->i_sb
);
703 d_add(dentry
, inode
);
710 return ERR_PTR(result
);
714 * v9fs_vfs_unlink - VFS unlink hook to delete an inode
715 * @i: inode that is being unlinked
716 * @d: dentry that is being unlinked
720 static int v9fs_vfs_unlink(struct inode
*i
, struct dentry
*d
)
722 return v9fs_remove(i
, d
, 0);
726 * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
727 * @i: inode that is being unlinked
728 * @d: dentry that is being unlinked
732 static int v9fs_vfs_rmdir(struct inode
*i
, struct dentry
*d
)
734 return v9fs_remove(i
, d
, 1);
738 * v9fs_vfs_rename - VFS hook to rename an inode
739 * @old_dir: old dir inode
740 * @old_dentry: old dentry
741 * @new_dir: new dir inode
742 * @new_dentry: new dentry
747 v9fs_vfs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
748 struct inode
*new_dir
, struct dentry
*new_dentry
)
750 struct inode
*old_inode
= old_dentry
->d_inode
;
751 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(old_inode
);
752 struct v9fs_fid
*oldfid
= v9fs_fid_lookup(old_dentry
);
753 struct v9fs_fid
*olddirfid
=
754 v9fs_fid_lookup(old_dentry
->d_parent
);
755 struct v9fs_fid
*newdirfid
=
756 v9fs_fid_lookup(new_dentry
->d_parent
);
757 struct v9fs_wstat wstat
;
758 struct v9fs_fcall
*fcall
= NULL
;
760 int olddirfidnum
= -1;
761 int newdirfidnum
= -1;
764 dprintk(DEBUG_VFS
, "\n");
766 if ((!oldfid
) || (!olddirfid
) || (!newdirfid
)) {
767 dprintk(DEBUG_ERROR
, "problem with arguments\n");
771 /* 9P can only handle file rename in the same directory */
772 if (memcmp(&olddirfid
->qid
, &newdirfid
->qid
, sizeof(newdirfid
->qid
))) {
773 dprintk(DEBUG_ERROR
, "old dir and new dir are different\n");
779 olddirfidnum
= olddirfid
->fid
;
780 newdirfidnum
= newdirfid
->fid
;
783 dprintk(DEBUG_ERROR
, "no fid for old file #%lu\n",
789 v9fs_blank_wstat(&wstat
);
790 wstat
.muid
= v9ses
->name
;
791 wstat
.name
= (char *) new_dentry
->d_name
.name
;
793 retval
= v9fs_t_wstat(v9ses
, fid
, &wstat
, &fcall
);
797 PRINT_FCALL_ERROR("wstat error", fcall
);
804 * v9fs_vfs_getattr - retrieve file metadata
805 * @mnt - mount information
806 * @dentry - file to get attributes on
807 * @stat - metadata structure to populate
812 v9fs_vfs_getattr(struct vfsmount
*mnt
, struct dentry
*dentry
,
815 struct v9fs_fcall
*fcall
= NULL
;
816 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
817 struct v9fs_fid
*fid
= v9fs_fid_lookup(dentry
);
820 dprintk(DEBUG_VFS
, "dentry: %p\n", dentry
);
823 "couldn't find fid associated with dentry\n");
827 err
= v9fs_t_stat(v9ses
, fid
->fid
, &fcall
);
830 dprintk(DEBUG_ERROR
, "stat error\n");
832 v9fs_stat2inode(&fcall
->params
.rstat
.stat
, dentry
->d_inode
,
833 dentry
->d_inode
->i_sb
);
834 generic_fillattr(dentry
->d_inode
, stat
);
842 * v9fs_vfs_setattr - set file metadata
843 * @dentry: file whose metadata to set
844 * @iattr: metadata assignment structure
848 static int v9fs_vfs_setattr(struct dentry
*dentry
, struct iattr
*iattr
)
850 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
851 struct v9fs_fid
*fid
= v9fs_fid_lookup(dentry
);
852 struct v9fs_fcall
*fcall
= NULL
;
853 struct v9fs_wstat wstat
;
856 dprintk(DEBUG_VFS
, "\n");
860 "Couldn't find fid associated with dentry\n");
864 v9fs_blank_wstat(&wstat
);
865 if (iattr
->ia_valid
& ATTR_MODE
)
866 wstat
.mode
= unixmode2p9mode(v9ses
, iattr
->ia_mode
);
868 if (iattr
->ia_valid
& ATTR_MTIME
)
869 wstat
.mtime
= iattr
->ia_mtime
.tv_sec
;
871 if (iattr
->ia_valid
& ATTR_ATIME
)
872 wstat
.atime
= iattr
->ia_atime
.tv_sec
;
874 if (iattr
->ia_valid
& ATTR_SIZE
)
875 wstat
.length
= iattr
->ia_size
;
877 if (v9ses
->extended
) {
878 if (iattr
->ia_valid
& ATTR_UID
)
879 wstat
.n_uid
= iattr
->ia_uid
;
881 if (iattr
->ia_valid
& ATTR_GID
)
882 wstat
.n_gid
= iattr
->ia_gid
;
885 res
= v9fs_t_wstat(v9ses
, fid
->fid
, &wstat
, &fcall
);
888 PRINT_FCALL_ERROR("wstat error", fcall
);
892 res
= inode_setattr(dentry
->d_inode
, iattr
);
898 * v9fs_stat2inode - populate an inode structure with mistat info
899 * @stat: Plan 9 metadata (mistat) structure
900 * @inode: inode to populate
901 * @sb: superblock of filesystem
906 v9fs_stat2inode(struct v9fs_stat
*stat
, struct inode
*inode
,
907 struct super_block
*sb
)
911 struct v9fs_session_info
*v9ses
= sb
->s_fs_info
;
915 inode
->i_atime
.tv_sec
= stat
->atime
;
916 inode
->i_mtime
.tv_sec
= stat
->mtime
;
917 inode
->i_ctime
.tv_sec
= stat
->mtime
;
919 inode
->i_uid
= v9ses
->uid
;
920 inode
->i_gid
= v9ses
->gid
;
922 if (v9ses
->extended
) {
923 inode
->i_uid
= stat
->n_uid
;
924 inode
->i_gid
= stat
->n_gid
;
927 inode
->i_mode
= p9mode2unixmode(v9ses
, stat
->mode
);
928 if ((S_ISBLK(inode
->i_mode
)) || (S_ISCHR(inode
->i_mode
))) {
933 n
= stat
->extension
.len
;
934 if (n
> sizeof(ext
)-1)
936 memmove(ext
, stat
->extension
.str
, n
);
938 sscanf(ext
, "%c %u %u", &type
, &major
, &minor
);
941 inode
->i_mode
&= ~S_IFBLK
;
942 inode
->i_mode
|= S_IFCHR
;
947 dprintk(DEBUG_ERROR
, "Unknown special type %c (%.*s)\n",
948 type
, stat
->extension
.len
, stat
->extension
.str
);
950 inode
->i_rdev
= MKDEV(major
, minor
);
954 inode
->i_size
= stat
->length
;
956 inode
->i_blksize
= sb
->s_blocksize
;
958 (inode
->i_size
+ inode
->i_blksize
- 1) >> sb
->s_blocksize_bits
;
962 * v9fs_qid2ino - convert qid into inode number
965 * BUG: potential for inode number collisions?
968 ino_t
v9fs_qid2ino(struct v9fs_qid
*qid
)
970 u64 path
= qid
->path
+ 2;
973 if (sizeof(ino_t
) == sizeof(path
))
974 memcpy(&i
, &path
, sizeof(ino_t
));
976 i
= (ino_t
) (path
^ (path
>> 32));
982 * v9fs_readlink - read a symlink's location (internal version)
983 * @dentry: dentry for symlink
984 * @buffer: buffer to load symlink location into
985 * @buflen: length of buffer
989 static int v9fs_readlink(struct dentry
*dentry
, char *buffer
, int buflen
)
993 struct v9fs_fcall
*fcall
= NULL
;
994 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
995 struct v9fs_fid
*fid
= v9fs_fid_lookup(dentry
);
998 dprintk(DEBUG_ERROR
, "could not resolve fid from dentry\n");
1003 if (!v9ses
->extended
) {
1005 dprintk(DEBUG_ERROR
, "not extended\n");
1009 dprintk(DEBUG_VFS
, " %s\n", dentry
->d_name
.name
);
1010 retval
= v9fs_t_stat(v9ses
, fid
->fid
, &fcall
);
1013 dprintk(DEBUG_ERROR
, "stat error\n");
1020 if (!(fcall
->params
.rstat
.stat
.mode
& V9FS_DMSYMLINK
)) {
1025 /* copy extension buffer into buffer */
1026 if (fcall
->params
.rstat
.stat
.extension
.len
< buflen
)
1027 buflen
= fcall
->params
.rstat
.stat
.extension
.len
+ 1;
1029 memmove(buffer
, fcall
->params
.rstat
.stat
.extension
.str
, buflen
- 1);
1030 buffer
[buflen
-1] = 0;
1032 dprintk(DEBUG_ERROR
, "%s -> %.*s (%s)\n", dentry
->d_name
.name
, fcall
->params
.rstat
.stat
.extension
.len
,
1033 fcall
->params
.rstat
.stat
.extension
.str
, buffer
);
1043 * v9fs_vfs_readlink - read a symlink's location
1044 * @dentry: dentry for symlink
1045 * @buf: buffer to load symlink location into
1046 * @buflen: length of buffer
1050 static int v9fs_vfs_readlink(struct dentry
*dentry
, char __user
* buffer
,
1055 char *link
= __getname();
1057 if (buflen
> PATH_MAX
)
1060 dprintk(DEBUG_VFS
, " dentry: %s (%p)\n", dentry
->d_iname
, dentry
);
1062 retval
= v9fs_readlink(dentry
, link
, buflen
);
1065 if ((ret
= copy_to_user(buffer
, link
, retval
)) != 0) {
1066 dprintk(DEBUG_ERROR
, "problem copying to user: %d\n",
1077 * v9fs_vfs_follow_link - follow a symlink path
1078 * @dentry: dentry for symlink
1083 static void *v9fs_vfs_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
1086 char *link
= __getname();
1088 dprintk(DEBUG_VFS
, "%s n", dentry
->d_name
.name
);
1091 link
= ERR_PTR(-ENOMEM
);
1093 len
= v9fs_readlink(dentry
, link
, PATH_MAX
);
1097 link
= ERR_PTR(len
);
1101 nd_set_link(nd
, link
);
1107 * v9fs_vfs_put_link - release a symlink path
1108 * @dentry: dentry for symlink
1113 static void v9fs_vfs_put_link(struct dentry
*dentry
, struct nameidata
*nd
, void *p
)
1115 char *s
= nd_get_link(nd
);
1117 dprintk(DEBUG_VFS
, " %s %s\n", dentry
->d_name
.name
, s
);
1122 static int v9fs_vfs_mkspecial(struct inode
*dir
, struct dentry
*dentry
,
1123 int mode
, const char *extension
)
1127 struct v9fs_session_info
*v9ses
;
1128 struct v9fs_fid
*dfid
, *vfid
;
1129 struct inode
*inode
;
1133 v9ses
= v9fs_inode2v9ses(dir
);
1134 dfid
= v9fs_fid_lookup(dentry
->d_parent
);
1135 perm
= unixmode2p9mode(v9ses
, mode
);
1137 if (!v9ses
->extended
) {
1138 dprintk(DEBUG_ERROR
, "not extended\n");
1142 err
= v9fs_create(v9ses
, dfid
->fid
, (char *) dentry
->d_name
.name
,
1143 perm
, V9FS_OREAD
, (char *) extension
, &fid
, NULL
, NULL
);
1148 err
= v9fs_t_clunk(v9ses
, fid
);
1152 vfid
= v9fs_clone_walk(v9ses
, dfid
->fid
, dentry
);
1154 err
= PTR_ERR(vfid
);
1159 inode
= v9fs_inode_from_fid(v9ses
, vfid
->fid
, dir
->i_sb
);
1160 if (IS_ERR(inode
)) {
1161 err
= PTR_ERR(inode
);
1166 dentry
->d_op
= &v9fs_dentry_operations
;
1167 d_instantiate(dentry
, inode
);
1172 v9fs_fid_destroy(vfid
);
1182 * v9fs_vfs_symlink - helper function to create symlinks
1183 * @dir: directory inode containing symlink
1184 * @dentry: dentry for symlink
1185 * @symname: symlink data
1187 * See 9P2000.u RFC for more information
1192 v9fs_vfs_symlink(struct inode
*dir
, struct dentry
*dentry
, const char *symname
)
1194 dprintk(DEBUG_VFS
, " %lu,%s,%s\n", dir
->i_ino
, dentry
->d_name
.name
,
1197 return v9fs_vfs_mkspecial(dir
, dentry
, S_IFLNK
, symname
);
1201 * v9fs_vfs_link - create a hardlink
1202 * @old_dentry: dentry for file to link to
1203 * @dir: inode destination for new link
1204 * @dentry: dentry for link
1208 /* XXX - lots of code dup'd from symlink and creates,
1209 * figure out a better reuse strategy
1213 v9fs_vfs_link(struct dentry
*old_dentry
, struct inode
*dir
,
1214 struct dentry
*dentry
)
1217 struct v9fs_fid
*oldfid
;
1220 dprintk(DEBUG_VFS
, " %lu,%s,%s\n", dir
->i_ino
, dentry
->d_name
.name
,
1221 old_dentry
->d_name
.name
);
1223 oldfid
= v9fs_fid_lookup(old_dentry
);
1225 dprintk(DEBUG_ERROR
, "can't find oldfid\n");
1230 sprintf(name
, "%d\n", oldfid
->fid
);
1231 retval
= v9fs_vfs_mkspecial(dir
, dentry
, V9FS_DMLINK
, name
);
1238 * v9fs_vfs_mknod - create a special file
1239 * @dir: inode destination for new link
1240 * @dentry: dentry for file
1241 * @mode: mode for creation
1242 * @dev_t: device associated with special file
1247 v9fs_vfs_mknod(struct inode
*dir
, struct dentry
*dentry
, int mode
, dev_t rdev
)
1252 dprintk(DEBUG_VFS
, " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir
->i_ino
,
1253 dentry
->d_name
.name
, mode
, MAJOR(rdev
), MINOR(rdev
));
1255 if (!new_valid_dev(rdev
))
1261 /* build extension */
1263 sprintf(name
, "b %u %u", MAJOR(rdev
), MINOR(rdev
));
1264 else if (S_ISCHR(mode
))
1265 sprintf(name
, "c %u %u", MAJOR(rdev
), MINOR(rdev
));
1266 else if (S_ISFIFO(mode
))
1273 retval
= v9fs_vfs_mkspecial(dir
, dentry
, mode
, name
);
1279 static struct inode_operations v9fs_dir_inode_operations_ext
= {
1280 .create
= v9fs_vfs_create
,
1281 .lookup
= v9fs_vfs_lookup
,
1282 .symlink
= v9fs_vfs_symlink
,
1283 .link
= v9fs_vfs_link
,
1284 .unlink
= v9fs_vfs_unlink
,
1285 .mkdir
= v9fs_vfs_mkdir
,
1286 .rmdir
= v9fs_vfs_rmdir
,
1287 .mknod
= v9fs_vfs_mknod
,
1288 .rename
= v9fs_vfs_rename
,
1289 .readlink
= v9fs_vfs_readlink
,
1290 .getattr
= v9fs_vfs_getattr
,
1291 .setattr
= v9fs_vfs_setattr
,
1294 static struct inode_operations v9fs_dir_inode_operations
= {
1295 .create
= v9fs_vfs_create
,
1296 .lookup
= v9fs_vfs_lookup
,
1297 .unlink
= v9fs_vfs_unlink
,
1298 .mkdir
= v9fs_vfs_mkdir
,
1299 .rmdir
= v9fs_vfs_rmdir
,
1300 .mknod
= v9fs_vfs_mknod
,
1301 .rename
= v9fs_vfs_rename
,
1302 .getattr
= v9fs_vfs_getattr
,
1303 .setattr
= v9fs_vfs_setattr
,
1306 static struct inode_operations v9fs_file_inode_operations
= {
1307 .getattr
= v9fs_vfs_getattr
,
1308 .setattr
= v9fs_vfs_setattr
,
1311 static struct inode_operations v9fs_symlink_inode_operations
= {
1312 .readlink
= v9fs_vfs_readlink
,
1313 .follow_link
= v9fs_vfs_follow_link
,
1314 .put_link
= v9fs_vfs_put_link
,
1315 .getattr
= v9fs_vfs_getattr
,
1316 .setattr
= v9fs_vfs_setattr
,