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/inet.h>
34 #include <linux/namei.h>
35 #include <linux/idr.h>
43 static const struct inode_operations v9fs_dir_inode_operations
;
44 static const struct inode_operations v9fs_dir_inode_operations_ext
;
45 static const struct inode_operations v9fs_file_inode_operations
;
46 static const struct inode_operations v9fs_symlink_inode_operations
;
49 * unixmode2p9mode - convert unix mode bits to plan 9
50 * @v9ses: v9fs session information
51 * @mode: mode to convert
55 static int unixmode2p9mode(struct v9fs_session_info
*v9ses
, int mode
)
61 if (v9ses
->extended
) {
63 res
|= V9FS_DMSYMLINK
;
64 if (v9ses
->nodev
== 0) {
68 res
|= V9FS_DMNAMEDPIPE
;
75 if ((mode
& S_ISUID
) == S_ISUID
)
77 if ((mode
& S_ISGID
) == S_ISGID
)
79 if ((mode
& V9FS_DMLINK
))
87 * p9mode2unixmode- convert plan9 mode bits to unix mode bits
88 * @v9ses: v9fs session information
89 * @mode: mode to convert
93 static int p9mode2unixmode(struct v9fs_session_info
*v9ses
, int mode
)
99 if ((mode
& V9FS_DMDIR
) == V9FS_DMDIR
)
101 else if ((mode
& V9FS_DMSYMLINK
) && (v9ses
->extended
))
103 else if ((mode
& V9FS_DMSOCKET
) && (v9ses
->extended
)
104 && (v9ses
->nodev
== 0))
106 else if ((mode
& V9FS_DMNAMEDPIPE
) && (v9ses
->extended
)
107 && (v9ses
->nodev
== 0))
109 else if ((mode
& V9FS_DMDEVICE
) && (v9ses
->extended
)
110 && (v9ses
->nodev
== 0))
115 if (v9ses
->extended
) {
116 if ((mode
& V9FS_DMSETUID
) == V9FS_DMSETUID
)
119 if ((mode
& V9FS_DMSETGID
) == V9FS_DMSETGID
)
126 int v9fs_uflags2omode(int uflags
)
149 if (uflags
& O_TRUNC
)
152 if (uflags
& O_APPEND
)
159 * v9fs_blank_wstat - helper function to setup a 9P stat structure
160 * @v9ses: 9P session info (for determining extended mode)
161 * @wstat: structure to initialize
166 v9fs_blank_wstat(struct v9fs_wstat
*wstat
)
170 wstat
->qid
.type
= ~0;
171 wstat
->qid
.version
= ~0;
172 *((long long *)&wstat
->qid
.path
) = ~0;
184 wstat
->extension
= NULL
;
188 * v9fs_get_inode - helper function to setup an inode
190 * @mode: mode to setup inode with
194 struct inode
*v9fs_get_inode(struct super_block
*sb
, int mode
)
197 struct v9fs_session_info
*v9ses
= sb
->s_fs_info
;
199 dprintk(DEBUG_VFS
, "super block: %p mode: %o\n", sb
, mode
);
201 inode
= new_inode(sb
);
203 inode
->i_mode
= mode
;
204 inode
->i_uid
= current
->fsuid
;
205 inode
->i_gid
= current
->fsgid
;
208 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
209 inode
->i_mapping
->a_ops
= &v9fs_addr_operations
;
211 switch (mode
& S_IFMT
) {
216 if(!v9ses
->extended
) {
217 dprintk(DEBUG_ERROR
, "special files without extended mode\n");
218 return ERR_PTR(-EINVAL
);
220 init_special_inode(inode
, inode
->i_mode
,
224 inode
->i_op
= &v9fs_file_inode_operations
;
225 inode
->i_fop
= &v9fs_file_operations
;
228 if(!v9ses
->extended
) {
229 dprintk(DEBUG_ERROR
, "extended modes used w/o 9P2000.u\n");
230 return ERR_PTR(-EINVAL
);
232 inode
->i_op
= &v9fs_symlink_inode_operations
;
237 inode
->i_op
= &v9fs_dir_inode_operations_ext
;
239 inode
->i_op
= &v9fs_dir_inode_operations
;
240 inode
->i_fop
= &v9fs_dir_operations
;
243 dprintk(DEBUG_ERROR
, "BAD mode 0x%x S_IFMT 0x%x\n",
244 mode
, mode
& S_IFMT
);
245 return ERR_PTR(-EINVAL
);
248 eprintk(KERN_WARNING
, "Problem allocating inode\n");
249 return ERR_PTR(-ENOMEM
);
255 v9fs_create(struct v9fs_session_info
*v9ses
, u32 pfid
, char *name
, u32 perm
,
256 u8 mode
, char *extension
, u32
*fidp
, struct v9fs_qid
*qid
, u32
*iounit
)
260 struct v9fs_fcall
*fcall
;
262 fid
= v9fs_get_idpool(&v9ses
->fidpool
);
264 eprintk(KERN_WARNING
, "no free fids available\n");
268 err
= v9fs_t_walk(v9ses
, pfid
, fid
, NULL
, &fcall
);
270 PRINT_FCALL_ERROR("clone error", fcall
);
271 if (fcall
&& fcall
->id
== RWALK
)
278 err
= v9fs_t_create(v9ses
, fid
, name
, perm
, mode
, extension
, &fcall
);
280 PRINT_FCALL_ERROR("create fails", fcall
);
285 *iounit
= fcall
->params
.rcreate
.iounit
;
288 *qid
= fcall
->params
.rcreate
.qid
;
297 v9fs_t_clunk(v9ses
, fid
);
301 if (fid
!= V9FS_NOFID
)
302 v9fs_put_idpool(fid
, &v9ses
->fidpool
);
308 static struct v9fs_fid
*
309 v9fs_clone_walk(struct v9fs_session_info
*v9ses
, u32 fid
, struct dentry
*dentry
)
313 struct v9fs_fid
*ret
;
314 struct v9fs_fcall
*fcall
;
316 nfid
= v9fs_get_idpool(&v9ses
->fidpool
);
318 eprintk(KERN_WARNING
, "no free fids available\n");
319 return ERR_PTR(-ENOSPC
);
322 err
= v9fs_t_walk(v9ses
, fid
, nfid
, (char *) dentry
->d_name
.name
,
326 if (fcall
&& fcall
->id
== RWALK
)
329 PRINT_FCALL_ERROR("walk error", fcall
);
330 v9fs_put_idpool(nfid
, &v9ses
->fidpool
);
336 ret
= v9fs_fid_create(v9ses
, nfid
);
342 err
= v9fs_fid_insert(ret
, dentry
);
344 v9fs_fid_destroy(ret
);
351 v9fs_t_clunk(v9ses
, nfid
);
358 static struct inode
*
359 v9fs_inode_from_fid(struct v9fs_session_info
*v9ses
, u32 fid
,
360 struct super_block
*sb
)
364 struct v9fs_fcall
*fcall
;
367 err
= v9fs_t_stat(v9ses
, fid
, &fcall
);
369 PRINT_FCALL_ERROR("stat error", fcall
);
373 umode
= p9mode2unixmode(v9ses
, fcall
->params
.rstat
.stat
.mode
);
374 ret
= v9fs_get_inode(sb
, umode
);
381 v9fs_stat2inode(&fcall
->params
.rstat
.stat
, ret
, sb
);
394 * v9fs_remove - helper function to remove files and directories
395 * @dir: directory inode that is being deleted
396 * @file: dentry that is being deleted
397 * @rmdir: removing a directory
401 static int v9fs_remove(struct inode
*dir
, struct dentry
*file
, int rmdir
)
403 struct v9fs_fcall
*fcall
= NULL
;
404 struct super_block
*sb
= NULL
;
405 struct v9fs_session_info
*v9ses
= NULL
;
406 struct v9fs_fid
*v9fid
= NULL
;
407 struct inode
*file_inode
= NULL
;
411 dprintk(DEBUG_VFS
, "inode: %p dentry: %p rmdir: %d\n", dir
, file
,
414 file_inode
= file
->d_inode
;
415 sb
= file_inode
->i_sb
;
416 v9ses
= v9fs_inode2v9ses(file_inode
);
417 v9fid
= v9fs_fid_clone(file
);
419 return PTR_ERR(v9fid
);
423 dprintk(DEBUG_ERROR
, "inode #%lu, no fid!\n",
428 result
= v9fs_t_remove(v9ses
, fid
, &fcall
);
430 PRINT_FCALL_ERROR("remove fails", fcall
);
434 v9fs_put_idpool(fid
, &v9ses
->fidpool
);
435 v9fs_fid_destroy(v9fid
);
443 v9fs_open_created(struct inode
*inode
, struct file
*file
)
449 * v9fs_vfs_create - VFS hook to create files
450 * @inode: directory inode that is being deleted
451 * @dentry: dentry that is being deleted
452 * @mode: create permissions
453 * @nd: path information
458 v9fs_vfs_create(struct inode
*dir
, struct dentry
*dentry
, int mode
,
459 struct nameidata
*nd
)
462 u32 fid
, perm
, iounit
;
464 struct v9fs_session_info
*v9ses
;
465 struct v9fs_fid
*dfid
, *vfid
, *ffid
;
472 v9ses
= v9fs_inode2v9ses(dir
);
473 dfid
= v9fs_fid_clone(dentry
->d_parent
);
479 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
);
492 v9fs_fid_clunk(v9ses
, dfid
);
499 inode
= v9fs_inode_from_fid(v9ses
, vfid
->fid
, dir
->i_sb
);
501 err
= PTR_ERR(inode
);
507 dentry
->d_op
= &v9fs_cached_dentry_operations
;
509 dentry
->d_op
= &v9fs_dentry_operations
;
510 d_instantiate(dentry
, inode
);
512 if (nd
&& nd
->flags
& LOOKUP_OPEN
) {
513 ffid
= v9fs_fid_create(v9ses
, fid
);
517 filp
= lookup_instantiate_filp(nd
, dentry
, v9fs_open_created
);
519 v9fs_fid_destroy(ffid
);
520 return PTR_ERR(filp
);
524 ffid
->rdir_fcall
= NULL
;
526 ffid
->iounit
= iounit
;
528 filp
->private_data
= ffid
;
534 v9fs_fid_clunk(v9ses
, dfid
);
538 v9fs_fid_destroy(vfid
);
544 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
545 * @inode: inode that is being unlinked
546 * @dentry: dentry that is being unlinked
547 * @mode: mode for new directory
551 static int v9fs_vfs_mkdir(struct inode
*dir
, struct dentry
*dentry
, int mode
)
555 struct v9fs_session_info
*v9ses
;
556 struct v9fs_fid
*dfid
, *vfid
;
561 v9ses
= v9fs_inode2v9ses(dir
);
562 dfid
= v9fs_fid_clone(dentry
->d_parent
);
568 perm
= unixmode2p9mode(v9ses
, mode
| S_IFDIR
);
570 err
= v9fs_create(v9ses
, dfid
->fid
, (char *) dentry
->d_name
.name
,
571 perm
, V9FS_OREAD
, NULL
, &fid
, NULL
, NULL
);
574 dprintk(DEBUG_ERROR
, "create error %d\n", err
);
578 vfid
= v9fs_clone_walk(v9ses
, dfid
->fid
, dentry
);
585 v9fs_fid_clunk(v9ses
, dfid
);
586 inode
= v9fs_inode_from_fid(v9ses
, vfid
->fid
, dir
->i_sb
);
588 err
= PTR_ERR(inode
);
590 v9fs_fid_destroy(vfid
);
595 dentry
->d_op
= &v9fs_cached_dentry_operations
;
597 dentry
->d_op
= &v9fs_dentry_operations
;
598 d_instantiate(dentry
, inode
);
602 v9fs_fid_clunk(v9ses
, dfid
);
609 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
610 * @dir: inode that is being walked from
611 * @dentry: dentry that is being walked to?
612 * @nameidata: path data
616 static struct dentry
*v9fs_vfs_lookup(struct inode
*dir
, struct dentry
*dentry
,
617 struct nameidata
*nameidata
)
619 struct super_block
*sb
;
620 struct v9fs_session_info
*v9ses
;
621 struct v9fs_fid
*dirfid
;
622 struct v9fs_fid
*fid
;
624 struct v9fs_fcall
*fcall
= NULL
;
629 dprintk(DEBUG_VFS
, "dir: %p dentry: (%s) %p nameidata: %p\n",
630 dir
, dentry
->d_name
.name
, dentry
, nameidata
);
633 v9ses
= v9fs_inode2v9ses(dir
);
634 dirfid
= v9fs_fid_lookup(dentry
->d_parent
);
637 return ERR_PTR(PTR_ERR(dirfid
));
639 dirfidnum
= dirfid
->fid
;
641 newfid
= v9fs_get_idpool(&v9ses
->fidpool
);
643 eprintk(KERN_WARNING
, "newfid fails!\n");
648 result
= v9fs_t_walk(v9ses
, dirfidnum
, newfid
,
649 (char *)dentry
->d_name
.name
, &fcall
);
654 if (fcall
&& fcall
->id
== RWALK
)
655 v9fs_t_clunk(v9ses
, newfid
);
657 v9fs_put_idpool(newfid
, &v9ses
->fidpool
);
659 if (result
== -ENOENT
) {
662 "Return negative dentry %p count %d\n",
663 dentry
, atomic_read(&dentry
->d_count
));
667 dprintk(DEBUG_ERROR
, "walk error:%d\n", result
);
672 result
= v9fs_t_stat(v9ses
, newfid
, &fcall
);
674 dprintk(DEBUG_ERROR
, "stat error\n");
678 inode
= v9fs_get_inode(sb
, p9mode2unixmode(v9ses
,
679 fcall
->params
.rstat
.stat
.mode
));
681 if (IS_ERR(inode
) && (PTR_ERR(inode
) == -ENOSPC
)) {
682 eprintk(KERN_WARNING
, "inode alloc failes, returns %ld\n",
689 inode
->i_ino
= v9fs_qid2ino(&fcall
->params
.rstat
.stat
.qid
);
691 fid
= v9fs_fid_create(v9ses
, newfid
);
693 dprintk(DEBUG_ERROR
, "couldn't insert\n");
698 result
= v9fs_fid_insert(fid
, dentry
);
702 fid
->qid
= fcall
->params
.rstat
.stat
.qid
;
703 v9fs_stat2inode(&fcall
->params
.rstat
.stat
, inode
, inode
->i_sb
);
704 if((fid
->qid
.version
)&&(v9ses
->cache
))
705 dentry
->d_op
= &v9fs_cached_dentry_operations
;
707 dentry
->d_op
= &v9fs_dentry_operations
;
709 d_add(dentry
, inode
);
720 return ERR_PTR(result
);
724 * v9fs_vfs_unlink - VFS unlink hook to delete an inode
725 * @i: inode that is being unlinked
726 * @d: dentry that is being unlinked
730 static int v9fs_vfs_unlink(struct inode
*i
, struct dentry
*d
)
732 return v9fs_remove(i
, d
, 0);
736 * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
737 * @i: inode that is being unlinked
738 * @d: dentry that is being unlinked
742 static int v9fs_vfs_rmdir(struct inode
*i
, struct dentry
*d
)
744 return v9fs_remove(i
, d
, 1);
748 * v9fs_vfs_rename - VFS hook to rename an inode
749 * @old_dir: old dir inode
750 * @old_dentry: old dentry
751 * @new_dir: new dir inode
752 * @new_dentry: new dentry
757 v9fs_vfs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
758 struct inode
*new_dir
, struct dentry
*new_dentry
)
760 struct inode
*old_inode
= old_dentry
->d_inode
;
761 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(old_inode
);
762 struct v9fs_fid
*oldfid
= v9fs_fid_lookup(old_dentry
);
763 struct v9fs_fid
*olddirfid
;
764 struct v9fs_fid
*newdirfid
;
765 struct v9fs_wstat wstat
;
766 struct v9fs_fcall
*fcall
= NULL
;
768 int olddirfidnum
= -1;
769 int newdirfidnum
= -1;
772 dprintk(DEBUG_VFS
, "\n");
775 return PTR_ERR(oldfid
);
777 olddirfid
= v9fs_fid_clone(old_dentry
->d_parent
);
778 if(IS_ERR(olddirfid
)) {
779 retval
= PTR_ERR(olddirfid
);
783 newdirfid
= v9fs_fid_clone(new_dentry
->d_parent
);
784 if(IS_ERR(newdirfid
)) {
785 retval
= PTR_ERR(newdirfid
);
789 /* 9P can only handle file rename in the same directory */
790 if (memcmp(&olddirfid
->qid
, &newdirfid
->qid
, sizeof(newdirfid
->qid
))) {
791 dprintk(DEBUG_ERROR
, "old dir and new dir are different\n");
797 olddirfidnum
= olddirfid
->fid
;
798 newdirfidnum
= newdirfid
->fid
;
801 dprintk(DEBUG_ERROR
, "no fid for old file #%lu\n",
807 v9fs_blank_wstat(&wstat
);
808 wstat
.muid
= v9ses
->name
;
809 wstat
.name
= (char *) new_dentry
->d_name
.name
;
811 retval
= v9fs_t_wstat(v9ses
, fid
, &wstat
, &fcall
);
814 PRINT_FCALL_ERROR("wstat error", fcall
);
819 v9fs_fid_clunk(v9ses
, newdirfid
);
822 v9fs_fid_clunk(v9ses
, olddirfid
);
831 * v9fs_vfs_getattr - retrieve file metadata
832 * @mnt - mount information
833 * @dentry - file to get attributes on
834 * @stat - metadata structure to populate
839 v9fs_vfs_getattr(struct vfsmount
*mnt
, struct dentry
*dentry
,
842 struct v9fs_fcall
*fcall
= NULL
;
843 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
844 struct v9fs_fid
*fid
= v9fs_fid_clone(dentry
);
847 dprintk(DEBUG_VFS
, "dentry: %p\n", dentry
);
851 err
= v9fs_t_stat(v9ses
, fid
->fid
, &fcall
);
854 dprintk(DEBUG_ERROR
, "stat error\n");
856 v9fs_stat2inode(&fcall
->params
.rstat
.stat
, dentry
->d_inode
,
857 dentry
->d_inode
->i_sb
);
858 generic_fillattr(dentry
->d_inode
, stat
);
862 v9fs_fid_clunk(v9ses
, fid
);
867 * v9fs_vfs_setattr - set file metadata
868 * @dentry: file whose metadata to set
869 * @iattr: metadata assignment structure
873 static int v9fs_vfs_setattr(struct dentry
*dentry
, struct iattr
*iattr
)
875 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
876 struct v9fs_fid
*fid
= v9fs_fid_clone(dentry
);
877 struct v9fs_fcall
*fcall
= NULL
;
878 struct v9fs_wstat wstat
;
881 dprintk(DEBUG_VFS
, "\n");
885 v9fs_blank_wstat(&wstat
);
886 if (iattr
->ia_valid
& ATTR_MODE
)
887 wstat
.mode
= unixmode2p9mode(v9ses
, iattr
->ia_mode
);
889 if (iattr
->ia_valid
& ATTR_MTIME
)
890 wstat
.mtime
= iattr
->ia_mtime
.tv_sec
;
892 if (iattr
->ia_valid
& ATTR_ATIME
)
893 wstat
.atime
= iattr
->ia_atime
.tv_sec
;
895 if (iattr
->ia_valid
& ATTR_SIZE
)
896 wstat
.length
= iattr
->ia_size
;
898 if (v9ses
->extended
) {
899 if (iattr
->ia_valid
& ATTR_UID
)
900 wstat
.n_uid
= iattr
->ia_uid
;
902 if (iattr
->ia_valid
& ATTR_GID
)
903 wstat
.n_gid
= iattr
->ia_gid
;
906 res
= v9fs_t_wstat(v9ses
, fid
->fid
, &wstat
, &fcall
);
909 PRINT_FCALL_ERROR("wstat error", fcall
);
913 res
= inode_setattr(dentry
->d_inode
, iattr
);
915 v9fs_fid_clunk(v9ses
, fid
);
920 * v9fs_stat2inode - populate an inode structure with mistat info
921 * @stat: Plan 9 metadata (mistat) structure
922 * @inode: inode to populate
923 * @sb: superblock of filesystem
928 v9fs_stat2inode(struct v9fs_stat
*stat
, struct inode
*inode
,
929 struct super_block
*sb
)
933 struct v9fs_session_info
*v9ses
= sb
->s_fs_info
;
937 inode
->i_atime
.tv_sec
= stat
->atime
;
938 inode
->i_mtime
.tv_sec
= stat
->mtime
;
939 inode
->i_ctime
.tv_sec
= stat
->mtime
;
941 inode
->i_uid
= v9ses
->uid
;
942 inode
->i_gid
= v9ses
->gid
;
944 if (v9ses
->extended
) {
945 inode
->i_uid
= stat
->n_uid
;
946 inode
->i_gid
= stat
->n_gid
;
949 inode
->i_mode
= p9mode2unixmode(v9ses
, stat
->mode
);
950 if ((S_ISBLK(inode
->i_mode
)) || (S_ISCHR(inode
->i_mode
))) {
955 n
= stat
->extension
.len
;
956 if (n
> sizeof(ext
)-1)
958 memmove(ext
, stat
->extension
.str
, n
);
960 sscanf(ext
, "%c %u %u", &type
, &major
, &minor
);
963 inode
->i_mode
&= ~S_IFBLK
;
964 inode
->i_mode
|= S_IFCHR
;
969 dprintk(DEBUG_ERROR
, "Unknown special type %c (%.*s)\n",
970 type
, stat
->extension
.len
, stat
->extension
.str
);
972 inode
->i_rdev
= MKDEV(major
, minor
);
976 inode
->i_size
= stat
->length
;
979 (inode
->i_size
+ sb
->s_blocksize
- 1) >> sb
->s_blocksize_bits
;
983 * v9fs_qid2ino - convert qid into inode number
986 * BUG: potential for inode number collisions?
989 ino_t
v9fs_qid2ino(struct v9fs_qid
*qid
)
991 u64 path
= qid
->path
+ 2;
994 if (sizeof(ino_t
) == sizeof(path
))
995 memcpy(&i
, &path
, sizeof(ino_t
));
997 i
= (ino_t
) (path
^ (path
>> 32));
1003 * v9fs_readlink - read a symlink's location (internal version)
1004 * @dentry: dentry for symlink
1005 * @buffer: buffer to load symlink location into
1006 * @buflen: length of buffer
1010 static int v9fs_readlink(struct dentry
*dentry
, char *buffer
, int buflen
)
1012 int retval
= -EPERM
;
1014 struct v9fs_fcall
*fcall
= NULL
;
1015 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
1016 struct v9fs_fid
*fid
= v9fs_fid_clone(dentry
);
1019 return PTR_ERR(fid
);
1021 if (!v9ses
->extended
) {
1023 dprintk(DEBUG_ERROR
, "not extended\n");
1027 dprintk(DEBUG_VFS
, " %s\n", dentry
->d_name
.name
);
1028 retval
= v9fs_t_stat(v9ses
, fid
->fid
, &fcall
);
1031 dprintk(DEBUG_ERROR
, "stat error\n");
1040 if (!(fcall
->params
.rstat
.stat
.mode
& V9FS_DMSYMLINK
)) {
1045 /* copy extension buffer into buffer */
1046 if (fcall
->params
.rstat
.stat
.extension
.len
< buflen
)
1047 buflen
= fcall
->params
.rstat
.stat
.extension
.len
+ 1;
1049 memmove(buffer
, fcall
->params
.rstat
.stat
.extension
.str
, buflen
- 1);
1050 buffer
[buflen
-1] = 0;
1052 dprintk(DEBUG_ERROR
, "%s -> %.*s (%s)\n", dentry
->d_name
.name
, fcall
->params
.rstat
.stat
.extension
.len
,
1053 fcall
->params
.rstat
.stat
.extension
.str
, buffer
);
1060 v9fs_fid_clunk(v9ses
, fid
);
1066 * v9fs_vfs_readlink - read a symlink's location
1067 * @dentry: dentry for symlink
1068 * @buf: buffer to load symlink location into
1069 * @buflen: length of buffer
1073 static int v9fs_vfs_readlink(struct dentry
*dentry
, char __user
* buffer
,
1078 char *link
= __getname();
1080 if (unlikely(!link
))
1083 if (buflen
> PATH_MAX
)
1086 dprintk(DEBUG_VFS
, " dentry: %s (%p)\n", dentry
->d_iname
, dentry
);
1088 retval
= v9fs_readlink(dentry
, link
, buflen
);
1091 if ((ret
= copy_to_user(buffer
, link
, retval
)) != 0) {
1092 dprintk(DEBUG_ERROR
, "problem copying to user: %d\n",
1103 * v9fs_vfs_follow_link - follow a symlink path
1104 * @dentry: dentry for symlink
1109 static void *v9fs_vfs_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
1112 char *link
= __getname();
1114 dprintk(DEBUG_VFS
, "%s n", dentry
->d_name
.name
);
1117 link
= ERR_PTR(-ENOMEM
);
1119 len
= v9fs_readlink(dentry
, link
, PATH_MAX
);
1123 link
= ERR_PTR(len
);
1127 nd_set_link(nd
, link
);
1133 * v9fs_vfs_put_link - release a symlink path
1134 * @dentry: dentry for symlink
1139 static void v9fs_vfs_put_link(struct dentry
*dentry
, struct nameidata
*nd
, void *p
)
1141 char *s
= nd_get_link(nd
);
1143 dprintk(DEBUG_VFS
, " %s %s\n", dentry
->d_name
.name
, s
);
1148 static int v9fs_vfs_mkspecial(struct inode
*dir
, struct dentry
*dentry
,
1149 int mode
, const char *extension
)
1153 struct v9fs_session_info
*v9ses
;
1154 struct v9fs_fid
*dfid
, *vfid
= NULL
;
1155 struct inode
*inode
= NULL
;
1157 v9ses
= v9fs_inode2v9ses(dir
);
1158 if (!v9ses
->extended
) {
1159 dprintk(DEBUG_ERROR
, "not extended\n");
1163 dfid
= v9fs_fid_clone(dentry
->d_parent
);
1165 err
= PTR_ERR(dfid
);
1169 perm
= unixmode2p9mode(v9ses
, mode
);
1171 err
= v9fs_create(v9ses
, dfid
->fid
, (char *) dentry
->d_name
.name
,
1172 perm
, V9FS_OREAD
, (char *) extension
, &fid
, NULL
, NULL
);
1177 err
= v9fs_t_clunk(v9ses
, fid
);
1181 vfid
= v9fs_clone_walk(v9ses
, dfid
->fid
, dentry
);
1183 err
= PTR_ERR(vfid
);
1188 inode
= v9fs_inode_from_fid(v9ses
, vfid
->fid
, dir
->i_sb
);
1189 if (IS_ERR(inode
)) {
1190 err
= PTR_ERR(inode
);
1196 dentry
->d_op
= &v9fs_cached_dentry_operations
;
1198 dentry
->d_op
= &v9fs_dentry_operations
;
1199 d_instantiate(dentry
, inode
);
1203 v9fs_fid_destroy(vfid
);
1206 v9fs_fid_clunk(v9ses
, dfid
);
1214 * v9fs_vfs_symlink - helper function to create symlinks
1215 * @dir: directory inode containing symlink
1216 * @dentry: dentry for symlink
1217 * @symname: symlink data
1219 * See 9P2000.u RFC for more information
1224 v9fs_vfs_symlink(struct inode
*dir
, struct dentry
*dentry
, const char *symname
)
1226 dprintk(DEBUG_VFS
, " %lu,%s,%s\n", dir
->i_ino
, dentry
->d_name
.name
,
1229 return v9fs_vfs_mkspecial(dir
, dentry
, S_IFLNK
, symname
);
1233 * v9fs_vfs_link - create a hardlink
1234 * @old_dentry: dentry for file to link to
1235 * @dir: inode destination for new link
1236 * @dentry: dentry for link
1240 /* XXX - lots of code dup'd from symlink and creates,
1241 * figure out a better reuse strategy
1245 v9fs_vfs_link(struct dentry
*old_dentry
, struct inode
*dir
,
1246 struct dentry
*dentry
)
1249 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(dir
);
1250 struct v9fs_fid
*oldfid
;
1253 dprintk(DEBUG_VFS
, " %lu,%s,%s\n", dir
->i_ino
, dentry
->d_name
.name
,
1254 old_dentry
->d_name
.name
);
1256 oldfid
= v9fs_fid_clone(old_dentry
);
1258 return PTR_ERR(oldfid
);
1261 if (unlikely(!name
)) {
1266 sprintf(name
, "%d\n", oldfid
->fid
);
1267 retval
= v9fs_vfs_mkspecial(dir
, dentry
, V9FS_DMLINK
, name
);
1271 v9fs_fid_clunk(v9ses
, oldfid
);
1276 * v9fs_vfs_mknod - create a special file
1277 * @dir: inode destination for new link
1278 * @dentry: dentry for file
1279 * @mode: mode for creation
1280 * @dev_t: device associated with special file
1285 v9fs_vfs_mknod(struct inode
*dir
, struct dentry
*dentry
, int mode
, dev_t rdev
)
1290 dprintk(DEBUG_VFS
, " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir
->i_ino
,
1291 dentry
->d_name
.name
, mode
, MAJOR(rdev
), MINOR(rdev
));
1293 if (!new_valid_dev(rdev
))
1299 /* build extension */
1301 sprintf(name
, "b %u %u", MAJOR(rdev
), MINOR(rdev
));
1302 else if (S_ISCHR(mode
))
1303 sprintf(name
, "c %u %u", MAJOR(rdev
), MINOR(rdev
));
1304 else if (S_ISFIFO(mode
))
1311 retval
= v9fs_vfs_mkspecial(dir
, dentry
, mode
, name
);
1317 static const struct inode_operations v9fs_dir_inode_operations_ext
= {
1318 .create
= v9fs_vfs_create
,
1319 .lookup
= v9fs_vfs_lookup
,
1320 .symlink
= v9fs_vfs_symlink
,
1321 .link
= v9fs_vfs_link
,
1322 .unlink
= v9fs_vfs_unlink
,
1323 .mkdir
= v9fs_vfs_mkdir
,
1324 .rmdir
= v9fs_vfs_rmdir
,
1325 .mknod
= v9fs_vfs_mknod
,
1326 .rename
= v9fs_vfs_rename
,
1327 .readlink
= v9fs_vfs_readlink
,
1328 .getattr
= v9fs_vfs_getattr
,
1329 .setattr
= v9fs_vfs_setattr
,
1332 static const struct inode_operations v9fs_dir_inode_operations
= {
1333 .create
= v9fs_vfs_create
,
1334 .lookup
= v9fs_vfs_lookup
,
1335 .unlink
= v9fs_vfs_unlink
,
1336 .mkdir
= v9fs_vfs_mkdir
,
1337 .rmdir
= v9fs_vfs_rmdir
,
1338 .mknod
= v9fs_vfs_mknod
,
1339 .rename
= v9fs_vfs_rename
,
1340 .getattr
= v9fs_vfs_getattr
,
1341 .setattr
= v9fs_vfs_setattr
,
1344 static const struct inode_operations v9fs_file_inode_operations
= {
1345 .getattr
= v9fs_vfs_getattr
,
1346 .setattr
= v9fs_vfs_setattr
,
1349 static const struct inode_operations v9fs_symlink_inode_operations
= {
1350 .readlink
= v9fs_vfs_readlink
,
1351 .follow_link
= v9fs_vfs_follow_link
,
1352 .put_link
= v9fs_vfs_put_link
,
1353 .getattr
= v9fs_vfs_getattr
,
1354 .setattr
= v9fs_vfs_setattr
,