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 as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
27 #include <linux/module.h>
28 #include <linux/errno.h>
30 #include <linux/file.h>
31 #include <linux/pagemap.h>
32 #include <linux/stat.h>
33 #include <linux/string.h>
34 #include <linux/smp_lock.h>
35 #include <linux/inet.h>
36 #include <linux/namei.h>
37 #include <linux/idr.h>
45 static struct inode_operations v9fs_dir_inode_operations;
46 static struct inode_operations v9fs_dir_inode_operations_ext;
47 static struct inode_operations v9fs_file_inode_operations;
48 static 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 (v9ses->extended) {
65 res |= V9FS_DMSYMLINK;
66 if (v9ses->nodev == 0) {
70 res |= V9FS_DMNAMEDPIPE;
77 if ((mode & S_ISUID) == S_ISUID)
79 if ((mode & S_ISGID) == S_ISGID)
81 if ((mode & V9FS_DMLINK))
89 * p9mode2unixmode- convert plan9 mode bits to unix mode bits
90 * @v9ses: v9fs session information
91 * @mode: mode to convert
95 static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
101 if ((mode & V9FS_DMDIR) == V9FS_DMDIR)
103 else if ((mode & V9FS_DMSYMLINK) && (v9ses->extended))
105 else if ((mode & V9FS_DMSOCKET) && (v9ses->extended)
106 && (v9ses->nodev == 0))
108 else if ((mode & V9FS_DMNAMEDPIPE) && (v9ses->extended)
109 && (v9ses->nodev == 0))
111 else if ((mode & V9FS_DMDEVICE) && (v9ses->extended)
112 && (v9ses->nodev == 0))
117 if (v9ses->extended) {
118 if ((mode & V9FS_DMSETUID) == V9FS_DMSETUID)
121 if ((mode & V9FS_DMSETGID) == V9FS_DMSETGID)
128 int v9fs_uflags2omode(int uflags)
151 if (uflags & O_TRUNC)
154 if (uflags & O_APPEND)
161 * v9fs_blank_wstat - helper function to setup a 9P stat structure
162 * @v9ses: 9P session info (for determining extended mode)
163 * @wstat: structure to initialize
168 v9fs_blank_wstat(struct v9fs_wstat *wstat)
172 wstat->qid.type = ~0;
173 wstat->qid.version = ~0;
174 *((long long *)&wstat->qid.path) = ~0;
186 wstat->extension = NULL;
190 * v9fs_get_inode - helper function to setup an inode
192 * @mode: mode to setup inode with
196 struct inode *v9fs_get_inode(struct super_block *sb, int mode)
199 struct v9fs_session_info *v9ses = sb->s_fs_info;
201 dprintk(DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
203 inode = new_inode(sb);
205 inode->i_mode = mode;
206 inode->i_uid = current->fsuid;
207 inode->i_gid = current->fsgid;
208 inode->i_blksize = sb->s_blocksize;
211 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
212 inode->i_mapping->a_ops = &v9fs_addr_operations;
214 switch (mode & S_IFMT) {
219 if(!v9ses->extended) {
220 dprintk(DEBUG_ERROR, "special files without extended mode\n");
221 return ERR_PTR(-EINVAL);
223 init_special_inode(inode, inode->i_mode,
227 inode->i_op = &v9fs_file_inode_operations;
228 inode->i_fop = &v9fs_file_operations;
231 if(!v9ses->extended) {
232 dprintk(DEBUG_ERROR, "extended modes used w/o 9P2000.u\n");
233 return ERR_PTR(-EINVAL);
235 inode->i_op = &v9fs_symlink_inode_operations;
240 inode->i_op = &v9fs_dir_inode_operations_ext;
242 inode->i_op = &v9fs_dir_inode_operations;
243 inode->i_fop = &v9fs_dir_operations;
246 dprintk(DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n",
247 mode, mode & S_IFMT);
248 return ERR_PTR(-EINVAL);
251 eprintk(KERN_WARNING, "Problem allocating inode\n");
252 return ERR_PTR(-ENOMEM);
258 v9fs_create(struct v9fs_session_info *v9ses, u32 pfid, char *name,
259 u32 perm, u8 mode, u32 *fidp, struct v9fs_qid *qid, u32 *iounit)
263 struct v9fs_fcall *fcall;
265 fid = v9fs_get_idpool(&v9ses->fidpool);
267 eprintk(KERN_WARNING, "no free fids available\n");
272 err = v9fs_t_walk(v9ses, pfid, fid, NULL, &fcall);
274 PRINT_FCALL_ERROR("clone error", fcall);
279 err = v9fs_t_create(v9ses, fid, name, perm, mode, &fcall);
281 PRINT_FCALL_ERROR("create fails", fcall);
286 *iounit = fcall->params.rcreate.iounit;
289 *qid = fcall->params.rcreate.qid;
299 v9fs_put_idpool(fid, &v9ses->fidpool);
305 static struct v9fs_fid*
306 v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry)
310 struct v9fs_fid *ret;
311 struct v9fs_fcall *fcall;
313 nfid = v9fs_get_idpool(&v9ses->fidpool);
315 eprintk(KERN_WARNING, "no free fids available\n");
320 err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name,
324 PRINT_FCALL_ERROR("walk error", fcall);
325 v9fs_put_idpool(nfid, &v9ses->fidpool);
331 ret = v9fs_fid_create(v9ses, nfid);
337 err = v9fs_fid_insert(ret, dentry);
339 v9fs_fid_destroy(ret);
346 v9fs_t_clunk(v9ses, nfid);
354 v9fs_inode_from_fid(struct v9fs_session_info *v9ses, u32 fid,
355 struct super_block *sb)
359 struct v9fs_fcall *fcall;
362 err = v9fs_t_stat(v9ses, fid, &fcall);
364 PRINT_FCALL_ERROR("stat error", fcall);
368 umode = p9mode2unixmode(v9ses, fcall->params.rstat.stat.mode);
369 ret = v9fs_get_inode(sb, umode);
376 v9fs_stat2inode(&fcall->params.rstat.stat, ret, sb);
389 * v9fs_remove - helper function to remove files and directories
390 * @dir: directory inode that is being deleted
391 * @file: dentry that is being deleted
392 * @rmdir: removing a directory
396 static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
398 struct v9fs_fcall *fcall = NULL;
399 struct super_block *sb = NULL;
400 struct v9fs_session_info *v9ses = NULL;
401 struct v9fs_fid *v9fid = NULL;
402 struct inode *file_inode = NULL;
406 dprintk(DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file,
409 file_inode = file->d_inode;
410 sb = file_inode->i_sb;
411 v9ses = v9fs_inode2v9ses(file_inode);
412 v9fid = v9fs_fid_lookup(file);
422 dprintk(DEBUG_ERROR, "inode #%lu, no fid!\n",
427 result = v9fs_t_remove(v9ses, fid, &fcall);
429 PRINT_FCALL_ERROR("remove fails", fcall);
431 v9fs_put_idpool(fid, &v9ses->fidpool);
432 v9fs_fid_destroy(v9fid);
440 v9fs_open_created(struct inode *inode, struct file *file)
446 * v9fs_vfs_create - VFS hook to create files
447 * @inode: directory inode that is being deleted
448 * @dentry: dentry that is being deleted
449 * @mode: create permissions
450 * @nd: path information
455 v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
456 struct nameidata *nd)
459 u32 fid, perm, iounit;
461 struct v9fs_session_info *v9ses;
462 struct v9fs_fid *dfid, *vfid, *ffid;
469 v9ses = v9fs_inode2v9ses(dir);
470 dfid = v9fs_fid_lookup(dentry->d_parent);
471 perm = unixmode2p9mode(v9ses, mode);
473 if (nd && nd->flags & LOOKUP_OPEN)
474 flags = nd->intent.open.flags - 1;
478 err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name,
479 perm, v9fs_uflags2omode(flags), &fid, &qid, &iounit);
484 vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry);
491 inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb);
493 err = PTR_ERR(inode);
498 dentry->d_op = &v9fs_dentry_operations;
499 d_instantiate(dentry, inode);
501 if (nd && nd->flags & LOOKUP_OPEN) {
502 ffid = v9fs_fid_create(v9ses, fid);
506 filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created);
508 v9fs_fid_destroy(ffid);
509 return PTR_ERR(filp);
513 ffid->rdir_fcall = NULL;
515 ffid->iounit = iounit;
517 filp->private_data = ffid;
524 v9fs_fid_destroy(vfid);
533 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
534 * @inode: inode that is being unlinked
535 * @dentry: dentry that is being unlinked
536 * @mode: mode for new directory
540 static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
544 struct v9fs_session_info *v9ses;
545 struct v9fs_fid *dfid, *vfid;
550 v9ses = v9fs_inode2v9ses(dir);
551 dfid = v9fs_fid_lookup(dentry->d_parent);
552 perm = unixmode2p9mode(v9ses, mode | S_IFDIR);
554 err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name,
555 perm, V9FS_OREAD, &fid, NULL, NULL);
558 dprintk(DEBUG_ERROR, "create error %d\n", err);
562 err = v9fs_t_clunk(v9ses, fid);
564 dprintk(DEBUG_ERROR, "clunk error %d\n", err);
568 vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry);
575 inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb);
577 err = PTR_ERR(inode);
582 dentry->d_op = &v9fs_dentry_operations;
583 d_instantiate(dentry, inode);
588 v9fs_fid_destroy(vfid);
594 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
595 * @dir: inode that is being walked from
596 * @dentry: dentry that is being walked to?
597 * @nameidata: path data
601 static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
602 struct nameidata *nameidata)
604 struct super_block *sb;
605 struct v9fs_session_info *v9ses;
606 struct v9fs_fid *dirfid;
607 struct v9fs_fid *fid;
609 struct v9fs_fcall *fcall = NULL;
614 dprintk(DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n",
615 dir, dentry->d_iname, dentry, nameidata);
618 v9ses = v9fs_inode2v9ses(dir);
619 dirfid = v9fs_fid_lookup(dentry->d_parent);
622 dprintk(DEBUG_ERROR, "no dirfid\n");
623 return ERR_PTR(-EINVAL);
626 dirfidnum = dirfid->fid;
629 dprintk(DEBUG_ERROR, "no dirfid for inode %p, #%lu\n",
631 return ERR_PTR(-EBADF);
634 newfid = v9fs_get_idpool(&v9ses->fidpool);
636 eprintk(KERN_WARNING, "newfid fails!\n");
637 return ERR_PTR(-ENOSPC);
640 result = v9fs_t_walk(v9ses, dirfidnum, newfid,
641 (char *)dentry->d_name.name, NULL);
643 v9fs_put_idpool(newfid, &v9ses->fidpool);
644 if (result == -ENOENT) {
647 "Return negative dentry %p count %d\n",
648 dentry, atomic_read(&dentry->d_count));
651 dprintk(DEBUG_ERROR, "walk error:%d\n", result);
655 result = v9fs_t_stat(v9ses, newfid, &fcall);
657 dprintk(DEBUG_ERROR, "stat error\n");
661 inode = v9fs_get_inode(sb, p9mode2unixmode(v9ses,
662 fcall->params.rstat.stat.mode));
664 if (IS_ERR(inode) && (PTR_ERR(inode) == -ENOSPC)) {
665 eprintk(KERN_WARNING, "inode alloc failes, returns %ld\n",
672 inode->i_ino = v9fs_qid2ino(&fcall->params.rstat.stat.qid);
674 fid = v9fs_fid_create(v9ses, newfid);
676 dprintk(DEBUG_ERROR, "couldn't insert\n");
681 result = v9fs_fid_insert(fid, dentry);
685 fid->qid = fcall->params.rstat.stat.qid;
687 dentry->d_op = &v9fs_dentry_operations;
688 v9fs_stat2inode(&fcall->params.rstat.stat, inode, inode->i_sb);
690 d_add(dentry, inode);
697 return ERR_PTR(result);
701 * v9fs_vfs_unlink - VFS unlink hook to delete an inode
702 * @i: inode that is being unlinked
703 * @d: dentry that is being unlinked
707 static int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
709 return v9fs_remove(i, d, 0);
713 * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
714 * @i: inode that is being unlinked
715 * @d: dentry that is being unlinked
719 static int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
721 return v9fs_remove(i, d, 1);
725 * v9fs_vfs_rename - VFS hook to rename an inode
726 * @old_dir: old dir inode
727 * @old_dentry: old dentry
728 * @new_dir: new dir inode
729 * @new_dentry: new dentry
734 v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
735 struct inode *new_dir, struct dentry *new_dentry)
737 struct inode *old_inode = old_dentry->d_inode;
738 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(old_inode);
739 struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry);
740 struct v9fs_fid *olddirfid =
741 v9fs_fid_lookup(old_dentry->d_parent);
742 struct v9fs_fid *newdirfid =
743 v9fs_fid_lookup(new_dentry->d_parent);
744 struct v9fs_wstat wstat;
745 struct v9fs_fcall *fcall = NULL;
747 int olddirfidnum = -1;
748 int newdirfidnum = -1;
751 dprintk(DEBUG_VFS, "\n");
753 if ((!oldfid) || (!olddirfid) || (!newdirfid)) {
754 dprintk(DEBUG_ERROR, "problem with arguments\n");
758 /* 9P can only handle file rename in the same directory */
759 if (memcmp(&olddirfid->qid, &newdirfid->qid, sizeof(newdirfid->qid))) {
760 dprintk(DEBUG_ERROR, "old dir and new dir are different\n");
766 olddirfidnum = olddirfid->fid;
767 newdirfidnum = newdirfid->fid;
770 dprintk(DEBUG_ERROR, "no fid for old file #%lu\n",
776 v9fs_blank_wstat(&wstat);
777 wstat.muid = v9ses->name;
778 wstat.name = (char *) new_dentry->d_name.name;
780 retval = v9fs_t_wstat(v9ses, fid, &wstat, &fcall);
784 PRINT_FCALL_ERROR("wstat error", fcall);
791 * v9fs_vfs_getattr - retrieve file metadata
792 * @mnt - mount information
793 * @dentry - file to get attributes on
794 * @stat - metadata structure to populate
799 v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
802 struct v9fs_fcall *fcall = NULL;
803 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
804 struct v9fs_fid *fid = v9fs_fid_lookup(dentry);
807 dprintk(DEBUG_VFS, "dentry: %p\n", dentry);
810 "couldn't find fid associated with dentry\n");
814 err = v9fs_t_stat(v9ses, fid->fid, &fcall);
817 dprintk(DEBUG_ERROR, "stat error\n");
819 v9fs_stat2inode(&fcall->params.rstat.stat, dentry->d_inode,
820 dentry->d_inode->i_sb);
821 generic_fillattr(dentry->d_inode, stat);
829 * v9fs_vfs_setattr - set file metadata
830 * @dentry: file whose metadata to set
831 * @iattr: metadata assignment structure
835 static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
837 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
838 struct v9fs_fid *fid = v9fs_fid_lookup(dentry);
839 struct v9fs_fcall *fcall = NULL;
840 struct v9fs_wstat wstat;
843 dprintk(DEBUG_VFS, "\n");
847 "Couldn't find fid associated with dentry\n");
851 v9fs_blank_wstat(&wstat);
852 if (iattr->ia_valid & ATTR_MODE)
853 wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode);
855 if (iattr->ia_valid & ATTR_MTIME)
856 wstat.mtime = iattr->ia_mtime.tv_sec;
858 if (iattr->ia_valid & ATTR_ATIME)
859 wstat.atime = iattr->ia_atime.tv_sec;
861 if (iattr->ia_valid & ATTR_SIZE)
862 wstat.length = iattr->ia_size;
864 if (v9ses->extended) {
865 if (iattr->ia_valid & ATTR_UID)
866 wstat.n_uid = iattr->ia_uid;
868 if (iattr->ia_valid & ATTR_GID)
869 wstat.n_gid = iattr->ia_gid;
872 res = v9fs_t_wstat(v9ses, fid->fid, &wstat, &fcall);
875 PRINT_FCALL_ERROR("wstat error", fcall);
879 res = inode_setattr(dentry->d_inode, iattr);
885 * v9fs_stat2inode - populate an inode structure with mistat info
886 * @stat: Plan 9 metadata (mistat) structure
887 * @inode: inode to populate
888 * @sb: superblock of filesystem
893 v9fs_stat2inode(struct v9fs_stat *stat, struct inode *inode,
894 struct super_block *sb)
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->uid;
907 inode->i_gid = v9ses->gid;
909 if (v9ses->extended) {
910 inode->i_uid = stat->n_uid;
911 inode->i_gid = stat->n_gid;
914 inode->i_mode = p9mode2unixmode(v9ses, stat->mode);
915 if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) {
920 n = stat->extension.len;
921 if (n > sizeof(ext)-1)
923 memmove(ext, stat->extension.str, n);
925 sscanf(ext, "%c %u %u", &type, &major, &minor);
928 inode->i_mode &= ~S_IFBLK;
929 inode->i_mode |= S_IFCHR;
934 dprintk(DEBUG_ERROR, "Unknown special type %c (%.*s)\n",
935 type, stat->extension.len, stat->extension.str);
937 inode->i_rdev = MKDEV(major, minor);
941 inode->i_size = stat->length;
943 inode->i_blksize = sb->s_blocksize;
945 (inode->i_size + inode->i_blksize - 1) >> sb->s_blocksize_bits;
949 * v9fs_qid2ino - convert qid into inode number
952 * BUG: potential for inode number collisions?
955 ino_t v9fs_qid2ino(struct v9fs_qid *qid)
957 u64 path = qid->path + 2;
960 if (sizeof(ino_t) == sizeof(path))
961 memcpy(&i, &path, sizeof(ino_t));
963 i = (ino_t) (path ^ (path >> 32));
969 * v9fs_readlink - read a symlink's location (internal version)
970 * @dentry: dentry for symlink
971 * @buffer: buffer to load symlink location into
972 * @buflen: length of buffer
976 static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
980 struct v9fs_fcall *fcall = NULL;
981 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
982 struct v9fs_fid *fid = v9fs_fid_lookup(dentry);
985 dprintk(DEBUG_ERROR, "could not resolve fid from dentry\n");
990 if (!v9ses->extended) {
992 dprintk(DEBUG_ERROR, "not extended\n");
996 dprintk(DEBUG_VFS, " %s\n", dentry->d_name.name);
997 retval = v9fs_t_stat(v9ses, fid->fid, &fcall);
1000 dprintk(DEBUG_ERROR, "stat error\n");
1007 if (!(fcall->params.rstat.stat.mode & V9FS_DMSYMLINK)) {
1012 /* copy extension buffer into buffer */
1013 if (fcall->params.rstat.stat.extension.len < buflen)
1014 buflen = fcall->params.rstat.stat.extension.len;
1016 memcpy(buffer, fcall->params.rstat.stat.extension.str, buflen - 1);
1017 buffer[buflen-1] = 0;
1028 * v9fs_vfs_readlink - read a symlink's location
1029 * @dentry: dentry for symlink
1030 * @buf: buffer to load symlink location into
1031 * @buflen: length of buffer
1035 static int v9fs_vfs_readlink(struct dentry *dentry, char __user * buffer,
1040 char *link = __getname();
1042 if (buflen > PATH_MAX)
1045 dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
1047 retval = v9fs_readlink(dentry, link, buflen);
1050 if ((ret = copy_to_user(buffer, link, retval)) != 0) {
1051 dprintk(DEBUG_ERROR, "problem copying to user: %d\n",
1062 * v9fs_vfs_follow_link - follow a symlink path
1063 * @dentry: dentry for symlink
1068 static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
1071 char *link = __getname();
1073 dprintk(DEBUG_VFS, "%s n", dentry->d_name.name);
1076 link = ERR_PTR(-ENOMEM);
1078 len = v9fs_readlink(dentry, link, strlen(link));
1082 link = ERR_PTR(len);
1086 nd_set_link(nd, link);
1092 * v9fs_vfs_put_link - release a symlink path
1093 * @dentry: dentry for symlink
1098 static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
1100 char *s = nd_get_link(nd);
1102 dprintk(DEBUG_VFS, " %s %s\n", dentry->d_name.name, s);
1107 static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
1108 int mode, const char *extension)
1112 struct v9fs_session_info *v9ses;
1113 struct v9fs_fid *dfid, *vfid;
1114 struct inode *inode;
1115 struct v9fs_fcall *fcall;
1116 struct v9fs_wstat wstat;
1121 v9ses = v9fs_inode2v9ses(dir);
1122 dfid = v9fs_fid_lookup(dentry->d_parent);
1123 perm = unixmode2p9mode(v9ses, mode);
1125 if (!v9ses->extended) {
1126 dprintk(DEBUG_ERROR, "not extended\n");
1130 err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name,
1131 perm, V9FS_OREAD, &fid, NULL, NULL);
1136 err = v9fs_t_clunk(v9ses, fid);
1140 vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry);
1142 err = PTR_ERR(vfid);
1147 inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb);
1148 if (IS_ERR(inode)) {
1149 err = PTR_ERR(inode);
1154 /* issue a Twstat */
1155 v9fs_blank_wstat(&wstat);
1156 wstat.muid = v9ses->name;
1157 wstat.extension = (char *) extension;
1158 err = v9fs_t_wstat(v9ses, vfid->fid, &wstat, &fcall);
1160 PRINT_FCALL_ERROR("wstat error", fcall);
1165 dentry->d_op = &v9fs_dentry_operations;
1166 d_instantiate(dentry, inode);
1172 v9fs_fid_destroy(vfid);
1182 * v9fs_vfs_symlink - helper function to create symlinks
1183 * @dir: directory inode containing symlink
1184 * @dentry: dentry for symlink
1185 * @symname: symlink data
1187 * See 9P2000.u RFC for more information
1192 v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
1194 dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
1197 return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname);
1201 * v9fs_vfs_link - create a hardlink
1202 * @old_dentry: dentry for file to link to
1203 * @dir: inode destination for new link
1204 * @dentry: dentry for link
1208 /* XXX - lots of code dup'd from symlink and creates,
1209 * figure out a better reuse strategy
1213 v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1214 struct dentry *dentry)
1217 struct v9fs_fid *oldfid;
1220 dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
1221 old_dentry->d_name.name);
1223 oldfid = v9fs_fid_lookup(old_dentry);
1225 dprintk(DEBUG_ERROR, "can't find oldfid\n");
1230 sprintf(name, "hardlink(%d)\n", oldfid->fid);
1231 retval = v9fs_vfs_mkspecial(dir, dentry, V9FS_DMLINK, name);
1238 * v9fs_vfs_mknod - create a special file
1239 * @dir: inode destination for new link
1240 * @dentry: dentry for file
1241 * @mode: mode for creation
1242 * @dev_t: device associated with special file
1247 v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1252 dprintk(DEBUG_VFS, " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
1253 dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev));
1255 if (!new_valid_dev(rdev))
1259 /* build extension */
1261 sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev));
1262 else if (S_ISCHR(mode))
1263 sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev));
1264 else if (S_ISFIFO(mode))
1271 retval = v9fs_vfs_mkspecial(dir, dentry, mode, name);
1277 static struct inode_operations v9fs_dir_inode_operations_ext = {
1278 .create = v9fs_vfs_create,
1279 .lookup = v9fs_vfs_lookup,
1280 .symlink = v9fs_vfs_symlink,
1281 .link = v9fs_vfs_link,
1282 .unlink = v9fs_vfs_unlink,
1283 .mkdir = v9fs_vfs_mkdir,
1284 .rmdir = v9fs_vfs_rmdir,
1285 .mknod = v9fs_vfs_mknod,
1286 .rename = v9fs_vfs_rename,
1287 .readlink = v9fs_vfs_readlink,
1288 .getattr = v9fs_vfs_getattr,
1289 .setattr = v9fs_vfs_setattr,
1292 static struct inode_operations v9fs_dir_inode_operations = {
1293 .create = v9fs_vfs_create,
1294 .lookup = v9fs_vfs_lookup,
1295 .unlink = v9fs_vfs_unlink,
1296 .mkdir = v9fs_vfs_mkdir,
1297 .rmdir = v9fs_vfs_rmdir,
1298 .mknod = v9fs_vfs_mknod,
1299 .rename = v9fs_vfs_rename,
1300 .getattr = v9fs_vfs_getattr,
1301 .setattr = v9fs_vfs_setattr,
1304 static struct inode_operations v9fs_file_inode_operations = {
1305 .getattr = v9fs_vfs_getattr,
1306 .setattr = v9fs_vfs_setattr,
1309 static struct inode_operations v9fs_symlink_inode_operations = {
1310 .readlink = v9fs_vfs_readlink,
1311 .follow_link = v9fs_vfs_follow_link,
1312 .put_link = v9fs_vfs_put_link,
1313 .getattr = v9fs_vfs_getattr,
1314 .setattr = v9fs_vfs_setattr,