2 * linux/fs/9p/vfs_inode.c
4 * This file contains vfs inode ops for the 9P2000 protocol.
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, u32 perm,
259 u8 mode, char *extension, 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");
271 err = v9fs_t_walk(v9ses, pfid, fid, NULL, &fcall);
273 PRINT_FCALL_ERROR("clone error", fcall);
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);
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 PRINT_FCALL_ERROR("walk error", fcall);
327 v9fs_put_idpool(nfid, &v9ses->fidpool);
333 ret = v9fs_fid_create(v9ses, nfid);
339 err = v9fs_fid_insert(ret, dentry);
341 v9fs_fid_destroy(ret);
348 v9fs_t_clunk(v9ses, nfid);
355 static struct inode *
356 v9fs_inode_from_fid(struct v9fs_session_info *v9ses, u32 fid,
357 struct super_block *sb)
361 struct v9fs_fcall *fcall;
364 err = v9fs_t_stat(v9ses, fid, &fcall);
366 PRINT_FCALL_ERROR("stat error", fcall);
370 umode = p9mode2unixmode(v9ses, fcall->params.rstat.stat.mode);
371 ret = v9fs_get_inode(sb, umode);
378 v9fs_stat2inode(&fcall->params.rstat.stat, ret, sb);
391 * v9fs_remove - helper function to remove files and directories
392 * @dir: directory inode that is being deleted
393 * @file: dentry that is being deleted
394 * @rmdir: removing a directory
398 static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
400 struct v9fs_fcall *fcall = NULL;
401 struct super_block *sb = NULL;
402 struct v9fs_session_info *v9ses = NULL;
403 struct v9fs_fid *v9fid = NULL;
404 struct inode *file_inode = NULL;
408 dprintk(DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file,
411 file_inode = file->d_inode;
412 sb = file_inode->i_sb;
413 v9ses = v9fs_inode2v9ses(file_inode);
414 v9fid = v9fs_fid_lookup(file);
424 dprintk(DEBUG_ERROR, "inode #%lu, no fid!\n",
429 result = v9fs_t_remove(v9ses, fid, &fcall);
431 PRINT_FCALL_ERROR("remove fails", fcall);
433 v9fs_put_idpool(fid, &v9ses->fidpool);
434 v9fs_fid_destroy(v9fid);
442 v9fs_open_created(struct inode *inode, struct file *file)
448 * v9fs_vfs_create - VFS hook to create files
449 * @inode: directory inode that is being deleted
450 * @dentry: dentry that is being deleted
451 * @mode: create permissions
452 * @nd: path information
457 v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
458 struct nameidata *nd)
461 u32 fid, perm, iounit;
463 struct v9fs_session_info *v9ses;
464 struct v9fs_fid *dfid, *vfid, *ffid;
471 v9ses = v9fs_inode2v9ses(dir);
472 dfid = v9fs_fid_lookup(dentry->d_parent);
473 perm = unixmode2p9mode(v9ses, mode);
475 if (nd && nd->flags & LOOKUP_OPEN)
476 flags = nd->intent.open.flags - 1;
480 err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name,
481 perm, v9fs_uflags2omode(flags), NULL, &fid, &qid, &iounit);
486 vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry);
493 inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb);
495 err = PTR_ERR(inode);
500 dentry->d_op = &v9fs_dentry_operations;
501 d_instantiate(dentry, inode);
503 if (nd && nd->flags & LOOKUP_OPEN) {
504 ffid = v9fs_fid_create(v9ses, fid);
508 filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created);
510 v9fs_fid_destroy(ffid);
511 return PTR_ERR(filp);
515 ffid->rdir_fcall = NULL;
517 ffid->iounit = iounit;
519 filp->private_data = ffid;
526 v9fs_fid_destroy(vfid);
535 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
536 * @inode: inode that is being unlinked
537 * @dentry: dentry that is being unlinked
538 * @mode: mode for new directory
542 static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
546 struct v9fs_session_info *v9ses;
547 struct v9fs_fid *dfid, *vfid;
552 v9ses = v9fs_inode2v9ses(dir);
553 dfid = v9fs_fid_lookup(dentry->d_parent);
554 perm = unixmode2p9mode(v9ses, mode | S_IFDIR);
556 err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name,
557 perm, V9FS_OREAD, NULL, &fid, NULL, NULL);
560 dprintk(DEBUG_ERROR, "create error %d\n", err);
564 err = v9fs_t_clunk(v9ses, fid);
566 dprintk(DEBUG_ERROR, "clunk error %d\n", err);
570 vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry);
577 inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb);
579 err = PTR_ERR(inode);
584 dentry->d_op = &v9fs_dentry_operations;
585 d_instantiate(dentry, inode);
590 v9fs_fid_destroy(vfid);
596 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
597 * @dir: inode that is being walked from
598 * @dentry: dentry that is being walked to?
599 * @nameidata: path data
603 static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
604 struct nameidata *nameidata)
606 struct super_block *sb;
607 struct v9fs_session_info *v9ses;
608 struct v9fs_fid *dirfid;
609 struct v9fs_fid *fid;
611 struct v9fs_fcall *fcall = NULL;
616 dprintk(DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n",
617 dir, dentry->d_name.name, dentry, nameidata);
620 v9ses = v9fs_inode2v9ses(dir);
621 dentry->d_op = &v9fs_dentry_operations;
622 dirfid = v9fs_fid_lookup(dentry->d_parent);
625 dprintk(DEBUG_ERROR, "no dirfid\n");
626 return ERR_PTR(-EINVAL);
629 dirfidnum = dirfid->fid;
632 dprintk(DEBUG_ERROR, "no dirfid for inode %p, #%lu\n",
634 return ERR_PTR(-EBADF);
637 newfid = v9fs_get_idpool(&v9ses->fidpool);
639 eprintk(KERN_WARNING, "newfid fails!\n");
640 return ERR_PTR(-ENOSPC);
643 result = v9fs_t_walk(v9ses, dirfidnum, newfid,
644 (char *)dentry->d_name.name, NULL);
646 v9fs_put_idpool(newfid, &v9ses->fidpool);
647 if (result == -ENOENT) {
650 "Return negative dentry %p count %d\n",
651 dentry, atomic_read(&dentry->d_count));
654 dprintk(DEBUG_ERROR, "walk error:%d\n", result);
658 result = v9fs_t_stat(v9ses, newfid, &fcall);
660 dprintk(DEBUG_ERROR, "stat error\n");
664 inode = v9fs_get_inode(sb, p9mode2unixmode(v9ses,
665 fcall->params.rstat.stat.mode));
667 if (IS_ERR(inode) && (PTR_ERR(inode) == -ENOSPC)) {
668 eprintk(KERN_WARNING, "inode alloc failes, returns %ld\n",
675 inode->i_ino = v9fs_qid2ino(&fcall->params.rstat.stat.qid);
677 fid = v9fs_fid_create(v9ses, newfid);
679 dprintk(DEBUG_ERROR, "couldn't insert\n");
684 result = v9fs_fid_insert(fid, dentry);
688 fid->qid = fcall->params.rstat.stat.qid;
689 v9fs_stat2inode(&fcall->params.rstat.stat, inode, inode->i_sb);
691 d_add(dentry, inode);
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 = old_dentry->d_inode;
739 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(old_inode);
740 struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry);
741 struct v9fs_fid *olddirfid =
742 v9fs_fid_lookup(old_dentry->d_parent);
743 struct v9fs_fid *newdirfid =
744 v9fs_fid_lookup(new_dentry->d_parent);
745 struct v9fs_wstat wstat;
746 struct v9fs_fcall *fcall = NULL;
748 int olddirfidnum = -1;
749 int newdirfidnum = -1;
752 dprintk(DEBUG_VFS, "\n");
754 if ((!oldfid) || (!olddirfid) || (!newdirfid)) {
755 dprintk(DEBUG_ERROR, "problem with arguments\n");
759 /* 9P can only handle file rename in the same directory */
760 if (memcmp(&olddirfid->qid, &newdirfid->qid, sizeof(newdirfid->qid))) {
761 dprintk(DEBUG_ERROR, "old dir and new dir are different\n");
767 olddirfidnum = olddirfid->fid;
768 newdirfidnum = newdirfid->fid;
771 dprintk(DEBUG_ERROR, "no fid for old file #%lu\n",
777 v9fs_blank_wstat(&wstat);
778 wstat.muid = v9ses->name;
779 wstat.name = (char *) new_dentry->d_name.name;
781 retval = v9fs_t_wstat(v9ses, fid, &wstat, &fcall);
785 PRINT_FCALL_ERROR("wstat error", fcall);
792 * v9fs_vfs_getattr - retrieve file metadata
793 * @mnt - mount information
794 * @dentry - file to get attributes on
795 * @stat - metadata structure to populate
800 v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
803 struct v9fs_fcall *fcall = NULL;
804 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
805 struct v9fs_fid *fid = v9fs_fid_lookup(dentry);
808 dprintk(DEBUG_VFS, "dentry: %p\n", dentry);
811 "couldn't find fid associated with dentry\n");
815 err = v9fs_t_stat(v9ses, fid->fid, &fcall);
818 dprintk(DEBUG_ERROR, "stat error\n");
820 v9fs_stat2inode(&fcall->params.rstat.stat, dentry->d_inode,
821 dentry->d_inode->i_sb);
822 generic_fillattr(dentry->d_inode, stat);
830 * v9fs_vfs_setattr - set file metadata
831 * @dentry: file whose metadata to set
832 * @iattr: metadata assignment structure
836 static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
838 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
839 struct v9fs_fid *fid = v9fs_fid_lookup(dentry);
840 struct v9fs_fcall *fcall = NULL;
841 struct v9fs_wstat wstat;
844 dprintk(DEBUG_VFS, "\n");
848 "Couldn't find fid associated with dentry\n");
852 v9fs_blank_wstat(&wstat);
853 if (iattr->ia_valid & ATTR_MODE)
854 wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode);
856 if (iattr->ia_valid & ATTR_MTIME)
857 wstat.mtime = iattr->ia_mtime.tv_sec;
859 if (iattr->ia_valid & ATTR_ATIME)
860 wstat.atime = iattr->ia_atime.tv_sec;
862 if (iattr->ia_valid & ATTR_SIZE)
863 wstat.length = iattr->ia_size;
865 if (v9ses->extended) {
866 if (iattr->ia_valid & ATTR_UID)
867 wstat.n_uid = iattr->ia_uid;
869 if (iattr->ia_valid & ATTR_GID)
870 wstat.n_gid = iattr->ia_gid;
873 res = v9fs_t_wstat(v9ses, fid->fid, &wstat, &fcall);
876 PRINT_FCALL_ERROR("wstat error", fcall);
880 res = 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 v9fs_stat *stat, struct inode *inode,
895 struct super_block *sb)
899 struct v9fs_session_info *v9ses = sb->s_fs_info;
903 inode->i_atime.tv_sec = stat->atime;
904 inode->i_mtime.tv_sec = stat->mtime;
905 inode->i_ctime.tv_sec = stat->mtime;
907 inode->i_uid = v9ses->uid;
908 inode->i_gid = v9ses->gid;
910 if (v9ses->extended) {
911 inode->i_uid = stat->n_uid;
912 inode->i_gid = stat->n_gid;
915 inode->i_mode = p9mode2unixmode(v9ses, stat->mode);
916 if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) {
921 n = stat->extension.len;
922 if (n > sizeof(ext)-1)
924 memmove(ext, stat->extension.str, n);
926 sscanf(ext, "%c %u %u", &type, &major, &minor);
929 inode->i_mode &= ~S_IFBLK;
930 inode->i_mode |= S_IFCHR;
935 dprintk(DEBUG_ERROR, "Unknown special type %c (%.*s)\n",
936 type, stat->extension.len, stat->extension.str);
938 inode->i_rdev = MKDEV(major, minor);
942 inode->i_size = stat->length;
944 inode->i_blksize = sb->s_blocksize;
946 (inode->i_size + inode->i_blksize - 1) >> sb->s_blocksize_bits;
950 * v9fs_qid2ino - convert qid into inode number
953 * BUG: potential for inode number collisions?
956 ino_t v9fs_qid2ino(struct v9fs_qid *qid)
958 u64 path = qid->path + 2;
961 if (sizeof(ino_t) == sizeof(path))
962 memcpy(&i, &path, sizeof(ino_t));
964 i = (ino_t) (path ^ (path >> 32));
970 * v9fs_readlink - read a symlink's location (internal version)
971 * @dentry: dentry for symlink
972 * @buffer: buffer to load symlink location into
973 * @buflen: length of buffer
977 static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
981 struct v9fs_fcall *fcall = NULL;
982 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
983 struct v9fs_fid *fid = v9fs_fid_lookup(dentry);
986 dprintk(DEBUG_ERROR, "could not resolve fid from dentry\n");
991 if (!v9ses->extended) {
993 dprintk(DEBUG_ERROR, "not extended\n");
997 dprintk(DEBUG_VFS, " %s\n", dentry->d_name.name);
998 retval = v9fs_t_stat(v9ses, fid->fid, &fcall);
1001 dprintk(DEBUG_ERROR, "stat error\n");
1008 if (!(fcall->params.rstat.stat.mode & V9FS_DMSYMLINK)) {
1013 /* copy extension buffer into buffer */
1014 if (fcall->params.rstat.stat.extension.len < buflen)
1015 buflen = fcall->params.rstat.stat.extension.len + 1;
1017 memmove(buffer, fcall->params.rstat.stat.extension.str, buflen - 1);
1018 buffer[buflen-1] = 0;
1020 dprintk(DEBUG_ERROR, "%s -> %.*s (%s)\n", dentry->d_name.name, fcall->params.rstat.stat.extension.len,
1021 fcall->params.rstat.stat.extension.str, buffer);
1031 * v9fs_vfs_readlink - read a symlink's location
1032 * @dentry: dentry for symlink
1033 * @buf: buffer to load symlink location into
1034 * @buflen: length of buffer
1038 static int v9fs_vfs_readlink(struct dentry *dentry, char __user * buffer,
1043 char *link = __getname();
1045 if (buflen > PATH_MAX)
1048 dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
1050 retval = v9fs_readlink(dentry, link, buflen);
1053 if ((ret = copy_to_user(buffer, link, retval)) != 0) {
1054 dprintk(DEBUG_ERROR, "problem copying to user: %d\n",
1065 * v9fs_vfs_follow_link - follow a symlink path
1066 * @dentry: dentry for symlink
1071 static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
1074 char *link = __getname();
1076 dprintk(DEBUG_VFS, "%s n", dentry->d_name.name);
1079 link = ERR_PTR(-ENOMEM);
1081 len = v9fs_readlink(dentry, link, PATH_MAX);
1085 link = ERR_PTR(len);
1089 nd_set_link(nd, link);
1095 * v9fs_vfs_put_link - release a symlink path
1096 * @dentry: dentry for symlink
1101 static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
1103 char *s = nd_get_link(nd);
1105 dprintk(DEBUG_VFS, " %s %s\n", dentry->d_name.name, s);
1110 static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
1111 int mode, const char *extension)
1115 struct v9fs_session_info *v9ses;
1116 struct v9fs_fid *dfid, *vfid;
1117 struct inode *inode;
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, (char *) extension, &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 dentry->d_op = &v9fs_dentry_operations;
1155 d_instantiate(dentry, inode);
1160 v9fs_fid_destroy(vfid);
1170 * v9fs_vfs_symlink - helper function to create symlinks
1171 * @dir: directory inode containing symlink
1172 * @dentry: dentry for symlink
1173 * @symname: symlink data
1175 * See 9P2000.u RFC for more information
1180 v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
1182 dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
1185 return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname);
1189 * v9fs_vfs_link - create a hardlink
1190 * @old_dentry: dentry for file to link to
1191 * @dir: inode destination for new link
1192 * @dentry: dentry for link
1196 /* XXX - lots of code dup'd from symlink and creates,
1197 * figure out a better reuse strategy
1201 v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1202 struct dentry *dentry)
1205 struct v9fs_fid *oldfid;
1208 dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
1209 old_dentry->d_name.name);
1211 oldfid = v9fs_fid_lookup(old_dentry);
1213 dprintk(DEBUG_ERROR, "can't find oldfid\n");
1218 sprintf(name, "%d\n", oldfid->fid);
1219 retval = v9fs_vfs_mkspecial(dir, dentry, V9FS_DMLINK, name);
1226 * v9fs_vfs_mknod - create a special file
1227 * @dir: inode destination for new link
1228 * @dentry: dentry for file
1229 * @mode: mode for creation
1230 * @dev_t: device associated with special file
1235 v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1240 dprintk(DEBUG_VFS, " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
1241 dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev));
1243 if (!new_valid_dev(rdev))
1249 /* build extension */
1251 sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev));
1252 else if (S_ISCHR(mode))
1253 sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev));
1254 else if (S_ISFIFO(mode))
1261 retval = v9fs_vfs_mkspecial(dir, dentry, mode, name);
1267 static struct inode_operations v9fs_dir_inode_operations_ext = {
1268 .create = v9fs_vfs_create,
1269 .lookup = v9fs_vfs_lookup,
1270 .symlink = v9fs_vfs_symlink,
1271 .link = v9fs_vfs_link,
1272 .unlink = v9fs_vfs_unlink,
1273 .mkdir = v9fs_vfs_mkdir,
1274 .rmdir = v9fs_vfs_rmdir,
1275 .mknod = v9fs_vfs_mknod,
1276 .rename = v9fs_vfs_rename,
1277 .readlink = v9fs_vfs_readlink,
1278 .getattr = v9fs_vfs_getattr,
1279 .setattr = v9fs_vfs_setattr,
1282 static struct inode_operations v9fs_dir_inode_operations = {
1283 .create = v9fs_vfs_create,
1284 .lookup = v9fs_vfs_lookup,
1285 .unlink = v9fs_vfs_unlink,
1286 .mkdir = v9fs_vfs_mkdir,
1287 .rmdir = v9fs_vfs_rmdir,
1288 .mknod = v9fs_vfs_mknod,
1289 .rename = v9fs_vfs_rename,
1290 .getattr = v9fs_vfs_getattr,
1291 .setattr = v9fs_vfs_setattr,
1294 static struct inode_operations v9fs_file_inode_operations = {
1295 .getattr = v9fs_vfs_getattr,
1296 .setattr = v9fs_vfs_setattr,
1299 static struct inode_operations v9fs_symlink_inode_operations = {
1300 .readlink = v9fs_vfs_readlink,
1301 .follow_link = v9fs_vfs_follow_link,
1302 .put_link = v9fs_vfs_put_link,
1303 .getattr = v9fs_vfs_getattr,
1304 .setattr = v9fs_vfs_setattr,