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>
44 static const struct inode_operations v9fs_dir_inode_operations;
45 static const struct inode_operations v9fs_dir_inode_operations_ext;
46 static const struct inode_operations v9fs_file_inode_operations;
47 static const struct inode_operations v9fs_symlink_inode_operations;
50 * unixmode2p9mode - convert unix mode bits to plan 9
51 * @v9ses: v9fs session information
52 * @mode: mode to convert
56 static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode)
62 if (v9ses->extended) {
64 res |= V9FS_DMSYMLINK;
65 if (v9ses->nodev == 0) {
69 res |= V9FS_DMNAMEDPIPE;
76 if ((mode & S_ISUID) == S_ISUID)
78 if ((mode & S_ISGID) == S_ISGID)
80 if ((mode & V9FS_DMLINK))
88 * p9mode2unixmode- convert plan9 mode bits to unix mode bits
89 * @v9ses: v9fs session information
90 * @mode: mode to convert
94 static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
100 if ((mode & V9FS_DMDIR) == V9FS_DMDIR)
102 else if ((mode & V9FS_DMSYMLINK) && (v9ses->extended))
104 else if ((mode & V9FS_DMSOCKET) && (v9ses->extended)
105 && (v9ses->nodev == 0))
107 else if ((mode & V9FS_DMNAMEDPIPE) && (v9ses->extended)
108 && (v9ses->nodev == 0))
110 else if ((mode & V9FS_DMDEVICE) && (v9ses->extended)
111 && (v9ses->nodev == 0))
116 if (v9ses->extended) {
117 if ((mode & V9FS_DMSETUID) == V9FS_DMSETUID)
120 if ((mode & V9FS_DMSETGID) == V9FS_DMSETGID)
127 int v9fs_uflags2omode(int uflags)
150 if (uflags & O_TRUNC)
153 if (uflags & O_APPEND)
160 * v9fs_blank_wstat - helper function to setup a 9P stat structure
161 * @v9ses: 9P session info (for determining extended mode)
162 * @wstat: structure to initialize
167 v9fs_blank_wstat(struct v9fs_wstat *wstat)
171 wstat->qid.type = ~0;
172 wstat->qid.version = ~0;
173 *((long long *)&wstat->qid.path) = ~0;
185 wstat->extension = NULL;
189 * v9fs_get_inode - helper function to setup an inode
191 * @mode: mode to setup inode with
195 struct inode *v9fs_get_inode(struct super_block *sb, int mode)
198 struct v9fs_session_info *v9ses = sb->s_fs_info;
200 dprintk(DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
202 inode = new_inode(sb);
204 inode->i_mode = mode;
205 inode->i_uid = current->fsuid;
206 inode->i_gid = current->fsgid;
209 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
210 inode->i_mapping->a_ops = &v9fs_addr_operations;
212 switch (mode & S_IFMT) {
217 if(!v9ses->extended) {
218 dprintk(DEBUG_ERROR, "special files without extended mode\n");
219 return ERR_PTR(-EINVAL);
221 init_special_inode(inode, inode->i_mode,
225 inode->i_op = &v9fs_file_inode_operations;
226 inode->i_fop = &v9fs_file_operations;
229 if(!v9ses->extended) {
230 dprintk(DEBUG_ERROR, "extended modes used w/o 9P2000.u\n");
231 return ERR_PTR(-EINVAL);
233 inode->i_op = &v9fs_symlink_inode_operations;
238 inode->i_op = &v9fs_dir_inode_operations_ext;
240 inode->i_op = &v9fs_dir_inode_operations;
241 inode->i_fop = &v9fs_dir_operations;
244 dprintk(DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n",
245 mode, mode & S_IFMT);
246 return ERR_PTR(-EINVAL);
249 eprintk(KERN_WARNING, "Problem allocating inode\n");
250 return ERR_PTR(-ENOMEM);
256 v9fs_create(struct v9fs_session_info *v9ses, u32 pfid, char *name, u32 perm,
257 u8 mode, char *extension, u32 *fidp, struct v9fs_qid *qid, u32 *iounit)
261 struct v9fs_fcall *fcall;
263 fid = v9fs_get_idpool(&v9ses->fidpool);
265 eprintk(KERN_WARNING, "no free fids available\n");
269 err = v9fs_t_walk(v9ses, pfid, fid, NULL, &fcall);
271 PRINT_FCALL_ERROR("clone error", fcall);
272 if (fcall && fcall->id == RWALK)
279 err = v9fs_t_create(v9ses, fid, name, perm, mode, extension, &fcall);
281 PRINT_FCALL_ERROR("create fails", fcall);
286 *iounit = fcall->params.rcreate.iounit;
289 *qid = fcall->params.rcreate.qid;
298 v9fs_t_clunk(v9ses, fid);
302 if (fid != V9FS_NOFID)
303 v9fs_put_idpool(fid, &v9ses->fidpool);
309 static struct v9fs_fid*
310 v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry)
314 struct v9fs_fid *ret;
315 struct v9fs_fcall *fcall;
317 nfid = v9fs_get_idpool(&v9ses->fidpool);
319 eprintk(KERN_WARNING, "no free fids available\n");
320 return ERR_PTR(-ENOSPC);
323 err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name,
327 if (fcall && fcall->id == RWALK)
330 PRINT_FCALL_ERROR("walk error", fcall);
331 v9fs_put_idpool(nfid, &v9ses->fidpool);
337 ret = v9fs_fid_create(v9ses, nfid);
343 err = v9fs_fid_insert(ret, dentry);
345 v9fs_fid_destroy(ret);
352 v9fs_t_clunk(v9ses, nfid);
359 static struct inode *
360 v9fs_inode_from_fid(struct v9fs_session_info *v9ses, u32 fid,
361 struct super_block *sb)
365 struct v9fs_fcall *fcall;
368 err = v9fs_t_stat(v9ses, fid, &fcall);
370 PRINT_FCALL_ERROR("stat error", fcall);
374 umode = p9mode2unixmode(v9ses, fcall->params.rstat.stat.mode);
375 ret = v9fs_get_inode(sb, umode);
382 v9fs_stat2inode(&fcall->params.rstat.stat, ret, sb);
395 * v9fs_remove - helper function to remove files and directories
396 * @dir: directory inode that is being deleted
397 * @file: dentry that is being deleted
398 * @rmdir: removing a directory
402 static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
404 struct v9fs_fcall *fcall = NULL;
405 struct super_block *sb = NULL;
406 struct v9fs_session_info *v9ses = NULL;
407 struct v9fs_fid *v9fid = NULL;
408 struct inode *file_inode = NULL;
412 dprintk(DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file,
415 file_inode = file->d_inode;
416 sb = file_inode->i_sb;
417 v9ses = v9fs_inode2v9ses(file_inode);
418 v9fid = v9fs_fid_clone(file);
420 return PTR_ERR(v9fid);
424 dprintk(DEBUG_ERROR, "inode #%lu, no fid!\n",
429 result = v9fs_t_remove(v9ses, fid, &fcall);
431 PRINT_FCALL_ERROR("remove fails", fcall);
435 v9fs_put_idpool(fid, &v9ses->fidpool);
436 v9fs_fid_destroy(v9fid);
444 v9fs_open_created(struct inode *inode, struct file *file)
450 * v9fs_vfs_create - VFS hook to create files
451 * @inode: directory inode that is being deleted
452 * @dentry: dentry that is being deleted
453 * @mode: create permissions
454 * @nd: path information
459 v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
460 struct nameidata *nd)
463 u32 fid, perm, iounit;
465 struct v9fs_session_info *v9ses;
466 struct v9fs_fid *dfid, *vfid, *ffid;
473 v9ses = v9fs_inode2v9ses(dir);
474 dfid = v9fs_fid_clone(dentry->d_parent);
480 perm = unixmode2p9mode(v9ses, mode);
481 if (nd && nd->flags & LOOKUP_OPEN)
482 flags = nd->intent.open.flags - 1;
486 err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name,
487 perm, v9fs_uflags2omode(flags), NULL, &fid, &qid, &iounit);
492 vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry);
493 v9fs_fid_clunk(v9ses, dfid);
500 inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb);
502 err = PTR_ERR(inode);
508 dentry->d_op = &v9fs_cached_dentry_operations;
510 dentry->d_op = &v9fs_dentry_operations;
511 d_instantiate(dentry, inode);
513 if (nd && nd->flags & LOOKUP_OPEN) {
514 ffid = v9fs_fid_create(v9ses, fid);
518 filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created);
520 v9fs_fid_destroy(ffid);
521 return PTR_ERR(filp);
525 ffid->rdir_fcall = NULL;
527 ffid->iounit = iounit;
529 filp->private_data = ffid;
535 v9fs_fid_clunk(v9ses, dfid);
539 v9fs_fid_destroy(vfid);
545 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
546 * @inode: inode that is being unlinked
547 * @dentry: dentry that is being unlinked
548 * @mode: mode for new directory
552 static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
556 struct v9fs_session_info *v9ses;
557 struct v9fs_fid *dfid, *vfid;
562 v9ses = v9fs_inode2v9ses(dir);
563 dfid = v9fs_fid_clone(dentry->d_parent);
569 perm = unixmode2p9mode(v9ses, mode | S_IFDIR);
571 err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name,
572 perm, V9FS_OREAD, NULL, &fid, NULL, NULL);
575 dprintk(DEBUG_ERROR, "create error %d\n", err);
579 vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry);
586 v9fs_fid_clunk(v9ses, dfid);
587 inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb);
589 err = PTR_ERR(inode);
591 v9fs_fid_destroy(vfid);
596 dentry->d_op = &v9fs_cached_dentry_operations;
598 dentry->d_op = &v9fs_dentry_operations;
599 d_instantiate(dentry, inode);
603 v9fs_fid_clunk(v9ses, dfid);
610 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
611 * @dir: inode that is being walked from
612 * @dentry: dentry that is being walked to?
613 * @nameidata: path data
617 static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
618 struct nameidata *nameidata)
620 struct super_block *sb;
621 struct v9fs_session_info *v9ses;
622 struct v9fs_fid *dirfid;
623 struct v9fs_fid *fid;
625 struct v9fs_fcall *fcall = NULL;
630 dprintk(DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n",
631 dir, dentry->d_name.name, dentry, nameidata);
634 v9ses = v9fs_inode2v9ses(dir);
635 dirfid = v9fs_fid_lookup(dentry->d_parent);
638 return ERR_PTR(PTR_ERR(dirfid));
640 dirfidnum = dirfid->fid;
642 newfid = v9fs_get_idpool(&v9ses->fidpool);
644 eprintk(KERN_WARNING, "newfid fails!\n");
649 result = v9fs_t_walk(v9ses, dirfidnum, newfid,
650 (char *)dentry->d_name.name, &fcall);
655 if (fcall && fcall->id == RWALK)
656 v9fs_t_clunk(v9ses, newfid);
658 v9fs_put_idpool(newfid, &v9ses->fidpool);
660 if (result == -ENOENT) {
663 "Return negative dentry %p count %d\n",
664 dentry, atomic_read(&dentry->d_count));
668 dprintk(DEBUG_ERROR, "walk error:%d\n", result);
673 result = v9fs_t_stat(v9ses, newfid, &fcall);
675 dprintk(DEBUG_ERROR, "stat error\n");
679 inode = v9fs_get_inode(sb, p9mode2unixmode(v9ses,
680 fcall->params.rstat.stat.mode));
682 if (IS_ERR(inode) && (PTR_ERR(inode) == -ENOSPC)) {
683 eprintk(KERN_WARNING, "inode alloc failes, returns %ld\n",
690 inode->i_ino = v9fs_qid2ino(&fcall->params.rstat.stat.qid);
692 fid = v9fs_fid_create(v9ses, newfid);
694 dprintk(DEBUG_ERROR, "couldn't insert\n");
699 result = v9fs_fid_insert(fid, dentry);
703 fid->qid = fcall->params.rstat.stat.qid;
704 v9fs_stat2inode(&fcall->params.rstat.stat, inode, inode->i_sb);
705 if((fid->qid.version)&&(v9ses->cache))
706 dentry->d_op = &v9fs_cached_dentry_operations;
708 dentry->d_op = &v9fs_dentry_operations;
710 d_add(dentry, inode);
721 return ERR_PTR(result);
725 * v9fs_vfs_unlink - VFS unlink hook to delete an inode
726 * @i: inode that is being unlinked
727 * @d: dentry that is being unlinked
731 static int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
733 return v9fs_remove(i, d, 0);
737 * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
738 * @i: inode that is being unlinked
739 * @d: dentry that is being unlinked
743 static int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
745 return v9fs_remove(i, d, 1);
749 * v9fs_vfs_rename - VFS hook to rename an inode
750 * @old_dir: old dir inode
751 * @old_dentry: old dentry
752 * @new_dir: new dir inode
753 * @new_dentry: new dentry
758 v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
759 struct inode *new_dir, struct dentry *new_dentry)
761 struct inode *old_inode = old_dentry->d_inode;
762 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(old_inode);
763 struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry);
764 struct v9fs_fid *olddirfid;
765 struct v9fs_fid *newdirfid;
766 struct v9fs_wstat wstat;
767 struct v9fs_fcall *fcall = NULL;
769 int olddirfidnum = -1;
770 int newdirfidnum = -1;
773 dprintk(DEBUG_VFS, "\n");
776 return PTR_ERR(oldfid);
778 olddirfid = v9fs_fid_clone(old_dentry->d_parent);
779 if(IS_ERR(olddirfid)) {
780 retval = PTR_ERR(olddirfid);
784 newdirfid = v9fs_fid_clone(new_dentry->d_parent);
785 if(IS_ERR(newdirfid)) {
786 retval = PTR_ERR(newdirfid);
790 /* 9P can only handle file rename in the same directory */
791 if (memcmp(&olddirfid->qid, &newdirfid->qid, sizeof(newdirfid->qid))) {
792 dprintk(DEBUG_ERROR, "old dir and new dir are different\n");
798 olddirfidnum = olddirfid->fid;
799 newdirfidnum = newdirfid->fid;
802 dprintk(DEBUG_ERROR, "no fid for old file #%lu\n",
808 v9fs_blank_wstat(&wstat);
809 wstat.muid = v9ses->name;
810 wstat.name = (char *) new_dentry->d_name.name;
812 retval = v9fs_t_wstat(v9ses, fid, &wstat, &fcall);
815 PRINT_FCALL_ERROR("wstat error", fcall);
820 v9fs_fid_clunk(v9ses, newdirfid);
823 v9fs_fid_clunk(v9ses, olddirfid);
832 * v9fs_vfs_getattr - retrieve file metadata
833 * @mnt - mount information
834 * @dentry - file to get attributes on
835 * @stat - metadata structure to populate
840 v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
843 struct v9fs_fcall *fcall = NULL;
844 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
845 struct v9fs_fid *fid = v9fs_fid_clone(dentry);
848 dprintk(DEBUG_VFS, "dentry: %p\n", dentry);
852 err = v9fs_t_stat(v9ses, fid->fid, &fcall);
855 dprintk(DEBUG_ERROR, "stat error\n");
857 v9fs_stat2inode(&fcall->params.rstat.stat, dentry->d_inode,
858 dentry->d_inode->i_sb);
859 generic_fillattr(dentry->d_inode, stat);
863 v9fs_fid_clunk(v9ses, fid);
868 * v9fs_vfs_setattr - set file metadata
869 * @dentry: file whose metadata to set
870 * @iattr: metadata assignment structure
874 static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
876 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
877 struct v9fs_fid *fid = v9fs_fid_clone(dentry);
878 struct v9fs_fcall *fcall = NULL;
879 struct v9fs_wstat wstat;
882 dprintk(DEBUG_VFS, "\n");
886 v9fs_blank_wstat(&wstat);
887 if (iattr->ia_valid & ATTR_MODE)
888 wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode);
890 if (iattr->ia_valid & ATTR_MTIME)
891 wstat.mtime = iattr->ia_mtime.tv_sec;
893 if (iattr->ia_valid & ATTR_ATIME)
894 wstat.atime = iattr->ia_atime.tv_sec;
896 if (iattr->ia_valid & ATTR_SIZE)
897 wstat.length = iattr->ia_size;
899 if (v9ses->extended) {
900 if (iattr->ia_valid & ATTR_UID)
901 wstat.n_uid = iattr->ia_uid;
903 if (iattr->ia_valid & ATTR_GID)
904 wstat.n_gid = iattr->ia_gid;
907 res = v9fs_t_wstat(v9ses, fid->fid, &wstat, &fcall);
910 PRINT_FCALL_ERROR("wstat error", fcall);
914 res = inode_setattr(dentry->d_inode, iattr);
916 v9fs_fid_clunk(v9ses, fid);
921 * v9fs_stat2inode - populate an inode structure with mistat info
922 * @stat: Plan 9 metadata (mistat) structure
923 * @inode: inode to populate
924 * @sb: superblock of filesystem
929 v9fs_stat2inode(struct v9fs_stat *stat, struct inode *inode,
930 struct super_block *sb)
934 struct v9fs_session_info *v9ses = sb->s_fs_info;
938 inode->i_atime.tv_sec = stat->atime;
939 inode->i_mtime.tv_sec = stat->mtime;
940 inode->i_ctime.tv_sec = stat->mtime;
942 inode->i_uid = v9ses->uid;
943 inode->i_gid = v9ses->gid;
945 if (v9ses->extended) {
946 inode->i_uid = stat->n_uid;
947 inode->i_gid = stat->n_gid;
950 inode->i_mode = p9mode2unixmode(v9ses, stat->mode);
951 if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) {
956 n = stat->extension.len;
957 if (n > sizeof(ext)-1)
959 memmove(ext, stat->extension.str, n);
961 sscanf(ext, "%c %u %u", &type, &major, &minor);
964 inode->i_mode &= ~S_IFBLK;
965 inode->i_mode |= S_IFCHR;
970 dprintk(DEBUG_ERROR, "Unknown special type %c (%.*s)\n",
971 type, stat->extension.len, stat->extension.str);
973 inode->i_rdev = MKDEV(major, minor);
977 inode->i_size = stat->length;
980 (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
984 * v9fs_qid2ino - convert qid into inode number
987 * BUG: potential for inode number collisions?
990 ino_t v9fs_qid2ino(struct v9fs_qid *qid)
992 u64 path = qid->path + 2;
995 if (sizeof(ino_t) == sizeof(path))
996 memcpy(&i, &path, sizeof(ino_t));
998 i = (ino_t) (path ^ (path >> 32));
1004 * v9fs_readlink - read a symlink's location (internal version)
1005 * @dentry: dentry for symlink
1006 * @buffer: buffer to load symlink location into
1007 * @buflen: length of buffer
1011 static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
1013 int retval = -EPERM;
1015 struct v9fs_fcall *fcall = NULL;
1016 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
1017 struct v9fs_fid *fid = v9fs_fid_clone(dentry);
1020 return PTR_ERR(fid);
1022 if (!v9ses->extended) {
1024 dprintk(DEBUG_ERROR, "not extended\n");
1028 dprintk(DEBUG_VFS, " %s\n", dentry->d_name.name);
1029 retval = v9fs_t_stat(v9ses, fid->fid, &fcall);
1032 dprintk(DEBUG_ERROR, "stat error\n");
1041 if (!(fcall->params.rstat.stat.mode & V9FS_DMSYMLINK)) {
1046 /* copy extension buffer into buffer */
1047 if (fcall->params.rstat.stat.extension.len < buflen)
1048 buflen = fcall->params.rstat.stat.extension.len + 1;
1050 memmove(buffer, fcall->params.rstat.stat.extension.str, buflen - 1);
1051 buffer[buflen-1] = 0;
1053 dprintk(DEBUG_ERROR, "%s -> %.*s (%s)\n", dentry->d_name.name, fcall->params.rstat.stat.extension.len,
1054 fcall->params.rstat.stat.extension.str, buffer);
1061 v9fs_fid_clunk(v9ses, fid);
1067 * v9fs_vfs_readlink - read a symlink's location
1068 * @dentry: dentry for symlink
1069 * @buf: buffer to load symlink location into
1070 * @buflen: length of buffer
1074 static int v9fs_vfs_readlink(struct dentry *dentry, char __user * buffer,
1079 char *link = __getname();
1081 if (unlikely(!link))
1084 if (buflen > PATH_MAX)
1087 dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
1089 retval = v9fs_readlink(dentry, link, buflen);
1092 if ((ret = copy_to_user(buffer, link, retval)) != 0) {
1093 dprintk(DEBUG_ERROR, "problem copying to user: %d\n",
1104 * v9fs_vfs_follow_link - follow a symlink path
1105 * @dentry: dentry for symlink
1110 static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
1113 char *link = __getname();
1115 dprintk(DEBUG_VFS, "%s n", dentry->d_name.name);
1118 link = ERR_PTR(-ENOMEM);
1120 len = v9fs_readlink(dentry, link, PATH_MAX);
1124 link = ERR_PTR(len);
1128 nd_set_link(nd, link);
1134 * v9fs_vfs_put_link - release a symlink path
1135 * @dentry: dentry for symlink
1140 static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
1142 char *s = nd_get_link(nd);
1144 dprintk(DEBUG_VFS, " %s %s\n", dentry->d_name.name, s);
1149 static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
1150 int mode, const char *extension)
1154 struct v9fs_session_info *v9ses;
1155 struct v9fs_fid *dfid, *vfid = NULL;
1156 struct inode *inode = NULL;
1158 v9ses = v9fs_inode2v9ses(dir);
1159 if (!v9ses->extended) {
1160 dprintk(DEBUG_ERROR, "not extended\n");
1164 dfid = v9fs_fid_clone(dentry->d_parent);
1166 err = PTR_ERR(dfid);
1170 perm = unixmode2p9mode(v9ses, mode);
1172 err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name,
1173 perm, V9FS_OREAD, (char *) extension, &fid, NULL, NULL);
1178 err = v9fs_t_clunk(v9ses, fid);
1182 vfid = v9fs_clone_walk(v9ses, dfid->fid, dentry);
1184 err = PTR_ERR(vfid);
1189 inode = v9fs_inode_from_fid(v9ses, vfid->fid, dir->i_sb);
1190 if (IS_ERR(inode)) {
1191 err = PTR_ERR(inode);
1197 dentry->d_op = &v9fs_cached_dentry_operations;
1199 dentry->d_op = &v9fs_dentry_operations;
1200 d_instantiate(dentry, inode);
1204 v9fs_fid_destroy(vfid);
1207 v9fs_fid_clunk(v9ses, dfid);
1215 * v9fs_vfs_symlink - helper function to create symlinks
1216 * @dir: directory inode containing symlink
1217 * @dentry: dentry for symlink
1218 * @symname: symlink data
1220 * See 9P2000.u RFC for more information
1225 v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
1227 dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
1230 return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname);
1234 * v9fs_vfs_link - create a hardlink
1235 * @old_dentry: dentry for file to link to
1236 * @dir: inode destination for new link
1237 * @dentry: dentry for link
1241 /* XXX - lots of code dup'd from symlink and creates,
1242 * figure out a better reuse strategy
1246 v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1247 struct dentry *dentry)
1250 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
1251 struct v9fs_fid *oldfid;
1254 dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
1255 old_dentry->d_name.name);
1257 oldfid = v9fs_fid_clone(old_dentry);
1259 return PTR_ERR(oldfid);
1262 if (unlikely(!name)) {
1267 sprintf(name, "%d\n", oldfid->fid);
1268 retval = v9fs_vfs_mkspecial(dir, dentry, V9FS_DMLINK, name);
1272 v9fs_fid_clunk(v9ses, oldfid);
1277 * v9fs_vfs_mknod - create a special file
1278 * @dir: inode destination for new link
1279 * @dentry: dentry for file
1280 * @mode: mode for creation
1281 * @dev_t: device associated with special file
1286 v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1291 dprintk(DEBUG_VFS, " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
1292 dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev));
1294 if (!new_valid_dev(rdev))
1300 /* build extension */
1302 sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev));
1303 else if (S_ISCHR(mode))
1304 sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev));
1305 else if (S_ISFIFO(mode))
1312 retval = v9fs_vfs_mkspecial(dir, dentry, mode, name);
1318 static const struct inode_operations v9fs_dir_inode_operations_ext = {
1319 .create = v9fs_vfs_create,
1320 .lookup = v9fs_vfs_lookup,
1321 .symlink = v9fs_vfs_symlink,
1322 .link = v9fs_vfs_link,
1323 .unlink = v9fs_vfs_unlink,
1324 .mkdir = v9fs_vfs_mkdir,
1325 .rmdir = v9fs_vfs_rmdir,
1326 .mknod = v9fs_vfs_mknod,
1327 .rename = v9fs_vfs_rename,
1328 .readlink = v9fs_vfs_readlink,
1329 .getattr = v9fs_vfs_getattr,
1330 .setattr = v9fs_vfs_setattr,
1333 static const struct inode_operations v9fs_dir_inode_operations = {
1334 .create = v9fs_vfs_create,
1335 .lookup = v9fs_vfs_lookup,
1336 .unlink = v9fs_vfs_unlink,
1337 .mkdir = v9fs_vfs_mkdir,
1338 .rmdir = v9fs_vfs_rmdir,
1339 .mknod = v9fs_vfs_mknod,
1340 .rename = v9fs_vfs_rename,
1341 .getattr = v9fs_vfs_getattr,
1342 .setattr = v9fs_vfs_setattr,
1345 static const struct inode_operations v9fs_file_inode_operations = {
1346 .getattr = v9fs_vfs_getattr,
1347 .setattr = v9fs_vfs_setattr,
1350 static const struct inode_operations v9fs_symlink_inode_operations = {
1351 .readlink = v9fs_vfs_readlink,
1352 .follow_link = v9fs_vfs_follow_link,
1353 .put_link = v9fs_vfs_put_link,
1354 .getattr = v9fs_vfs_getattr,
1355 .setattr = v9fs_vfs_setattr,