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 <net/9p/9p.h>
38 #include <net/9p/client.h>
45 static const struct inode_operations v9fs_dir_inode_operations
;
46 static const struct inode_operations v9fs_dir_inode_operations_ext
;
47 static const struct inode_operations v9fs_file_inode_operations
;
48 static const struct inode_operations v9fs_symlink_inode_operations
;
51 * unixmode2p9mode - convert unix mode bits to plan 9
52 * @v9ses: v9fs session information
53 * @mode: mode to convert
57 static int unixmode2p9mode(struct v9fs_session_info
*v9ses
, int mode
)
63 if (v9fs_extended(v9ses
)) {
66 if (v9ses
->nodev
== 0) {
70 res
|= P9_DMNAMEDPIPE
;
77 if ((mode
& S_ISUID
) == S_ISUID
)
79 if ((mode
& S_ISGID
) == S_ISGID
)
81 if ((mode
& S_ISVTX
) == S_ISVTX
)
83 if ((mode
& P9_DMLINK
))
91 * p9mode2unixmode- convert plan9 mode bits to unix mode bits
92 * @v9ses: v9fs session information
93 * @mode: mode to convert
97 static int p9mode2unixmode(struct v9fs_session_info
*v9ses
, int mode
)
103 if ((mode
& P9_DMDIR
) == P9_DMDIR
)
105 else if ((mode
& P9_DMSYMLINK
) && (v9fs_extended(v9ses
)))
107 else if ((mode
& P9_DMSOCKET
) && (v9fs_extended(v9ses
))
108 && (v9ses
->nodev
== 0))
110 else if ((mode
& P9_DMNAMEDPIPE
) && (v9fs_extended(v9ses
))
111 && (v9ses
->nodev
== 0))
113 else if ((mode
& P9_DMDEVICE
) && (v9fs_extended(v9ses
))
114 && (v9ses
->nodev
== 0))
119 if (v9fs_extended(v9ses
)) {
120 if ((mode
& P9_DMSETUID
) == P9_DMSETUID
)
123 if ((mode
& P9_DMSETGID
) == P9_DMSETGID
)
126 if ((mode
& P9_DMSETVTX
) == P9_DMSETVTX
)
134 * v9fs_uflags2omode- convert posix open flags to plan 9 mode bits
135 * @uflags: flags to convert
136 * @extended: if .u extensions are active
139 int v9fs_uflags2omode(int uflags
, int extended
)
159 if (uflags
& O_TRUNC
)
166 if (uflags
& O_APPEND
)
174 * v9fs_blank_wstat - helper function to setup a 9P stat structure
175 * @wstat: structure to initialize
180 v9fs_blank_wstat(struct p9_wstat
*wstat
)
184 wstat
->qid
.type
= ~0;
185 wstat
->qid
.version
= ~0;
186 *((long long *)&wstat
->qid
.path
) = ~0;
198 wstat
->extension
= NULL
;
201 #ifdef CONFIG_9P_FSCACHE
203 * v9fs_alloc_inode - helper function to allocate an inode
204 * This callback is executed before setting up the inode so that we
205 * can associate a vcookie with each inode.
209 struct inode
*v9fs_alloc_inode(struct super_block
*sb
)
211 struct v9fs_cookie
*vcookie
;
212 vcookie
= (struct v9fs_cookie
*)kmem_cache_alloc(vcookie_cache
,
217 vcookie
->fscache
= NULL
;
219 spin_lock_init(&vcookie
->lock
);
220 return &vcookie
->inode
;
224 * v9fs_destroy_inode - destroy an inode
228 void v9fs_destroy_inode(struct inode
*inode
)
230 kmem_cache_free(vcookie_cache
, v9fs_inode2cookie(inode
));
235 * v9fs_get_inode - helper function to setup an inode
237 * @mode: mode to setup inode with
241 struct inode
*v9fs_get_inode(struct super_block
*sb
, int mode
)
245 struct v9fs_session_info
*v9ses
= sb
->s_fs_info
;
247 P9_DPRINTK(P9_DEBUG_VFS
, "super block: %p mode: %o\n", sb
, mode
);
249 inode
= new_inode(sb
);
251 P9_EPRINTK(KERN_WARNING
, "Problem allocating inode\n");
252 return ERR_PTR(-ENOMEM
);
255 inode
->i_mode
= mode
;
256 inode
->i_uid
= current_fsuid();
257 inode
->i_gid
= current_fsgid();
260 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
261 inode
->i_mapping
->a_ops
= &v9fs_addr_operations
;
263 switch (mode
& S_IFMT
) {
268 if (!v9fs_extended(v9ses
)) {
269 P9_DPRINTK(P9_DEBUG_ERROR
,
270 "special files without extended mode\n");
274 init_special_inode(inode
, inode
->i_mode
, inode
->i_rdev
);
277 inode
->i_op
= &v9fs_file_inode_operations
;
278 inode
->i_fop
= &v9fs_file_operations
;
281 if (!v9fs_extended(v9ses
)) {
282 P9_DPRINTK(P9_DEBUG_ERROR
,
283 "extended modes used w/o 9P2000.u\n");
287 inode
->i_op
= &v9fs_symlink_inode_operations
;
291 if (v9fs_extended(v9ses
))
292 inode
->i_op
= &v9fs_dir_inode_operations_ext
;
294 inode
->i_op
= &v9fs_dir_inode_operations
;
295 inode
->i_fop
= &v9fs_dir_operations
;
298 P9_DPRINTK(P9_DEBUG_ERROR
, "BAD mode 0x%x S_IFMT 0x%x\n",
299 mode
, mode
& S_IFMT
);
312 static struct v9fs_fid*
313 v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry)
317 struct v9fs_fid *ret;
318 struct v9fs_fcall *fcall;
320 nfid = v9fs_get_idpool(&v9ses->fidpool);
322 eprintk(KERN_WARNING, "no free fids available\n");
323 return ERR_PTR(-ENOSPC);
326 err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name,
330 if (fcall && fcall->id == RWALK)
333 PRINT_FCALL_ERROR("walk error", fcall);
334 v9fs_put_idpool(nfid, &v9ses->fidpool);
340 ret = v9fs_fid_create(v9ses, nfid);
346 err = v9fs_fid_insert(ret, dentry);
348 v9fs_fid_destroy(ret);
355 v9fs_t_clunk(v9ses, nfid);
365 * v9fs_clear_inode - release an inode
366 * @inode: inode to release
369 void v9fs_clear_inode(struct inode
*inode
)
371 filemap_fdatawrite(inode
->i_mapping
);
373 #ifdef CONFIG_9P_FSCACHE
374 v9fs_cache_inode_put_cookie(inode
);
379 * v9fs_inode_from_fid - populate an inode by issuing a attribute request
380 * @v9ses: session information
381 * @fid: fid to issue attribute request for
382 * @sb: superblock on which to create inode
386 static struct inode
*
387 v9fs_inode_from_fid(struct v9fs_session_info
*v9ses
, struct p9_fid
*fid
,
388 struct super_block
*sb
)
395 st
= p9_client_stat(fid
);
399 umode
= p9mode2unixmode(v9ses
, st
->mode
);
400 ret
= v9fs_get_inode(sb
, umode
);
406 v9fs_stat2inode(st
, ret
, sb
);
407 ret
->i_ino
= v9fs_qid2ino(&st
->qid
);
409 #ifdef CONFIG_9P_FSCACHE
410 v9fs_vcookie_set_qid(ret
, &st
->qid
);
411 v9fs_cache_inode_get_cookie(ret
);
425 * v9fs_remove - helper function to remove files and directories
426 * @dir: directory inode that is being deleted
427 * @file: dentry that is being deleted
428 * @rmdir: removing a directory
432 static int v9fs_remove(struct inode
*dir
, struct dentry
*file
, int rmdir
)
434 struct inode
*file_inode
;
435 struct v9fs_session_info
*v9ses
;
436 struct p9_fid
*v9fid
;
438 P9_DPRINTK(P9_DEBUG_VFS
, "inode: %p dentry: %p rmdir: %d\n", dir
, file
,
441 file_inode
= file
->d_inode
;
442 v9ses
= v9fs_inode2v9ses(file_inode
);
443 v9fid
= v9fs_fid_clone(file
);
445 return PTR_ERR(v9fid
);
447 return p9_client_remove(v9fid
);
451 v9fs_open_created(struct inode
*inode
, struct file
*file
)
458 * v9fs_create - Create a file
459 * @v9ses: session information
460 * @dir: directory that dentry is being created in
461 * @dentry: dentry that is being created
462 * @extension: 9p2000.u extension string to support devices, etc.
463 * @perm: create permissions
467 static struct p9_fid
*
468 v9fs_create(struct v9fs_session_info
*v9ses
, struct inode
*dir
,
469 struct dentry
*dentry
, char *extension
, u32 perm
, u8 mode
)
473 struct p9_fid
*dfid
, *ofid
, *fid
;
476 P9_DPRINTK(P9_DEBUG_VFS
, "name %s\n", dentry
->d_name
.name
);
481 name
= (char *) dentry
->d_name
.name
;
482 dfid
= v9fs_fid_clone(dentry
->d_parent
);
485 P9_DPRINTK(P9_DEBUG_VFS
, "fid clone failed %d\n", err
);
490 /* clone a fid to use for creation */
491 ofid
= p9_client_walk(dfid
, 0, NULL
, 1);
494 P9_DPRINTK(P9_DEBUG_VFS
, "p9_client_walk failed %d\n", err
);
499 err
= p9_client_fcreate(ofid
, name
, perm
, mode
, extension
);
501 P9_DPRINTK(P9_DEBUG_VFS
, "p9_client_fcreate failed %d\n", err
);
505 /* now walk from the parent so we can get unopened fid */
506 fid
= p9_client_walk(dfid
, 1, &name
, 0);
509 P9_DPRINTK(P9_DEBUG_VFS
, "p9_client_walk failed %d\n", err
);
515 /* instantiate inode and assign the unopened fid to the dentry */
516 inode
= v9fs_inode_from_fid(v9ses
, fid
, dir
->i_sb
);
518 err
= PTR_ERR(inode
);
519 P9_DPRINTK(P9_DEBUG_VFS
, "inode creation failed %d\n", err
);
524 dentry
->d_op
= &v9fs_cached_dentry_operations
;
526 dentry
->d_op
= &v9fs_dentry_operations
;
528 d_instantiate(dentry
, inode
);
529 err
= v9fs_fid_add(dentry
, fid
);
537 p9_client_clunk(dfid
);
540 p9_client_clunk(ofid
);
543 p9_client_clunk(fid
);
549 * v9fs_vfs_create - VFS hook to create files
550 * @dir: directory inode that is being created
551 * @dentry: dentry that is being deleted
552 * @mode: create permissions
553 * @nd: path information
558 v9fs_vfs_create(struct inode
*dir
, struct dentry
*dentry
, int mode
,
559 struct nameidata
*nd
)
564 struct v9fs_session_info
*v9ses
;
570 v9ses
= v9fs_inode2v9ses(dir
);
571 perm
= unixmode2p9mode(v9ses
, mode
);
572 if (nd
&& nd
->flags
& LOOKUP_OPEN
)
573 flags
= nd
->intent
.open
.flags
- 1;
577 fid
= v9fs_create(v9ses
, dir
, dentry
, NULL
, perm
,
578 v9fs_uflags2omode(flags
, v9fs_extended(v9ses
)));
585 /* if we are opening a file, assign the open fid to the file */
586 if (nd
&& nd
->flags
& LOOKUP_OPEN
) {
587 filp
= lookup_instantiate_filp(nd
, dentry
, v9fs_open_created
);
593 filp
->private_data
= fid
;
595 p9_client_clunk(fid
);
601 p9_client_clunk(fid
);
607 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
608 * @dir: inode that is being unlinked
609 * @dentry: dentry that is being unlinked
610 * @mode: mode for new directory
614 static int v9fs_vfs_mkdir(struct inode
*dir
, struct dentry
*dentry
, int mode
)
618 struct v9fs_session_info
*v9ses
;
621 P9_DPRINTK(P9_DEBUG_VFS
, "name %s\n", dentry
->d_name
.name
);
623 v9ses
= v9fs_inode2v9ses(dir
);
624 perm
= unixmode2p9mode(v9ses
, mode
| S_IFDIR
);
625 fid
= v9fs_create(v9ses
, dir
, dentry
, NULL
, perm
, P9_OREAD
);
632 p9_client_clunk(fid
);
638 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
639 * @dir: inode that is being walked from
640 * @dentry: dentry that is being walked to?
641 * @nameidata: path data
645 static struct dentry
*v9fs_vfs_lookup(struct inode
*dir
, struct dentry
*dentry
,
646 struct nameidata
*nameidata
)
648 struct super_block
*sb
;
649 struct v9fs_session_info
*v9ses
;
650 struct p9_fid
*dfid
, *fid
;
655 P9_DPRINTK(P9_DEBUG_VFS
, "dir: %p dentry: (%s) %p nameidata: %p\n",
656 dir
, dentry
->d_name
.name
, dentry
, nameidata
);
659 v9ses
= v9fs_inode2v9ses(dir
);
660 dfid
= v9fs_fid_lookup(dentry
->d_parent
);
662 return ERR_CAST(dfid
);
664 name
= (char *) dentry
->d_name
.name
;
665 fid
= p9_client_walk(dfid
, 1, &name
, 1);
667 result
= PTR_ERR(fid
);
668 if (result
== -ENOENT
) {
673 return ERR_PTR(result
);
676 inode
= v9fs_inode_from_fid(v9ses
, fid
, dir
->i_sb
);
678 result
= PTR_ERR(inode
);
683 result
= v9fs_fid_add(dentry
, fid
);
687 if ((fid
->qid
.version
) && (v9ses
->cache
))
688 dentry
->d_op
= &v9fs_cached_dentry_operations
;
690 dentry
->d_op
= &v9fs_dentry_operations
;
692 d_add(dentry
, inode
);
696 p9_client_clunk(fid
);
698 return ERR_PTR(result
);
702 * v9fs_vfs_unlink - VFS unlink hook to delete an inode
703 * @i: inode that is being unlinked
704 * @d: dentry that is being unlinked
708 static int v9fs_vfs_unlink(struct inode
*i
, struct dentry
*d
)
710 return v9fs_remove(i
, d
, 0);
714 * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
715 * @i: inode that is being unlinked
716 * @d: dentry that is being unlinked
720 static int v9fs_vfs_rmdir(struct inode
*i
, struct dentry
*d
)
722 return v9fs_remove(i
, d
, 1);
726 * v9fs_vfs_rename - VFS hook to rename an inode
727 * @old_dir: old dir inode
728 * @old_dentry: old dentry
729 * @new_dir: new dir inode
730 * @new_dentry: new dentry
735 v9fs_vfs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
736 struct inode
*new_dir
, struct dentry
*new_dentry
)
738 struct inode
*old_inode
;
739 struct v9fs_session_info
*v9ses
;
740 struct p9_fid
*oldfid
;
741 struct p9_fid
*olddirfid
;
742 struct p9_fid
*newdirfid
;
743 struct p9_wstat wstat
;
746 P9_DPRINTK(P9_DEBUG_VFS
, "\n");
748 old_inode
= old_dentry
->d_inode
;
749 v9ses
= v9fs_inode2v9ses(old_inode
);
750 oldfid
= v9fs_fid_lookup(old_dentry
);
752 return PTR_ERR(oldfid
);
754 olddirfid
= v9fs_fid_clone(old_dentry
->d_parent
);
755 if (IS_ERR(olddirfid
)) {
756 retval
= PTR_ERR(olddirfid
);
760 newdirfid
= v9fs_fid_clone(new_dentry
->d_parent
);
761 if (IS_ERR(newdirfid
)) {
762 retval
= PTR_ERR(newdirfid
);
766 /* 9P can only handle file rename in the same directory */
767 if (memcmp(&olddirfid
->qid
, &newdirfid
->qid
, sizeof(newdirfid
->qid
))) {
768 P9_DPRINTK(P9_DEBUG_ERROR
,
769 "old dir and new dir are different\n");
774 v9fs_blank_wstat(&wstat
);
775 wstat
.muid
= v9ses
->uname
;
776 wstat
.name
= (char *) new_dentry
->d_name
.name
;
777 retval
= p9_client_wstat(oldfid
, &wstat
);
780 p9_client_clunk(newdirfid
);
783 p9_client_clunk(olddirfid
);
790 * v9fs_vfs_getattr - retrieve file metadata
791 * @mnt: mount information
792 * @dentry: file to get attributes on
793 * @stat: metadata structure to populate
798 v9fs_vfs_getattr(struct vfsmount
*mnt
, struct dentry
*dentry
,
802 struct v9fs_session_info
*v9ses
;
806 P9_DPRINTK(P9_DEBUG_VFS
, "dentry: %p\n", dentry
);
808 v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
809 if (v9ses
->cache
== CACHE_LOOSE
|| v9ses
->cache
== CACHE_FSCACHE
)
810 return simple_getattr(mnt
, dentry
, stat
);
812 fid
= v9fs_fid_lookup(dentry
);
816 st
= p9_client_stat(fid
);
820 v9fs_stat2inode(st
, dentry
->d_inode
, dentry
->d_inode
->i_sb
);
821 generic_fillattr(dentry
->d_inode
, stat
);
828 * v9fs_vfs_setattr - set file metadata
829 * @dentry: file whose metadata to set
830 * @iattr: metadata assignment structure
834 static int v9fs_vfs_setattr(struct dentry
*dentry
, struct iattr
*iattr
)
837 struct v9fs_session_info
*v9ses
;
839 struct p9_wstat wstat
;
841 P9_DPRINTK(P9_DEBUG_VFS
, "\n");
843 v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
844 fid
= v9fs_fid_lookup(dentry
);
848 v9fs_blank_wstat(&wstat
);
849 if (iattr
->ia_valid
& ATTR_MODE
)
850 wstat
.mode
= unixmode2p9mode(v9ses
, iattr
->ia_mode
);
852 if (iattr
->ia_valid
& ATTR_MTIME
)
853 wstat
.mtime
= iattr
->ia_mtime
.tv_sec
;
855 if (iattr
->ia_valid
& ATTR_ATIME
)
856 wstat
.atime
= iattr
->ia_atime
.tv_sec
;
858 if (iattr
->ia_valid
& ATTR_SIZE
)
859 wstat
.length
= iattr
->ia_size
;
861 if (v9fs_extended(v9ses
)) {
862 if (iattr
->ia_valid
& ATTR_UID
)
863 wstat
.n_uid
= iattr
->ia_uid
;
865 if (iattr
->ia_valid
& ATTR_GID
)
866 wstat
.n_gid
= iattr
->ia_gid
;
869 retval
= p9_client_wstat(fid
, &wstat
);
871 retval
= inode_setattr(dentry
->d_inode
, iattr
);
877 * v9fs_stat2inode - populate an inode structure with mistat info
878 * @stat: Plan 9 metadata (mistat) structure
879 * @inode: inode to populate
880 * @sb: superblock of filesystem
885 v9fs_stat2inode(struct p9_wstat
*stat
, struct inode
*inode
,
886 struct super_block
*sb
)
889 struct v9fs_session_info
*v9ses
= sb
->s_fs_info
;
893 inode
->i_atime
.tv_sec
= stat
->atime
;
894 inode
->i_mtime
.tv_sec
= stat
->mtime
;
895 inode
->i_ctime
.tv_sec
= stat
->mtime
;
897 inode
->i_uid
= v9ses
->dfltuid
;
898 inode
->i_gid
= v9ses
->dfltgid
;
900 if (v9fs_extended(v9ses
)) {
901 inode
->i_uid
= stat
->n_uid
;
902 inode
->i_gid
= stat
->n_gid
;
905 inode
->i_mode
= p9mode2unixmode(v9ses
, stat
->mode
);
906 if ((S_ISBLK(inode
->i_mode
)) || (S_ISCHR(inode
->i_mode
))) {
911 strncpy(ext
, stat
->extension
, sizeof(ext
));
912 sscanf(ext
, "%c %u %u", &type
, &major
, &minor
);
915 inode
->i_mode
&= ~S_IFBLK
;
916 inode
->i_mode
|= S_IFCHR
;
921 P9_DPRINTK(P9_DEBUG_ERROR
,
922 "Unknown special type %c %s\n", type
,
925 inode
->i_rdev
= MKDEV(major
, minor
);
926 init_special_inode(inode
, inode
->i_mode
, inode
->i_rdev
);
930 i_size_write(inode
, stat
->length
);
932 /* not real number of blocks, but 512 byte ones ... */
933 inode
->i_blocks
= (i_size_read(inode
) + 512 - 1) >> 9;
937 * v9fs_qid2ino - convert qid into inode number
940 * BUG: potential for inode number collisions?
943 ino_t
v9fs_qid2ino(struct p9_qid
*qid
)
945 u64 path
= qid
->path
+ 2;
948 if (sizeof(ino_t
) == sizeof(path
))
949 memcpy(&i
, &path
, sizeof(ino_t
));
951 i
= (ino_t
) (path
^ (path
>> 32));
957 * v9fs_readlink - read a symlink's location (internal version)
958 * @dentry: dentry for symlink
959 * @buffer: buffer to load symlink location into
960 * @buflen: length of buffer
964 static int v9fs_readlink(struct dentry
*dentry
, char *buffer
, int buflen
)
968 struct v9fs_session_info
*v9ses
;
972 P9_DPRINTK(P9_DEBUG_VFS
, " %s\n", dentry
->d_name
.name
);
974 v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
975 fid
= v9fs_fid_lookup(dentry
);
979 if (!v9fs_extended(v9ses
))
982 st
= p9_client_stat(fid
);
986 if (!(st
->mode
& P9_DMSYMLINK
)) {
991 /* copy extension buffer into buffer */
992 strncpy(buffer
, st
->extension
, buflen
);
994 P9_DPRINTK(P9_DEBUG_VFS
,
995 "%s -> %s (%s)\n", dentry
->d_name
.name
, st
->extension
, buffer
);
1005 * v9fs_vfs_readlink - read a symlink's location
1006 * @dentry: dentry for symlink
1007 * @buffer: buffer to load symlink location into
1008 * @buflen: length of buffer
1012 static int v9fs_vfs_readlink(struct dentry
*dentry
, char __user
* buffer
,
1017 char *link
= __getname();
1019 if (unlikely(!link
))
1022 if (buflen
> PATH_MAX
)
1025 P9_DPRINTK(P9_DEBUG_VFS
, " dentry: %s (%p)\n", dentry
->d_name
.name
,
1028 retval
= v9fs_readlink(dentry
, link
, buflen
);
1031 if ((ret
= copy_to_user(buffer
, link
, retval
)) != 0) {
1032 P9_DPRINTK(P9_DEBUG_ERROR
,
1033 "problem copying to user: %d\n", ret
);
1043 * v9fs_vfs_follow_link - follow a symlink path
1044 * @dentry: dentry for symlink
1049 static void *v9fs_vfs_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
1052 char *link
= __getname();
1054 P9_DPRINTK(P9_DEBUG_VFS
, "%s n", dentry
->d_name
.name
);
1057 link
= ERR_PTR(-ENOMEM
);
1059 len
= v9fs_readlink(dentry
, link
, PATH_MAX
);
1063 link
= ERR_PTR(len
);
1067 nd_set_link(nd
, link
);
1073 * v9fs_vfs_put_link - release a symlink path
1074 * @dentry: dentry for symlink
1081 v9fs_vfs_put_link(struct dentry
*dentry
, struct nameidata
*nd
, void *p
)
1083 char *s
= nd_get_link(nd
);
1085 P9_DPRINTK(P9_DEBUG_VFS
, " %s %s\n", dentry
->d_name
.name
,
1086 IS_ERR(s
) ? "<error>" : s
);
1092 * v9fs_vfs_mkspecial - create a special file
1093 * @dir: inode to create special file in
1094 * @dentry: dentry to create
1095 * @mode: mode to create special file
1096 * @extension: 9p2000.u format extension string representing special file
1100 static int v9fs_vfs_mkspecial(struct inode
*dir
, struct dentry
*dentry
,
1101 int mode
, const char *extension
)
1104 struct v9fs_session_info
*v9ses
;
1107 v9ses
= v9fs_inode2v9ses(dir
);
1108 if (!v9fs_extended(v9ses
)) {
1109 P9_DPRINTK(P9_DEBUG_ERROR
, "not extended\n");
1113 perm
= unixmode2p9mode(v9ses
, mode
);
1114 fid
= v9fs_create(v9ses
, dir
, dentry
, (char *) extension
, perm
,
1117 return PTR_ERR(fid
);
1119 p9_client_clunk(fid
);
1124 * v9fs_vfs_symlink - helper function to create symlinks
1125 * @dir: directory inode containing symlink
1126 * @dentry: dentry for symlink
1127 * @symname: symlink data
1129 * See Also: 9P2000.u RFC for more information
1134 v9fs_vfs_symlink(struct inode
*dir
, struct dentry
*dentry
, const char *symname
)
1136 P9_DPRINTK(P9_DEBUG_VFS
, " %lu,%s,%s\n", dir
->i_ino
,
1137 dentry
->d_name
.name
, symname
);
1139 return v9fs_vfs_mkspecial(dir
, dentry
, S_IFLNK
, symname
);
1143 * v9fs_vfs_link - create a hardlink
1144 * @old_dentry: dentry for file to link to
1145 * @dir: inode destination for new link
1146 * @dentry: dentry for link
1151 v9fs_vfs_link(struct dentry
*old_dentry
, struct inode
*dir
,
1152 struct dentry
*dentry
)
1155 struct p9_fid
*oldfid
;
1158 P9_DPRINTK(P9_DEBUG_VFS
,
1159 " %lu,%s,%s\n", dir
->i_ino
, dentry
->d_name
.name
,
1160 old_dentry
->d_name
.name
);
1162 oldfid
= v9fs_fid_clone(old_dentry
);
1164 return PTR_ERR(oldfid
);
1167 if (unlikely(!name
)) {
1172 sprintf(name
, "%d\n", oldfid
->fid
);
1173 retval
= v9fs_vfs_mkspecial(dir
, dentry
, P9_DMLINK
, name
);
1177 p9_client_clunk(oldfid
);
1182 * v9fs_vfs_mknod - create a special file
1183 * @dir: inode destination for new link
1184 * @dentry: dentry for file
1185 * @mode: mode for creation
1186 * @rdev: device associated with special file
1191 v9fs_vfs_mknod(struct inode
*dir
, struct dentry
*dentry
, int mode
, dev_t rdev
)
1196 P9_DPRINTK(P9_DEBUG_VFS
,
1197 " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir
->i_ino
,
1198 dentry
->d_name
.name
, mode
, MAJOR(rdev
), MINOR(rdev
));
1200 if (!new_valid_dev(rdev
))
1206 /* build extension */
1208 sprintf(name
, "b %u %u", MAJOR(rdev
), MINOR(rdev
));
1209 else if (S_ISCHR(mode
))
1210 sprintf(name
, "c %u %u", MAJOR(rdev
), MINOR(rdev
));
1211 else if (S_ISFIFO(mode
))
1218 retval
= v9fs_vfs_mkspecial(dir
, dentry
, mode
, name
);
1224 static const struct inode_operations v9fs_dir_inode_operations_ext
= {
1225 .create
= v9fs_vfs_create
,
1226 .lookup
= v9fs_vfs_lookup
,
1227 .symlink
= v9fs_vfs_symlink
,
1228 .link
= v9fs_vfs_link
,
1229 .unlink
= v9fs_vfs_unlink
,
1230 .mkdir
= v9fs_vfs_mkdir
,
1231 .rmdir
= v9fs_vfs_rmdir
,
1232 .mknod
= v9fs_vfs_mknod
,
1233 .rename
= v9fs_vfs_rename
,
1234 .readlink
= v9fs_vfs_readlink
,
1235 .getattr
= v9fs_vfs_getattr
,
1236 .setattr
= v9fs_vfs_setattr
,
1239 static const struct inode_operations v9fs_dir_inode_operations
= {
1240 .create
= v9fs_vfs_create
,
1241 .lookup
= v9fs_vfs_lookup
,
1242 .unlink
= v9fs_vfs_unlink
,
1243 .mkdir
= v9fs_vfs_mkdir
,
1244 .rmdir
= v9fs_vfs_rmdir
,
1245 .mknod
= v9fs_vfs_mknod
,
1246 .rename
= v9fs_vfs_rename
,
1247 .getattr
= v9fs_vfs_getattr
,
1248 .setattr
= v9fs_vfs_setattr
,
1251 static const struct inode_operations v9fs_file_inode_operations
= {
1252 .getattr
= v9fs_vfs_getattr
,
1253 .setattr
= v9fs_vfs_setattr
,
1256 static const struct inode_operations v9fs_symlink_inode_operations
= {
1257 .readlink
= v9fs_vfs_readlink
,
1258 .follow_link
= v9fs_vfs_follow_link
,
1259 .put_link
= v9fs_vfs_put_link
,
1260 .getattr
= v9fs_vfs_getattr
,
1261 .setattr
= v9fs_vfs_setattr
,