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>
36 #include <linux/sched.h>
37 #include <linux/slab.h>
38 #include <net/9p/9p.h>
39 #include <net/9p/client.h>
46 static const struct inode_operations v9fs_dir_inode_operations
;
47 static const struct inode_operations v9fs_dir_inode_operations_ext
;
48 static const struct inode_operations v9fs_file_inode_operations
;
49 static const struct inode_operations v9fs_symlink_inode_operations
;
52 * unixmode2p9mode - convert unix mode bits to plan 9
53 * @v9ses: v9fs session information
54 * @mode: mode to convert
58 static int unixmode2p9mode(struct v9fs_session_info
*v9ses
, int mode
)
64 if (v9fs_proto_dotu(v9ses
)) {
67 if (v9ses
->nodev
== 0) {
71 res
|= P9_DMNAMEDPIPE
;
78 if ((mode
& S_ISUID
) == S_ISUID
)
80 if ((mode
& S_ISGID
) == S_ISGID
)
82 if ((mode
& S_ISVTX
) == S_ISVTX
)
84 if ((mode
& P9_DMLINK
))
92 * p9mode2unixmode- convert plan9 mode bits to unix mode bits
93 * @v9ses: v9fs session information
94 * @mode: mode to convert
98 static int p9mode2unixmode(struct v9fs_session_info
*v9ses
, int mode
)
104 if ((mode
& P9_DMDIR
) == P9_DMDIR
)
106 else if ((mode
& P9_DMSYMLINK
) && (v9fs_proto_dotu(v9ses
)))
108 else if ((mode
& P9_DMSOCKET
) && (v9fs_proto_dotu(v9ses
))
109 && (v9ses
->nodev
== 0))
111 else if ((mode
& P9_DMNAMEDPIPE
) && (v9fs_proto_dotu(v9ses
))
112 && (v9ses
->nodev
== 0))
114 else if ((mode
& P9_DMDEVICE
) && (v9fs_proto_dotu(v9ses
))
115 && (v9ses
->nodev
== 0))
120 if (v9fs_proto_dotu(v9ses
)) {
121 if ((mode
& P9_DMSETUID
) == P9_DMSETUID
)
124 if ((mode
& P9_DMSETGID
) == P9_DMSETGID
)
127 if ((mode
& P9_DMSETVTX
) == P9_DMSETVTX
)
135 * v9fs_uflags2omode- convert posix open flags to plan 9 mode bits
136 * @uflags: flags to convert
137 * @extended: if .u extensions are active
140 int v9fs_uflags2omode(int uflags
, int extended
)
160 if (uflags
& O_TRUNC
)
167 if (uflags
& O_APPEND
)
175 * v9fs_blank_wstat - helper function to setup a 9P stat structure
176 * @wstat: structure to initialize
181 v9fs_blank_wstat(struct p9_wstat
*wstat
)
185 wstat
->qid
.type
= ~0;
186 wstat
->qid
.version
= ~0;
187 *((long long *)&wstat
->qid
.path
) = ~0;
199 wstat
->extension
= NULL
;
202 #ifdef CONFIG_9P_FSCACHE
204 * v9fs_alloc_inode - helper function to allocate an inode
205 * This callback is executed before setting up the inode so that we
206 * can associate a vcookie with each inode.
210 struct inode
*v9fs_alloc_inode(struct super_block
*sb
)
212 struct v9fs_cookie
*vcookie
;
213 vcookie
= (struct v9fs_cookie
*)kmem_cache_alloc(vcookie_cache
,
218 vcookie
->fscache
= NULL
;
220 spin_lock_init(&vcookie
->lock
);
221 return &vcookie
->inode
;
225 * v9fs_destroy_inode - destroy an inode
229 void v9fs_destroy_inode(struct inode
*inode
)
231 kmem_cache_free(vcookie_cache
, v9fs_inode2cookie(inode
));
236 * v9fs_get_inode - helper function to setup an inode
238 * @mode: mode to setup inode with
242 struct inode
*v9fs_get_inode(struct super_block
*sb
, int mode
)
246 struct v9fs_session_info
*v9ses
= sb
->s_fs_info
;
248 P9_DPRINTK(P9_DEBUG_VFS
, "super block: %p mode: %o\n", sb
, mode
);
250 inode
= new_inode(sb
);
252 P9_EPRINTK(KERN_WARNING
, "Problem allocating inode\n");
253 return ERR_PTR(-ENOMEM
);
256 inode
->i_mode
= mode
;
257 inode
->i_uid
= current_fsuid();
258 inode
->i_gid
= current_fsgid();
261 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
262 inode
->i_mapping
->a_ops
= &v9fs_addr_operations
;
264 switch (mode
& S_IFMT
) {
269 if (!v9fs_proto_dotu(v9ses
)) {
270 P9_DPRINTK(P9_DEBUG_ERROR
,
271 "special files without extended mode\n");
275 init_special_inode(inode
, inode
->i_mode
, inode
->i_rdev
);
278 inode
->i_op
= &v9fs_file_inode_operations
;
279 inode
->i_fop
= &v9fs_file_operations
;
282 if (!v9fs_proto_dotu(v9ses
)) {
283 P9_DPRINTK(P9_DEBUG_ERROR
,
284 "extended modes used w/o 9P2000.u\n");
288 inode
->i_op
= &v9fs_symlink_inode_operations
;
292 if (v9fs_proto_dotu(v9ses
))
293 inode
->i_op
= &v9fs_dir_inode_operations_ext
;
295 inode
->i_op
= &v9fs_dir_inode_operations
;
296 inode
->i_fop
= &v9fs_dir_operations
;
299 P9_DPRINTK(P9_DEBUG_ERROR
, "BAD mode 0x%x S_IFMT 0x%x\n",
300 mode
, mode
& S_IFMT
);
313 static struct v9fs_fid*
314 v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry)
318 struct v9fs_fid *ret;
319 struct v9fs_fcall *fcall;
321 nfid = v9fs_get_idpool(&v9ses->fidpool);
323 eprintk(KERN_WARNING, "no free fids available\n");
324 return ERR_PTR(-ENOSPC);
327 err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name,
331 if (fcall && fcall->id == RWALK)
334 PRINT_FCALL_ERROR("walk error", fcall);
335 v9fs_put_idpool(nfid, &v9ses->fidpool);
341 ret = v9fs_fid_create(v9ses, nfid);
347 err = v9fs_fid_insert(ret, dentry);
349 v9fs_fid_destroy(ret);
356 v9fs_t_clunk(v9ses, nfid);
366 * v9fs_clear_inode - release an inode
367 * @inode: inode to release
370 void v9fs_clear_inode(struct inode
*inode
)
372 filemap_fdatawrite(inode
->i_mapping
);
374 #ifdef CONFIG_9P_FSCACHE
375 v9fs_cache_inode_put_cookie(inode
);
380 * v9fs_inode_from_fid - populate an inode by issuing a attribute request
381 * @v9ses: session information
382 * @fid: fid to issue attribute request for
383 * @sb: superblock on which to create inode
387 static struct inode
*
388 v9fs_inode_from_fid(struct v9fs_session_info
*v9ses
, struct p9_fid
*fid
,
389 struct super_block
*sb
)
396 st
= p9_client_stat(fid
);
400 umode
= p9mode2unixmode(v9ses
, st
->mode
);
401 ret
= v9fs_get_inode(sb
, umode
);
407 v9fs_stat2inode(st
, ret
, sb
);
408 ret
->i_ino
= v9fs_qid2ino(&st
->qid
);
410 #ifdef CONFIG_9P_FSCACHE
411 v9fs_vcookie_set_qid(ret
, &st
->qid
);
412 v9fs_cache_inode_get_cookie(ret
);
426 * v9fs_remove - helper function to remove files and directories
427 * @dir: directory inode that is being deleted
428 * @file: dentry that is being deleted
429 * @rmdir: removing a directory
433 static int v9fs_remove(struct inode
*dir
, struct dentry
*file
, int rmdir
)
436 struct inode
*file_inode
;
437 struct v9fs_session_info
*v9ses
;
438 struct p9_fid
*v9fid
;
440 P9_DPRINTK(P9_DEBUG_VFS
, "inode: %p dentry: %p rmdir: %d\n", dir
, file
,
443 file_inode
= file
->d_inode
;
444 v9ses
= v9fs_inode2v9ses(file_inode
);
445 v9fid
= v9fs_fid_clone(file
);
447 return PTR_ERR(v9fid
);
449 retval
= p9_client_remove(v9fid
);
451 drop_nlink(file_inode
);
456 v9fs_open_created(struct inode
*inode
, struct file
*file
)
463 * v9fs_create - Create a file
464 * @v9ses: session information
465 * @dir: directory that dentry is being created in
466 * @dentry: dentry that is being created
467 * @extension: 9p2000.u extension string to support devices, etc.
468 * @perm: create permissions
472 static struct p9_fid
*
473 v9fs_create(struct v9fs_session_info
*v9ses
, struct inode
*dir
,
474 struct dentry
*dentry
, char *extension
, u32 perm
, u8 mode
)
478 struct p9_fid
*dfid
, *ofid
, *fid
;
481 P9_DPRINTK(P9_DEBUG_VFS
, "name %s\n", dentry
->d_name
.name
);
486 name
= (char *) dentry
->d_name
.name
;
487 dfid
= v9fs_fid_clone(dentry
->d_parent
);
490 P9_DPRINTK(P9_DEBUG_VFS
, "fid clone failed %d\n", err
);
495 /* clone a fid to use for creation */
496 ofid
= p9_client_walk(dfid
, 0, NULL
, 1);
499 P9_DPRINTK(P9_DEBUG_VFS
, "p9_client_walk failed %d\n", err
);
504 err
= p9_client_fcreate(ofid
, name
, perm
, mode
, extension
);
506 P9_DPRINTK(P9_DEBUG_VFS
, "p9_client_fcreate failed %d\n", err
);
510 /* now walk from the parent so we can get unopened fid */
511 fid
= p9_client_walk(dfid
, 1, &name
, 0);
514 P9_DPRINTK(P9_DEBUG_VFS
, "p9_client_walk failed %d\n", err
);
520 /* instantiate inode and assign the unopened fid to the dentry */
521 inode
= v9fs_inode_from_fid(v9ses
, fid
, dir
->i_sb
);
523 err
= PTR_ERR(inode
);
524 P9_DPRINTK(P9_DEBUG_VFS
, "inode creation failed %d\n", err
);
529 dentry
->d_op
= &v9fs_cached_dentry_operations
;
531 dentry
->d_op
= &v9fs_dentry_operations
;
533 d_instantiate(dentry
, inode
);
534 err
= v9fs_fid_add(dentry
, fid
);
542 p9_client_clunk(dfid
);
545 p9_client_clunk(ofid
);
548 p9_client_clunk(fid
);
554 * v9fs_vfs_create - VFS hook to create files
555 * @dir: directory inode that is being created
556 * @dentry: dentry that is being deleted
557 * @mode: create permissions
558 * @nd: path information
563 v9fs_vfs_create(struct inode
*dir
, struct dentry
*dentry
, int mode
,
564 struct nameidata
*nd
)
569 struct v9fs_session_info
*v9ses
;
575 v9ses
= v9fs_inode2v9ses(dir
);
576 perm
= unixmode2p9mode(v9ses
, mode
);
577 if (nd
&& nd
->flags
& LOOKUP_OPEN
)
578 flags
= nd
->intent
.open
.flags
- 1;
582 fid
= v9fs_create(v9ses
, dir
, dentry
, NULL
, perm
,
583 v9fs_uflags2omode(flags
,
584 v9fs_proto_dotu(v9ses
)));
591 /* if we are opening a file, assign the open fid to the file */
592 if (nd
&& nd
->flags
& LOOKUP_OPEN
) {
593 filp
= lookup_instantiate_filp(nd
, dentry
, v9fs_open_created
);
599 filp
->private_data
= fid
;
601 p9_client_clunk(fid
);
607 p9_client_clunk(fid
);
613 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
614 * @dir: inode that is being unlinked
615 * @dentry: dentry that is being unlinked
616 * @mode: mode for new directory
620 static int v9fs_vfs_mkdir(struct inode
*dir
, struct dentry
*dentry
, int mode
)
624 struct v9fs_session_info
*v9ses
;
627 P9_DPRINTK(P9_DEBUG_VFS
, "name %s\n", dentry
->d_name
.name
);
629 v9ses
= v9fs_inode2v9ses(dir
);
630 perm
= unixmode2p9mode(v9ses
, mode
| S_IFDIR
);
631 fid
= v9fs_create(v9ses
, dir
, dentry
, NULL
, perm
, P9_OREAD
);
638 p9_client_clunk(fid
);
644 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
645 * @dir: inode that is being walked from
646 * @dentry: dentry that is being walked to?
647 * @nameidata: path data
651 static struct dentry
*v9fs_vfs_lookup(struct inode
*dir
, struct dentry
*dentry
,
652 struct nameidata
*nameidata
)
654 struct super_block
*sb
;
655 struct v9fs_session_info
*v9ses
;
656 struct p9_fid
*dfid
, *fid
;
661 P9_DPRINTK(P9_DEBUG_VFS
, "dir: %p dentry: (%s) %p nameidata: %p\n",
662 dir
, dentry
->d_name
.name
, dentry
, nameidata
);
664 if (dentry
->d_name
.len
> NAME_MAX
)
665 return ERR_PTR(-ENAMETOOLONG
);
668 v9ses
= v9fs_inode2v9ses(dir
);
669 dfid
= v9fs_fid_lookup(dentry
->d_parent
);
671 return ERR_CAST(dfid
);
673 name
= (char *) dentry
->d_name
.name
;
674 fid
= p9_client_walk(dfid
, 1, &name
, 1);
676 result
= PTR_ERR(fid
);
677 if (result
== -ENOENT
) {
682 return ERR_PTR(result
);
685 inode
= v9fs_inode_from_fid(v9ses
, fid
, dir
->i_sb
);
687 result
= PTR_ERR(inode
);
692 result
= v9fs_fid_add(dentry
, fid
);
696 if ((fid
->qid
.version
) && (v9ses
->cache
))
697 dentry
->d_op
= &v9fs_cached_dentry_operations
;
699 dentry
->d_op
= &v9fs_dentry_operations
;
701 d_add(dentry
, inode
);
705 p9_client_clunk(fid
);
707 return ERR_PTR(result
);
711 * v9fs_vfs_unlink - VFS unlink hook to delete an inode
712 * @i: inode that is being unlinked
713 * @d: dentry that is being unlinked
717 static int v9fs_vfs_unlink(struct inode
*i
, struct dentry
*d
)
719 return v9fs_remove(i
, d
, 0);
723 * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
724 * @i: inode that is being unlinked
725 * @d: dentry that is being unlinked
729 static int v9fs_vfs_rmdir(struct inode
*i
, struct dentry
*d
)
731 return v9fs_remove(i
, d
, 1);
735 * v9fs_vfs_rename - VFS hook to rename an inode
736 * @old_dir: old dir inode
737 * @old_dentry: old dentry
738 * @new_dir: new dir inode
739 * @new_dentry: new dentry
744 v9fs_vfs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
745 struct inode
*new_dir
, struct dentry
*new_dentry
)
747 struct inode
*old_inode
;
748 struct v9fs_session_info
*v9ses
;
749 struct p9_fid
*oldfid
;
750 struct p9_fid
*olddirfid
;
751 struct p9_fid
*newdirfid
;
752 struct p9_wstat wstat
;
755 P9_DPRINTK(P9_DEBUG_VFS
, "\n");
757 old_inode
= old_dentry
->d_inode
;
758 v9ses
= v9fs_inode2v9ses(old_inode
);
759 oldfid
= v9fs_fid_lookup(old_dentry
);
761 return PTR_ERR(oldfid
);
763 olddirfid
= v9fs_fid_clone(old_dentry
->d_parent
);
764 if (IS_ERR(olddirfid
)) {
765 retval
= PTR_ERR(olddirfid
);
769 newdirfid
= v9fs_fid_clone(new_dentry
->d_parent
);
770 if (IS_ERR(newdirfid
)) {
771 retval
= PTR_ERR(newdirfid
);
775 /* 9P can only handle file rename in the same directory */
776 if (memcmp(&olddirfid
->qid
, &newdirfid
->qid
, sizeof(newdirfid
->qid
))) {
777 P9_DPRINTK(P9_DEBUG_ERROR
,
778 "old dir and new dir are different\n");
783 v9fs_blank_wstat(&wstat
);
784 wstat
.muid
= v9ses
->uname
;
785 wstat
.name
= (char *) new_dentry
->d_name
.name
;
786 retval
= p9_client_wstat(oldfid
, &wstat
);
789 p9_client_clunk(newdirfid
);
792 p9_client_clunk(olddirfid
);
799 * v9fs_vfs_getattr - retrieve file metadata
800 * @mnt: mount information
801 * @dentry: file to get attributes on
802 * @stat: metadata structure to populate
807 v9fs_vfs_getattr(struct vfsmount
*mnt
, struct dentry
*dentry
,
811 struct v9fs_session_info
*v9ses
;
815 P9_DPRINTK(P9_DEBUG_VFS
, "dentry: %p\n", dentry
);
817 v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
818 if (v9ses
->cache
== CACHE_LOOSE
|| v9ses
->cache
== CACHE_FSCACHE
)
819 return simple_getattr(mnt
, dentry
, stat
);
821 fid
= v9fs_fid_lookup(dentry
);
825 st
= p9_client_stat(fid
);
829 v9fs_stat2inode(st
, dentry
->d_inode
, dentry
->d_inode
->i_sb
);
830 generic_fillattr(dentry
->d_inode
, stat
);
837 * v9fs_vfs_setattr - set file metadata
838 * @dentry: file whose metadata to set
839 * @iattr: metadata assignment structure
843 static int v9fs_vfs_setattr(struct dentry
*dentry
, struct iattr
*iattr
)
846 struct v9fs_session_info
*v9ses
;
848 struct p9_wstat wstat
;
850 P9_DPRINTK(P9_DEBUG_VFS
, "\n");
852 v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
853 fid
= v9fs_fid_lookup(dentry
);
857 v9fs_blank_wstat(&wstat
);
858 if (iattr
->ia_valid
& ATTR_MODE
)
859 wstat
.mode
= unixmode2p9mode(v9ses
, iattr
->ia_mode
);
861 if (iattr
->ia_valid
& ATTR_MTIME
)
862 wstat
.mtime
= iattr
->ia_mtime
.tv_sec
;
864 if (iattr
->ia_valid
& ATTR_ATIME
)
865 wstat
.atime
= iattr
->ia_atime
.tv_sec
;
867 if (iattr
->ia_valid
& ATTR_SIZE
)
868 wstat
.length
= iattr
->ia_size
;
870 if (v9fs_proto_dotu(v9ses
)) {
871 if (iattr
->ia_valid
& ATTR_UID
)
872 wstat
.n_uid
= iattr
->ia_uid
;
874 if (iattr
->ia_valid
& ATTR_GID
)
875 wstat
.n_gid
= iattr
->ia_gid
;
878 retval
= p9_client_wstat(fid
, &wstat
);
880 retval
= inode_setattr(dentry
->d_inode
, iattr
);
886 * v9fs_stat2inode - populate an inode structure with mistat info
887 * @stat: Plan 9 metadata (mistat) structure
888 * @inode: inode to populate
889 * @sb: superblock of filesystem
894 v9fs_stat2inode(struct p9_wstat
*stat
, struct inode
*inode
,
895 struct super_block
*sb
)
899 unsigned int i_nlink
;
900 struct v9fs_session_info
*v9ses
= sb
->s_fs_info
;
904 inode
->i_atime
.tv_sec
= stat
->atime
;
905 inode
->i_mtime
.tv_sec
= stat
->mtime
;
906 inode
->i_ctime
.tv_sec
= stat
->mtime
;
908 inode
->i_uid
= v9ses
->dfltuid
;
909 inode
->i_gid
= v9ses
->dfltgid
;
911 if (v9fs_proto_dotu(v9ses
)) {
912 inode
->i_uid
= stat
->n_uid
;
913 inode
->i_gid
= stat
->n_gid
;
915 if ((S_ISREG(inode
->i_mode
)) || (S_ISDIR(inode
->i_mode
))) {
916 if (v9fs_proto_dotu(v9ses
) && (stat
->extension
[0] != '\0')) {
918 * Hadlink support got added later to
919 * to the .u extension. So there can be
920 * server out there that doesn't support
921 * this even with .u extension. So check
922 * for non NULL stat->extension
924 strncpy(ext
, stat
->extension
, sizeof(ext
));
925 /* HARDLINKCOUNT %u */
926 sscanf(ext
, "%13s %u", tag_name
, &i_nlink
);
927 if (!strncmp(tag_name
, "HARDLINKCOUNT", 13))
928 inode
->i_nlink
= i_nlink
;
931 inode
->i_mode
= p9mode2unixmode(v9ses
, stat
->mode
);
932 if ((S_ISBLK(inode
->i_mode
)) || (S_ISCHR(inode
->i_mode
))) {
937 strncpy(ext
, stat
->extension
, sizeof(ext
));
938 sscanf(ext
, "%c %u %u", &type
, &major
, &minor
);
941 inode
->i_mode
&= ~S_IFBLK
;
942 inode
->i_mode
|= S_IFCHR
;
947 P9_DPRINTK(P9_DEBUG_ERROR
,
948 "Unknown special type %c %s\n", type
,
951 inode
->i_rdev
= MKDEV(major
, minor
);
952 init_special_inode(inode
, inode
->i_mode
, inode
->i_rdev
);
956 i_size_write(inode
, stat
->length
);
958 /* not real number of blocks, but 512 byte ones ... */
959 inode
->i_blocks
= (i_size_read(inode
) + 512 - 1) >> 9;
963 * v9fs_qid2ino - convert qid into inode number
966 * BUG: potential for inode number collisions?
969 ino_t
v9fs_qid2ino(struct p9_qid
*qid
)
971 u64 path
= qid
->path
+ 2;
974 if (sizeof(ino_t
) == sizeof(path
))
975 memcpy(&i
, &path
, sizeof(ino_t
));
977 i
= (ino_t
) (path
^ (path
>> 32));
983 * v9fs_readlink - read a symlink's location (internal version)
984 * @dentry: dentry for symlink
985 * @buffer: buffer to load symlink location into
986 * @buflen: length of buffer
990 static int v9fs_readlink(struct dentry
*dentry
, char *buffer
, int buflen
)
994 struct v9fs_session_info
*v9ses
;
998 P9_DPRINTK(P9_DEBUG_VFS
, " %s\n", dentry
->d_name
.name
);
1000 v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
1001 fid
= v9fs_fid_lookup(dentry
);
1003 return PTR_ERR(fid
);
1005 if (!v9fs_proto_dotu(v9ses
))
1008 st
= p9_client_stat(fid
);
1012 if (!(st
->mode
& P9_DMSYMLINK
)) {
1017 /* copy extension buffer into buffer */
1018 strncpy(buffer
, st
->extension
, buflen
);
1020 P9_DPRINTK(P9_DEBUG_VFS
,
1021 "%s -> %s (%s)\n", dentry
->d_name
.name
, st
->extension
, buffer
);
1023 retval
= strnlen(buffer
, buflen
);
1030 * v9fs_vfs_follow_link - follow a symlink path
1031 * @dentry: dentry for symlink
1036 static void *v9fs_vfs_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
1039 char *link
= __getname();
1041 P9_DPRINTK(P9_DEBUG_VFS
, "%s n", dentry
->d_name
.name
);
1044 link
= ERR_PTR(-ENOMEM
);
1046 len
= v9fs_readlink(dentry
, link
, PATH_MAX
);
1050 link
= ERR_PTR(len
);
1052 link
[min(len
, PATH_MAX
-1)] = 0;
1054 nd_set_link(nd
, link
);
1060 * v9fs_vfs_put_link - release a symlink path
1061 * @dentry: dentry for symlink
1068 v9fs_vfs_put_link(struct dentry
*dentry
, struct nameidata
*nd
, void *p
)
1070 char *s
= nd_get_link(nd
);
1072 P9_DPRINTK(P9_DEBUG_VFS
, " %s %s\n", dentry
->d_name
.name
,
1073 IS_ERR(s
) ? "<error>" : s
);
1079 * v9fs_vfs_mkspecial - create a special file
1080 * @dir: inode to create special file in
1081 * @dentry: dentry to create
1082 * @mode: mode to create special file
1083 * @extension: 9p2000.u format extension string representing special file
1087 static int v9fs_vfs_mkspecial(struct inode
*dir
, struct dentry
*dentry
,
1088 int mode
, const char *extension
)
1091 struct v9fs_session_info
*v9ses
;
1094 v9ses
= v9fs_inode2v9ses(dir
);
1095 if (!v9fs_proto_dotu(v9ses
)) {
1096 P9_DPRINTK(P9_DEBUG_ERROR
, "not extended\n");
1100 perm
= unixmode2p9mode(v9ses
, mode
);
1101 fid
= v9fs_create(v9ses
, dir
, dentry
, (char *) extension
, perm
,
1104 return PTR_ERR(fid
);
1106 p9_client_clunk(fid
);
1111 * v9fs_vfs_symlink - helper function to create symlinks
1112 * @dir: directory inode containing symlink
1113 * @dentry: dentry for symlink
1114 * @symname: symlink data
1116 * See Also: 9P2000.u RFC for more information
1121 v9fs_vfs_symlink(struct inode
*dir
, struct dentry
*dentry
, const char *symname
)
1123 P9_DPRINTK(P9_DEBUG_VFS
, " %lu,%s,%s\n", dir
->i_ino
,
1124 dentry
->d_name
.name
, symname
);
1126 return v9fs_vfs_mkspecial(dir
, dentry
, S_IFLNK
, symname
);
1130 * v9fs_vfs_link - create a hardlink
1131 * @old_dentry: dentry for file to link to
1132 * @dir: inode destination for new link
1133 * @dentry: dentry for link
1138 v9fs_vfs_link(struct dentry
*old_dentry
, struct inode
*dir
,
1139 struct dentry
*dentry
)
1142 struct p9_fid
*oldfid
;
1145 P9_DPRINTK(P9_DEBUG_VFS
,
1146 " %lu,%s,%s\n", dir
->i_ino
, dentry
->d_name
.name
,
1147 old_dentry
->d_name
.name
);
1149 oldfid
= v9fs_fid_clone(old_dentry
);
1151 return PTR_ERR(oldfid
);
1154 if (unlikely(!name
)) {
1159 sprintf(name
, "%d\n", oldfid
->fid
);
1160 retval
= v9fs_vfs_mkspecial(dir
, dentry
, P9_DMLINK
, name
);
1164 p9_client_clunk(oldfid
);
1169 * v9fs_vfs_mknod - create a special file
1170 * @dir: inode destination for new link
1171 * @dentry: dentry for file
1172 * @mode: mode for creation
1173 * @rdev: device associated with special file
1178 v9fs_vfs_mknod(struct inode
*dir
, struct dentry
*dentry
, int mode
, dev_t rdev
)
1183 P9_DPRINTK(P9_DEBUG_VFS
,
1184 " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir
->i_ino
,
1185 dentry
->d_name
.name
, mode
, MAJOR(rdev
), MINOR(rdev
));
1187 if (!new_valid_dev(rdev
))
1193 /* build extension */
1195 sprintf(name
, "b %u %u", MAJOR(rdev
), MINOR(rdev
));
1196 else if (S_ISCHR(mode
))
1197 sprintf(name
, "c %u %u", MAJOR(rdev
), MINOR(rdev
));
1198 else if (S_ISFIFO(mode
))
1205 retval
= v9fs_vfs_mkspecial(dir
, dentry
, mode
, name
);
1211 static const struct inode_operations v9fs_dir_inode_operations_ext
= {
1212 .create
= v9fs_vfs_create
,
1213 .lookup
= v9fs_vfs_lookup
,
1214 .symlink
= v9fs_vfs_symlink
,
1215 .link
= v9fs_vfs_link
,
1216 .unlink
= v9fs_vfs_unlink
,
1217 .mkdir
= v9fs_vfs_mkdir
,
1218 .rmdir
= v9fs_vfs_rmdir
,
1219 .mknod
= v9fs_vfs_mknod
,
1220 .rename
= v9fs_vfs_rename
,
1221 .getattr
= v9fs_vfs_getattr
,
1222 .setattr
= v9fs_vfs_setattr
,
1225 static const struct inode_operations v9fs_dir_inode_operations
= {
1226 .create
= v9fs_vfs_create
,
1227 .lookup
= v9fs_vfs_lookup
,
1228 .unlink
= v9fs_vfs_unlink
,
1229 .mkdir
= v9fs_vfs_mkdir
,
1230 .rmdir
= v9fs_vfs_rmdir
,
1231 .mknod
= v9fs_vfs_mknod
,
1232 .rename
= v9fs_vfs_rename
,
1233 .getattr
= v9fs_vfs_getattr
,
1234 .setattr
= v9fs_vfs_setattr
,
1237 static const struct inode_operations v9fs_file_inode_operations
= {
1238 .getattr
= v9fs_vfs_getattr
,
1239 .setattr
= v9fs_vfs_setattr
,
1242 static const struct inode_operations v9fs_symlink_inode_operations
= {
1243 .readlink
= generic_readlink
,
1244 .follow_link
= v9fs_vfs_follow_link
,
1245 .put_link
= v9fs_vfs_put_link
,
1246 .getattr
= v9fs_vfs_getattr
,
1247 .setattr
= v9fs_vfs_setattr
,