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_init_owner(inode, NULL, mode);
259 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
260 inode->i_mapping->a_ops = &v9fs_addr_operations;
262 switch (mode & S_IFMT) {
267 if (!v9fs_proto_dotu(v9ses)) {
268 P9_DPRINTK(P9_DEBUG_ERROR,
269 "special files without extended mode\n");
273 init_special_inode(inode, inode->i_mode, inode->i_rdev);
276 inode->i_op = &v9fs_file_inode_operations;
277 inode->i_fop = &v9fs_file_operations;
280 if (!v9fs_proto_dotu(v9ses)) {
281 P9_DPRINTK(P9_DEBUG_ERROR,
282 "extended modes used w/o 9P2000.u\n");
286 inode->i_op = &v9fs_symlink_inode_operations;
290 if (v9fs_proto_dotu(v9ses))
291 inode->i_op = &v9fs_dir_inode_operations_ext;
293 inode->i_op = &v9fs_dir_inode_operations;
294 inode->i_fop = &v9fs_dir_operations;
297 P9_DPRINTK(P9_DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n",
298 mode, mode & S_IFMT);
311 static struct v9fs_fid*
312 v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry)
316 struct v9fs_fid *ret;
317 struct v9fs_fcall *fcall;
319 nfid = v9fs_get_idpool(&v9ses->fidpool);
321 eprintk(KERN_WARNING, "no free fids available\n");
322 return ERR_PTR(-ENOSPC);
325 err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name,
329 if (fcall && fcall->id == RWALK)
332 PRINT_FCALL_ERROR("walk error", fcall);
333 v9fs_put_idpool(nfid, &v9ses->fidpool);
339 ret = v9fs_fid_create(v9ses, nfid);
345 err = v9fs_fid_insert(ret, dentry);
347 v9fs_fid_destroy(ret);
354 v9fs_t_clunk(v9ses, nfid);
364 * v9fs_clear_inode - release an inode
365 * @inode: inode to release
368 void v9fs_clear_inode(struct inode *inode)
370 filemap_fdatawrite(inode->i_mapping);
372 #ifdef CONFIG_9P_FSCACHE
373 v9fs_cache_inode_put_cookie(inode);
378 * v9fs_inode_from_fid - populate an inode by issuing a attribute request
379 * @v9ses: session information
380 * @fid: fid to issue attribute request for
381 * @sb: superblock on which to create inode
385 static struct inode *
386 v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
387 struct super_block *sb)
394 st = p9_client_stat(fid);
398 umode = p9mode2unixmode(v9ses, st->mode);
399 ret = v9fs_get_inode(sb, umode);
405 v9fs_stat2inode(st, ret, sb);
406 ret->i_ino = v9fs_qid2ino(&st->qid);
408 #ifdef CONFIG_9P_FSCACHE
409 v9fs_vcookie_set_qid(ret, &st->qid);
410 v9fs_cache_inode_get_cookie(ret);
424 * v9fs_remove - helper function to remove files and directories
425 * @dir: directory inode that is being deleted
426 * @file: dentry that is being deleted
427 * @rmdir: removing a directory
431 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 retval = p9_client_remove(v9fid);
449 drop_nlink(file_inode);
454 v9fs_open_created(struct inode *inode, struct file *file)
461 * v9fs_create - Create a file
462 * @v9ses: session information
463 * @dir: directory that dentry is being created in
464 * @dentry: dentry that is being created
465 * @extension: 9p2000.u extension string to support devices, etc.
466 * @perm: create permissions
470 static struct p9_fid *
471 v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
472 struct dentry *dentry, char *extension, u32 perm, u8 mode)
476 struct p9_fid *dfid, *ofid, *fid;
479 P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
484 name = (char *) dentry->d_name.name;
485 dfid = v9fs_fid_clone(dentry->d_parent);
488 P9_DPRINTK(P9_DEBUG_VFS, "fid clone failed %d\n", err);
493 /* clone a fid to use for creation */
494 ofid = p9_client_walk(dfid, 0, NULL, 1);
497 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
502 err = p9_client_fcreate(ofid, name, perm, mode, extension);
504 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err);
508 /* now walk from the parent so we can get unopened fid */
509 fid = p9_client_walk(dfid, 1, &name, 0);
512 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
518 /* instantiate inode and assign the unopened fid to the dentry */
519 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
521 err = PTR_ERR(inode);
522 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
527 dentry->d_op = &v9fs_cached_dentry_operations;
529 dentry->d_op = &v9fs_dentry_operations;
531 d_instantiate(dentry, inode);
532 err = v9fs_fid_add(dentry, fid);
540 p9_client_clunk(dfid);
543 p9_client_clunk(ofid);
546 p9_client_clunk(fid);
552 * v9fs_vfs_create - VFS hook to create files
553 * @dir: directory inode that is being created
554 * @dentry: dentry that is being deleted
555 * @mode: create permissions
556 * @nd: path information
561 v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
562 struct nameidata *nd)
567 struct v9fs_session_info *v9ses;
573 v9ses = v9fs_inode2v9ses(dir);
574 perm = unixmode2p9mode(v9ses, mode);
575 if (nd && nd->flags & LOOKUP_OPEN)
576 flags = nd->intent.open.flags - 1;
580 fid = v9fs_create(v9ses, dir, dentry, NULL, perm,
581 v9fs_uflags2omode(flags,
582 v9fs_proto_dotu(v9ses)));
589 /* if we are opening a file, assign the open fid to the file */
590 if (nd && nd->flags & LOOKUP_OPEN) {
591 filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created);
597 filp->private_data = fid;
599 p9_client_clunk(fid);
605 p9_client_clunk(fid);
611 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
612 * @dir: inode that is being unlinked
613 * @dentry: dentry that is being unlinked
614 * @mode: mode for new directory
618 static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
622 struct v9fs_session_info *v9ses;
625 P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
627 v9ses = v9fs_inode2v9ses(dir);
628 perm = unixmode2p9mode(v9ses, mode | S_IFDIR);
629 fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_OREAD);
636 p9_client_clunk(fid);
642 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
643 * @dir: inode that is being walked from
644 * @dentry: dentry that is being walked to?
645 * @nameidata: path data
649 static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
650 struct nameidata *nameidata)
652 struct super_block *sb;
653 struct v9fs_session_info *v9ses;
654 struct p9_fid *dfid, *fid;
659 P9_DPRINTK(P9_DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n",
660 dir, dentry->d_name.name, dentry, nameidata);
662 if (dentry->d_name.len > NAME_MAX)
663 return ERR_PTR(-ENAMETOOLONG);
666 v9ses = v9fs_inode2v9ses(dir);
667 dfid = v9fs_fid_lookup(dentry->d_parent);
669 return ERR_CAST(dfid);
671 name = (char *) dentry->d_name.name;
672 fid = p9_client_walk(dfid, 1, &name, 1);
674 result = PTR_ERR(fid);
675 if (result == -ENOENT) {
680 return ERR_PTR(result);
683 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
685 result = PTR_ERR(inode);
690 result = v9fs_fid_add(dentry, fid);
694 if ((fid->qid.version) && (v9ses->cache))
695 dentry->d_op = &v9fs_cached_dentry_operations;
697 dentry->d_op = &v9fs_dentry_operations;
699 d_add(dentry, inode);
703 p9_client_clunk(fid);
705 return ERR_PTR(result);
709 * v9fs_vfs_unlink - VFS unlink hook to delete an inode
710 * @i: inode that is being unlinked
711 * @d: dentry that is being unlinked
715 static int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
717 return v9fs_remove(i, d, 0);
721 * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
722 * @i: inode that is being unlinked
723 * @d: dentry that is being unlinked
727 static int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
729 return v9fs_remove(i, d, 1);
733 * v9fs_vfs_rename - VFS hook to rename an inode
734 * @old_dir: old dir inode
735 * @old_dentry: old dentry
736 * @new_dir: new dir inode
737 * @new_dentry: new dentry
742 v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
743 struct inode *new_dir, struct dentry *new_dentry)
745 struct inode *old_inode;
746 struct v9fs_session_info *v9ses;
747 struct p9_fid *oldfid;
748 struct p9_fid *olddirfid;
749 struct p9_fid *newdirfid;
750 struct p9_wstat wstat;
753 P9_DPRINTK(P9_DEBUG_VFS, "\n");
755 old_inode = old_dentry->d_inode;
756 v9ses = v9fs_inode2v9ses(old_inode);
757 oldfid = v9fs_fid_lookup(old_dentry);
759 return PTR_ERR(oldfid);
761 olddirfid = v9fs_fid_clone(old_dentry->d_parent);
762 if (IS_ERR(olddirfid)) {
763 retval = PTR_ERR(olddirfid);
767 newdirfid = v9fs_fid_clone(new_dentry->d_parent);
768 if (IS_ERR(newdirfid)) {
769 retval = PTR_ERR(newdirfid);
773 /* 9P can only handle file rename in the same directory */
774 if (memcmp(&olddirfid->qid, &newdirfid->qid, sizeof(newdirfid->qid))) {
775 P9_DPRINTK(P9_DEBUG_ERROR,
776 "old dir and new dir are different\n");
781 v9fs_blank_wstat(&wstat);
782 wstat.muid = v9ses->uname;
783 wstat.name = (char *) new_dentry->d_name.name;
784 retval = p9_client_wstat(oldfid, &wstat);
787 p9_client_clunk(newdirfid);
790 p9_client_clunk(olddirfid);
797 * v9fs_vfs_getattr - retrieve file metadata
798 * @mnt: mount information
799 * @dentry: file to get attributes on
800 * @stat: metadata structure to populate
805 v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
809 struct v9fs_session_info *v9ses;
813 P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
815 v9ses = v9fs_inode2v9ses(dentry->d_inode);
816 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
817 return simple_getattr(mnt, dentry, stat);
819 fid = v9fs_fid_lookup(dentry);
823 st = p9_client_stat(fid);
827 v9fs_stat2inode(st, dentry->d_inode, dentry->d_inode->i_sb);
828 generic_fillattr(dentry->d_inode, stat);
835 * v9fs_vfs_setattr - set file metadata
836 * @dentry: file whose metadata to set
837 * @iattr: metadata assignment structure
841 static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
844 struct v9fs_session_info *v9ses;
846 struct p9_wstat wstat;
848 P9_DPRINTK(P9_DEBUG_VFS, "\n");
850 v9ses = v9fs_inode2v9ses(dentry->d_inode);
851 fid = v9fs_fid_lookup(dentry);
855 v9fs_blank_wstat(&wstat);
856 if (iattr->ia_valid & ATTR_MODE)
857 wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode);
859 if (iattr->ia_valid & ATTR_MTIME)
860 wstat.mtime = iattr->ia_mtime.tv_sec;
862 if (iattr->ia_valid & ATTR_ATIME)
863 wstat.atime = iattr->ia_atime.tv_sec;
865 if (iattr->ia_valid & ATTR_SIZE)
866 wstat.length = iattr->ia_size;
868 if (v9fs_proto_dotu(v9ses)) {
869 if (iattr->ia_valid & ATTR_UID)
870 wstat.n_uid = iattr->ia_uid;
872 if (iattr->ia_valid & ATTR_GID)
873 wstat.n_gid = iattr->ia_gid;
876 retval = p9_client_wstat(fid, &wstat);
878 retval = inode_setattr(dentry->d_inode, iattr);
884 * v9fs_stat2inode - populate an inode structure with mistat info
885 * @stat: Plan 9 metadata (mistat) structure
886 * @inode: inode to populate
887 * @sb: superblock of filesystem
892 v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
893 struct super_block *sb)
897 unsigned int i_nlink;
898 struct v9fs_session_info *v9ses = sb->s_fs_info;
902 inode->i_atime.tv_sec = stat->atime;
903 inode->i_mtime.tv_sec = stat->mtime;
904 inode->i_ctime.tv_sec = stat->mtime;
906 inode->i_uid = v9ses->dfltuid;
907 inode->i_gid = v9ses->dfltgid;
909 if (v9fs_proto_dotu(v9ses)) {
910 inode->i_uid = stat->n_uid;
911 inode->i_gid = stat->n_gid;
913 if ((S_ISREG(inode->i_mode)) || (S_ISDIR(inode->i_mode))) {
914 if (v9fs_proto_dotu(v9ses) && (stat->extension[0] != '\0')) {
916 * Hadlink support got added later to
917 * to the .u extension. So there can be
918 * server out there that doesn't support
919 * this even with .u extension. So check
920 * for non NULL stat->extension
922 strncpy(ext, stat->extension, sizeof(ext));
923 /* HARDLINKCOUNT %u */
924 sscanf(ext, "%13s %u", tag_name, &i_nlink);
925 if (!strncmp(tag_name, "HARDLINKCOUNT", 13))
926 inode->i_nlink = i_nlink;
929 inode->i_mode = p9mode2unixmode(v9ses, stat->mode);
930 if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) {
935 strncpy(ext, stat->extension, sizeof(ext));
936 sscanf(ext, "%c %u %u", &type, &major, &minor);
939 inode->i_mode &= ~S_IFBLK;
940 inode->i_mode |= S_IFCHR;
945 P9_DPRINTK(P9_DEBUG_ERROR,
946 "Unknown special type %c %s\n", type,
949 inode->i_rdev = MKDEV(major, minor);
950 init_special_inode(inode, inode->i_mode, inode->i_rdev);
954 i_size_write(inode, stat->length);
956 /* not real number of blocks, but 512 byte ones ... */
957 inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9;
961 * v9fs_qid2ino - convert qid into inode number
964 * BUG: potential for inode number collisions?
967 ino_t v9fs_qid2ino(struct p9_qid *qid)
969 u64 path = qid->path + 2;
972 if (sizeof(ino_t) == sizeof(path))
973 memcpy(&i, &path, sizeof(ino_t));
975 i = (ino_t) (path ^ (path >> 32));
981 * v9fs_readlink - read a symlink's location (internal version)
982 * @dentry: dentry for symlink
983 * @buffer: buffer to load symlink location into
984 * @buflen: length of buffer
988 static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
992 struct v9fs_session_info *v9ses;
996 P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name);
998 v9ses = v9fs_inode2v9ses(dentry->d_inode);
999 fid = v9fs_fid_lookup(dentry);
1001 return PTR_ERR(fid);
1003 if (!v9fs_proto_dotu(v9ses))
1006 st = p9_client_stat(fid);
1010 if (!(st->mode & P9_DMSYMLINK)) {
1015 /* copy extension buffer into buffer */
1016 strncpy(buffer, st->extension, buflen);
1018 P9_DPRINTK(P9_DEBUG_VFS,
1019 "%s -> %s (%s)\n", dentry->d_name.name, st->extension, buffer);
1021 retval = strnlen(buffer, buflen);
1028 * v9fs_vfs_follow_link - follow a symlink path
1029 * @dentry: dentry for symlink
1034 static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
1037 char *link = __getname();
1039 P9_DPRINTK(P9_DEBUG_VFS, "%s n", dentry->d_name.name);
1042 link = ERR_PTR(-ENOMEM);
1044 len = v9fs_readlink(dentry, link, PATH_MAX);
1048 link = ERR_PTR(len);
1050 link[min(len, PATH_MAX-1)] = 0;
1052 nd_set_link(nd, link);
1058 * v9fs_vfs_put_link - release a symlink path
1059 * @dentry: dentry for symlink
1066 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
1068 char *s = nd_get_link(nd);
1070 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
1071 IS_ERR(s) ? "<error>" : s);
1077 * v9fs_vfs_mkspecial - create a special file
1078 * @dir: inode to create special file in
1079 * @dentry: dentry to create
1080 * @mode: mode to create special file
1081 * @extension: 9p2000.u format extension string representing special file
1085 static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
1086 int mode, const char *extension)
1089 struct v9fs_session_info *v9ses;
1092 v9ses = v9fs_inode2v9ses(dir);
1093 if (!v9fs_proto_dotu(v9ses)) {
1094 P9_DPRINTK(P9_DEBUG_ERROR, "not extended\n");
1098 perm = unixmode2p9mode(v9ses, mode);
1099 fid = v9fs_create(v9ses, dir, dentry, (char *) extension, perm,
1102 return PTR_ERR(fid);
1104 p9_client_clunk(fid);
1109 * v9fs_vfs_symlink - helper function to create symlinks
1110 * @dir: directory inode containing symlink
1111 * @dentry: dentry for symlink
1112 * @symname: symlink data
1114 * See Also: 9P2000.u RFC for more information
1119 v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
1121 P9_DPRINTK(P9_DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino,
1122 dentry->d_name.name, symname);
1124 return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname);
1128 * v9fs_vfs_link - create a hardlink
1129 * @old_dentry: dentry for file to link to
1130 * @dir: inode destination for new link
1131 * @dentry: dentry for link
1136 v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1137 struct dentry *dentry)
1140 struct p9_fid *oldfid;
1143 P9_DPRINTK(P9_DEBUG_VFS,
1144 " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
1145 old_dentry->d_name.name);
1147 oldfid = v9fs_fid_clone(old_dentry);
1149 return PTR_ERR(oldfid);
1152 if (unlikely(!name)) {
1157 sprintf(name, "%d\n", oldfid->fid);
1158 retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name);
1162 p9_client_clunk(oldfid);
1167 * v9fs_vfs_mknod - create a special file
1168 * @dir: inode destination for new link
1169 * @dentry: dentry for file
1170 * @mode: mode for creation
1171 * @rdev: device associated with special file
1176 v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1181 P9_DPRINTK(P9_DEBUG_VFS,
1182 " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
1183 dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev));
1185 if (!new_valid_dev(rdev))
1191 /* build extension */
1193 sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev));
1194 else if (S_ISCHR(mode))
1195 sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev));
1196 else if (S_ISFIFO(mode))
1203 retval = v9fs_vfs_mkspecial(dir, dentry, mode, name);
1209 static const struct inode_operations v9fs_dir_inode_operations_ext = {
1210 .create = v9fs_vfs_create,
1211 .lookup = v9fs_vfs_lookup,
1212 .symlink = v9fs_vfs_symlink,
1213 .link = v9fs_vfs_link,
1214 .unlink = v9fs_vfs_unlink,
1215 .mkdir = v9fs_vfs_mkdir,
1216 .rmdir = v9fs_vfs_rmdir,
1217 .mknod = v9fs_vfs_mknod,
1218 .rename = v9fs_vfs_rename,
1219 .getattr = v9fs_vfs_getattr,
1220 .setattr = v9fs_vfs_setattr,
1223 static const struct inode_operations v9fs_dir_inode_operations = {
1224 .create = v9fs_vfs_create,
1225 .lookup = v9fs_vfs_lookup,
1226 .unlink = v9fs_vfs_unlink,
1227 .mkdir = v9fs_vfs_mkdir,
1228 .rmdir = v9fs_vfs_rmdir,
1229 .mknod = v9fs_vfs_mknod,
1230 .rename = v9fs_vfs_rename,
1231 .getattr = v9fs_vfs_getattr,
1232 .setattr = v9fs_vfs_setattr,
1235 static const struct inode_operations v9fs_file_inode_operations = {
1236 .getattr = v9fs_vfs_getattr,
1237 .setattr = v9fs_vfs_setattr,
1240 static const struct inode_operations v9fs_symlink_inode_operations = {
1241 .readlink = generic_readlink,
1242 .follow_link = v9fs_vfs_follow_link,
1243 .put_link = v9fs_vfs_put_link,
1244 .getattr = v9fs_vfs_getattr,
1245 .setattr = v9fs_vfs_setattr,