<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
From: Eric Van Hensbergen &lt;ericvh@gmail.com&gt;

This part of the patch contains the VFS inode interfaces.

Signed-off-by: Eric Van Hensbergen &lt;ericvh@gmail.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
---

 fs/9p/vfs_inode.c | 1418 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 1418 insertions(+)

diff -puN /dev/null fs/9p/vfs_inode.c
--- /dev/null	2003-09-15 06:40:47.000000000 -0700
+++ devel-akpm/fs/9p/vfs_inode.c	2005-07-14 16:23:28.000000000 -0700
@@ -0,0 +1,1418 @@
+/*
+ *  linux/fs/9p/vfs_inode.c
+ *
+ * This file contians vfs inode ops for the 9P2000 protocol.
+ *
+ *  Copyright (C) 2004 by Eric Van Hensbergen &lt;ericvh@gmail.com&gt;
+ *  Copyright (C) 2002 by Ron Minnich &lt;rminnich@lanl.gov&gt;
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include &lt;linux/module.h&gt;
+#include &lt;linux/errno.h&gt;
+#include &lt;linux/fs.h&gt;
+#include &lt;linux/file.h&gt;
+#include &lt;linux/pagemap.h&gt;
+#include &lt;linux/stat.h&gt;
+#include &lt;linux/string.h&gt;
+#include &lt;linux/smp_lock.h&gt;
+#include &lt;linux/inet.h&gt;
+#include &lt;linux/namei.h&gt;
+
+#include "debug.h"
+#include "idpool.h"
+#include "v9fs.h"
+#include "9p.h"
+#include "v9fs_vfs.h"
+#include "conv.h"
+#include "fid.h"
+
+static struct inode_operations v9fs_dir_inode_operations;
+static struct inode_operations v9fs_file_inode_operations;
+static struct inode_operations v9fs_symlink_inode_operations;
+
+/**
+ * unixmode2p9mode - convert unix mode bits to plan 9
+ * @v9ses: v9fs session information
+ * @mode: mode to convert
+ *
+ */
+
+static inline int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode)
+{
+	int res;
+	res = mode &amp; 0777;
+	if (S_ISDIR(mode))
+		res |= V9FS_DMDIR;
+	if (v9ses-&gt;extended) {
+		if (S_ISLNK(mode))
+			res |= V9FS_DMSYMLINK;
+		if (v9ses-&gt;nodev == 0) {
+			if (S_ISSOCK(mode))
+				res |= V9FS_DMSOCKET;
+			if (S_ISFIFO(mode))
+				res |= V9FS_DMNAMEDPIPE;
+			if (S_ISBLK(mode))
+				res |= V9FS_DMDEVICE;
+			if (S_ISCHR(mode))
+				res |= V9FS_DMDEVICE;
+		}
+
+		if ((mode &amp; S_ISUID) == S_ISUID)
+			res |= V9FS_DMSETUID;
+		if ((mode &amp; S_ISGID) == S_ISGID)
+			res |= V9FS_DMSETGID;
+		if ((mode &amp; V9FS_DMLINK))
+			res |= V9FS_DMLINK;
+	}
+
+	return res;
+}
+
+/**
+ * p9mode2unixmode- convert plan9 mode bits to unix mode bits
+ * @v9ses: v9fs session information
+ * @mode: mode to convert
+ *
+ */
+
+static inline int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
+{
+	int res;
+
+	res = mode &amp; 0777;
+
+	if ((mode &amp; V9FS_DMDIR) == V9FS_DMDIR)
+		res |= S_IFDIR;
+	else if ((mode &amp; V9FS_DMSYMLINK) &amp;&amp; (v9ses-&gt;extended))
+		res |= S_IFLNK;
+	else if ((mode &amp; V9FS_DMSOCKET) &amp;&amp; (v9ses-&gt;extended)
+		 &amp;&amp; (v9ses-&gt;nodev == 0))
+		res |= S_IFSOCK;
+	else if ((mode &amp; V9FS_DMNAMEDPIPE) &amp;&amp; (v9ses-&gt;extended)
+		 &amp;&amp; (v9ses-&gt;nodev == 0))
+		res |= S_IFIFO;
+	else if ((mode &amp; V9FS_DMDEVICE) &amp;&amp; (v9ses-&gt;extended)
+		 &amp;&amp; (v9ses-&gt;nodev == 0))
+		res |= S_IFBLK;
+	else
+		res |= S_IFREG;
+
+	if (v9ses-&gt;extended) {
+		if ((mode &amp; V9FS_DMSETUID) == V9FS_DMSETUID)
+			res |= S_ISUID;
+
+		if ((mode &amp; V9FS_DMSETGID) == V9FS_DMSETGID)
+			res |= S_ISGID;
+	}
+
+	return res;
+}
+
+/**
+ * v9fs_blank_mistat - helper function to setup a 9P stat structure
+ * @v9ses: 9P session info (for determining extended mode)
+ * @mistat: structure to initialize
+ *
+ */
+
+static inline void
+v9fs_blank_mistat(struct v9fs_session_info *v9ses, struct v9fs_stat *mistat)
+{
+	mistat-&gt;type = ~0;
+	mistat-&gt;dev = ~0;
+	mistat-&gt;qid.type = ~0;
+	mistat-&gt;qid.version = ~0;
+	*((long long *)&amp;mistat-&gt;qid.path) = ~0;
+	mistat-&gt;mode = ~0;
+	mistat-&gt;atime = ~0;
+	mistat-&gt;mtime = ~0;
+	mistat-&gt;length = ~0;
+	mistat-&gt;name = mistat-&gt;data;
+	mistat-&gt;uid = mistat-&gt;data;
+	mistat-&gt;gid = mistat-&gt;data;
+	mistat-&gt;muid = mistat-&gt;data;
+	if (v9ses-&gt;extended) {
+		mistat-&gt;n_uid = ~0;
+		mistat-&gt;n_gid = ~0;
+		mistat-&gt;n_muid = ~0;
+		mistat-&gt;extension = mistat-&gt;data;
+	}
+	*mistat-&gt;data = 0;
+}
+
+/**
+ * v9fs_mistat2unix - convert mistat to unix stat
+ * @mistat: Plan 9 metadata (mistat) structure
+ * @stat: unix metadata (stat) structure to populate
+ * @sb: superblock
+ *
+ */
+
+static void
+v9fs_mistat2unix(struct v9fs_stat *mistat, struct stat *buf,
+		 struct super_block *sb)
+{
+	struct v9fs_session_info *v9ses = sb ? sb-&gt;s_fs_info : NULL;
+
+	buf-&gt;st_nlink = 1;
+
+	buf-&gt;st_atime = mistat-&gt;atime;
+	buf-&gt;st_mtime = mistat-&gt;mtime;
+	buf-&gt;st_ctime = mistat-&gt;mtime;
+
+	if (v9ses &amp;&amp; v9ses-&gt;extended) {
+		/* TODO: string to uid mapping via user-space daemon */
+		buf-&gt;st_uid = mistat-&gt;n_uid;
+		buf-&gt;st_gid = mistat-&gt;n_gid;
+
+		sscanf(mistat-&gt;uid, "%x", (unsigned int *)&amp;buf-&gt;st_uid);
+		sscanf(mistat-&gt;gid, "%x", (unsigned int *)&amp;buf-&gt;st_gid);
+	} else {
+		buf-&gt;st_uid = v9ses-&gt;uid;
+		buf-&gt;st_gid = v9ses-&gt;gid;
+	}
+
+	buf-&gt;st_uid = (unsigned short)-1;
+	buf-&gt;st_gid = (unsigned short)-1;
+
+	if (v9ses &amp;&amp; v9ses-&gt;extended) {
+		if (mistat-&gt;n_uid != -1)
+			sscanf(mistat-&gt;uid, "%x", (unsigned int *)&amp;buf-&gt;st_uid);
+
+		if (mistat-&gt;n_gid != -1)
+			sscanf(mistat-&gt;gid, "%x", (unsigned int *)&amp;buf-&gt;st_gid);
+	}
+
+	if (buf-&gt;st_uid == (unsigned short)-1)
+		buf-&gt;st_uid = v9ses-&gt;uid;
+	if (buf-&gt;st_gid == (unsigned short)-1)
+		buf-&gt;st_gid = v9ses-&gt;gid;
+
+	buf-&gt;st_mode = p9mode2unixmode(v9ses, mistat-&gt;mode);
+	if ((S_ISBLK(buf-&gt;st_mode)) || (S_ISCHR(buf-&gt;st_mode))) {
+		char type = 0;
+		int major = -1;
+		int minor = -1;
+		sscanf(mistat-&gt;extension, "%c %u %u", &amp;type, &amp;major, &amp;minor);
+		switch (type) {
+		case 'c':
+			buf-&gt;st_mode &amp;= ~S_IFBLK;
+			buf-&gt;st_mode |= S_IFCHR;
+			break;
+		case 'b':
+			break;
+		default:
+			dprintk(DEBUG_ERROR, "Unknown special type %c (%s)\n",
+				type, mistat-&gt;extension);
+		};
+		buf-&gt;st_rdev = MKDEV(major, minor);
+	} else
+		buf-&gt;st_rdev = 0;
+
+	buf-&gt;st_size = mistat-&gt;length;
+
+	buf-&gt;st_blksize = sb-&gt;s_blocksize;
+	buf-&gt;st_blocks =
+	    (buf-&gt;st_size + buf-&gt;st_blksize - 1) &gt;&gt; sb-&gt;s_blocksize_bits;
+}
+
+/**
+ * v9fs_get_inode - helper function to setup an inode
+ * @sb: superblock
+ * @mode: mode to setup inode with
+ *
+ */
+
+struct inode *v9fs_get_inode(struct super_block *sb, int mode)
+{
+	struct inode *inode = NULL;
+
+	dprintk(DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
+
+	inode = new_inode(sb);
+	if (inode) {
+		inode-&gt;i_mode = mode;
+		inode-&gt;i_uid = current-&gt;fsuid;
+		inode-&gt;i_gid = current-&gt;fsgid;
+		inode-&gt;i_blksize = sb-&gt;s_blocksize;
+		inode-&gt;i_blocks = 0;
+		inode-&gt;i_rdev = 0;
+		inode-&gt;i_atime = inode-&gt;i_mtime = inode-&gt;i_ctime = CURRENT_TIME;
+
+		switch (mode &amp; S_IFMT) {
+		case S_IFIFO:
+		case S_IFBLK:
+		case S_IFCHR:
+		case S_IFSOCK:
+		case S_IFREG:
+			inode-&gt;i_op = &amp;v9fs_file_inode_operations;
+			inode-&gt;i_fop = &amp;v9fs_file_operations;
+			break;
+		case S_IFDIR:
+			inode-&gt;i_nlink++;
+			inode-&gt;i_op = &amp;v9fs_dir_inode_operations;
+			inode-&gt;i_fop = &amp;v9fs_dir_operations;
+			break;
+		case S_IFLNK:
+			inode-&gt;i_op = &amp;v9fs_symlink_inode_operations;
+			break;
+		default:
+			dprintk(DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n",
+				mode, mode &amp; S_IFMT);
+			sb-&gt;s_op-&gt;put_inode(inode);
+			return ERR_PTR(-EINVAL);
+		}
+	} else {
+		eprintk(KERN_WARNING, "Problem allocating inode\n");
+		return ERR_PTR(-ENOMEM);
+	}
+	return inode;
+}
+
+/**
+ * v9fs_create - helper function to create files and directories
+ * @dir: directory inode file is being created in
+ * @file_dentry: dentry file is being created in
+ * @perm: permissions file is being created with
+ * @open_mode: resulting open mode for file ???
+ *
+ */
+
+static int
+v9fs_create(struct inode *dir,
+	    struct dentry *file_dentry,
+	    unsigned int perm, unsigned int open_mode)
+{
+	struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
+	struct super_block *sb = dir-&gt;i_sb;
+	struct v9fs_fid *dirfid =
+	    v9fs_fid_lookup(file_dentry-&gt;d_parent, FID_WALK);
+	struct v9fs_fid *fid = NULL;
+	struct inode *file_inode = NULL;
+	struct v9fs_fcall *fcall = NULL;
+	struct v9fs_qid qid;
+	struct stat newstat;
+	int dirfidnum = -1;
+	long newfid = -1;
+	int result = 0;
+	unsigned int iounit = 0;
+
+	perm = unixmode2p9mode(v9ses, perm);
+
+	dprintk(DEBUG_VFS, "dir: %p dentry: %p perm: %o mode: %o\n", dir,
+		file_dentry, perm, open_mode);
+
+	if (!dirfid)
+		return -EBADF;
+
+	dirfidnum = dirfid-&gt;fid;
+	if (dirfidnum &lt; 0) {
+		dprintk(DEBUG_ERROR, "No fid for the directory #%lu\n",
+			dir-&gt;i_ino);
+		return -EBADF;
+	}
+
+	if (file_dentry-&gt;d_inode) {
+		dprintk(DEBUG_ERROR,
+			"Odd. There is an inode for dir %lu, name :%s:\n",
+			dir-&gt;i_ino, file_dentry-&gt;d_name.name);
+		return -EEXIST;
+	}
+
+	newfid = v9fs_get_idpool(&amp;v9ses-&gt;fidpool);
+	if (newfid &lt; 0) {
+		eprintk(KERN_WARNING, "no free fids available\n");
+		return -ENOSPC;
+	}
+
+	result = v9fs_t_walk(v9ses, dirfidnum, newfid, NULL, &amp;fcall);
+	if (result &lt; 0) {
+		dprintk(DEBUG_ERROR, "clone error: %s\n", FCALL_ERROR(fcall));
+		v9fs_put_idpool(newfid, &amp;v9ses-&gt;fidpool);
+		newfid = 0;
+		goto CleanUpFid;
+	}
+
+	kfree(fcall);
+
+	result = v9fs_t_create(v9ses, newfid, (char *)file_dentry-&gt;d_name.name,
+			       perm, open_mode, &amp;fcall);
+	if (result &lt; 0) {
+		dprintk(DEBUG_ERROR, "create fails: %s(%d)\n",
+			FCALL_ERROR(fcall), result);
+
+		goto CleanUpFid;
+	}
+
+	iounit = fcall-&gt;params.rcreate.iounit;
+	qid = fcall-&gt;params.rcreate.qid;
+	kfree(fcall);
+
+	fid = v9fs_fid_create(file_dentry);
+	if (!fid) {
+		result = -ENOMEM;
+		goto CleanUpFid;
+	}
+
+	fid-&gt;fid = newfid;
+	fid-&gt;fidopen = 0;
+	fid-&gt;fidcreate = 1;
+	fid-&gt;qid = qid;
+	fid-&gt;iounit = iounit;
+	fid-&gt;rdir_pos = 0;
+	fid-&gt;rdir_fcall = NULL;
+	fid-&gt;v9ses = v9ses;
+
+	if ((perm &amp; V9FS_DMSYMLINK) || (perm &amp; V9FS_DMLINK) ||
+	    (perm &amp; V9FS_DMNAMEDPIPE) || (perm &amp; V9FS_DMSOCKET) ||
+	    (perm &amp; V9FS_DMDEVICE))
+		return 0;
+
+	result = v9fs_t_stat(v9ses, newfid, &amp;fcall);
+	if (result &lt; 0) {
+		dprintk(DEBUG_ERROR, "stat error: %s(%d)\n", FCALL_ERROR(fcall),
+			result);
+		goto CleanUpFid;
+	}
+
+	v9fs_mistat2unix(fcall-&gt;params.rstat.stat, &amp;newstat, sb);
+
+	file_inode = v9fs_get_inode(sb, newstat.st_mode);
+	if ((!file_inode) || IS_ERR(file_inode)) {
+		dprintk(DEBUG_ERROR, "create inode failed\n");
+		result = -EBADF;
+		goto CleanUpFid;
+	}
+
+	v9fs_mistat2inode(fcall-&gt;params.rstat.stat, file_inode, sb);
+	kfree(fcall);
+	d_instantiate(file_dentry, file_inode);
+
+	if (perm &amp; V9FS_DMDIR) {
+		if (v9fs_t_clunk(v9ses, newfid, &amp;fcall))
+			dprintk(DEBUG_ERROR, "clunk for mkdir failed: %s\n",
+				FCALL_ERROR(fcall));
+
+		v9fs_put_idpool(newfid, &amp;v9ses-&gt;fidpool);
+		kfree(fcall);
+		fid-&gt;fidopen = 0;
+		fid-&gt;fidcreate = 0;
+		d_drop(file_dentry);
+	}
+
+	return 0;
+
+      CleanUpFid:
+	kfree(fcall);
+
+	if (newfid) {
+		if (v9fs_t_clunk(v9ses, newfid, &amp;fcall))
+			dprintk(DEBUG_ERROR, "clunk failed: %s\n",
+				FCALL_ERROR(fcall));
+
+		v9fs_put_idpool(newfid, &amp;v9ses-&gt;fidpool);
+		kfree(fcall);
+	}
+	return result;
+}
+
+/**
+ * v9fs_remove - helper function to remove files and directories
+ * @inode: directory inode that is being deleted
+ * @dentry:  dentry that is being deleted
+ * @rmdir: where we are a file or a directory
+ *
+ */
+
+static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
+{
+	struct v9fs_fcall *fcall = NULL;
+	struct super_block *sb = NULL;
+	struct v9fs_session_info *v9ses = NULL;
+	struct v9fs_fid *v9fid = NULL;
+	struct inode *file_inode = NULL;
+	int fid = -1;
+	int result = 0;
+
+	dprintk(DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file,
+		rmdir);
+
+	if (!dir || !S_ISDIR(dir-&gt;i_mode)) {
+		dprintk(DEBUG_ERROR, "dir inode is NULL or not a directory\n");
+		return -ENOENT;
+	}
+
+	if (!file) {
+		dprintk(DEBUG_ERROR, "NO dentry for file to remove\n");
+		return -EBADF;
+	}
+
+	if (!file-&gt;d_inode) {
+		dprintk(DEBUG_ERROR,
+			"dentry %p NO INODE for file to remove!\n", file);
+		return -EBADF;
+	}
+
+	file_inode = file-&gt;d_inode;
+	sb = file_inode-&gt;i_sb;
+	v9ses = v9fs_inode2v9ses(file_inode);
+	v9fid = v9fs_fid_lookup(file, FID_OP);
+
+	if (!sb || !v9ses || !v9fid) {
+		dprintk(DEBUG_ERROR,
+			"no superblock or v9session or v9fs_fid\n");
+		return -EBADF;
+	}
+
+	fid = v9fid-&gt;fid;
+	if (fid &lt; 0) {
+		dprintk(DEBUG_ERROR, "inode #%lu, no fid!\n",
+			file_inode-&gt;i_ino);
+		return -EBADF;
+	}
+
+	if (rmdir &amp;&amp; (!S_ISDIR(file_inode-&gt;i_mode))) {
+		dprintk(DEBUG_ERROR, "trying to remove non-directory\n");
+		return -ENOTDIR;
+	} else if ((!rmdir) &amp;&amp; S_ISDIR(file_inode-&gt;i_mode)) {
+		dprintk(DEBUG_ERROR, "trying to remove directory\n");
+		return -EISDIR;
+	}
+
+	result = v9fs_t_remove(v9ses, fid, &amp;fcall);
+	if (result &lt; 0)
+		dprintk(DEBUG_ERROR, "remove of file fails: %s(%d)\n",
+			FCALL_ERROR(fcall), result);
+	else {
+		v9fs_put_idpool(fid, &amp;v9ses-&gt;fidpool);
+		v9fs_fid_destroy(v9fid);
+	}
+
+	kfree(fcall);
+
+	return result;
+}
+
+/**
+ * v9fs_vfs_create - VFS hook to create files
+ * @inode: directory inode that is being deleted
+ * @dentry:  dentry that is being deleted
+ * @perm: create permissions
+ * @nd: path information
+ *
+ */
+
+static int
+v9fs_vfs_create(struct inode *inode, struct dentry *dentry, int perm,
+		struct nameidata *nd)
+{
+	return v9fs_create(inode, dentry, perm, O_RDWR);
+}
+
+/**
+ * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
+ * @i:  inode that is being unlinked
+ * @dentry: dentry that is being unlinked
+ * @mode: mode for new directory
+ *
+ */
+
+static int v9fs_vfs_mkdir(struct inode *inode, struct dentry *dentry, int mode)
+{
+	return v9fs_create(inode, dentry, mode | S_IFDIR, O_RDONLY);
+}
+
+/**
+ * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
+ * @dir:  inode that is being walked from
+ * @dentry: dentry that is being walked to?
+ * @nameidata: path data
+ *
+ */
+
+static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
+				      struct nameidata *nameidata)
+{
+	struct super_block *sb;
+	struct v9fs_session_info *v9ses;
+	struct v9fs_fid *dirfid;
+	struct v9fs_fid *fid;
+	struct inode *inode;
+	struct v9fs_fcall *fcall = NULL;
+	struct stat newstat;
+	int dirfidnum = -1;
+	int newfid = -1;
+	int result = 0;
+
+	dprintk(DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n",
+		dir, dentry-&gt;d_iname, dentry, nameidata);
+
+	if (!dir) {
+		dprintk(DEBUG_ERROR, "no dir inode\n");
+		return ERR_PTR(-EINVAL);
+	}
+
+	sb = dir-&gt;i_sb;
+	v9ses = v9fs_inode2v9ses(dir);
+	dirfid = v9fs_fid_lookup(dentry-&gt;d_parent, FID_WALK);
+
+	if (!sb || !v9ses || !dirfid) {
+		dprintk(DEBUG_ERROR, "no superblock, v9ses, or dirfid\n");
+		return ERR_PTR(-EINVAL);
+	}
+
+	dirfidnum = dirfid-&gt;fid;
+
+	if (dirfidnum &lt; 0) {
+		dprintk(DEBUG_ERROR, "no dirfid for inode %p, #%lu\n",
+			dir, dir-&gt;i_ino);
+		return ERR_PTR(-EBADF);
+	}
+
+	newfid = v9fs_get_idpool(&amp;v9ses-&gt;fidpool);
+	if (newfid &lt; 0) {
+		eprintk(KERN_WARNING, "newfid fails!\n");
+		return ERR_PTR(-ENOSPC);
+	}
+
+	result =
+	    v9fs_t_walk(v9ses, dirfidnum, newfid, (char *)dentry-&gt;d_name.name,
+			NULL);
+	if (result &lt; 0) {
+		v9fs_put_idpool(newfid, &amp;v9ses-&gt;fidpool);
+		if (result == -ENOENT) {
+			d_add(dentry, NULL);
+			dprintk(DEBUG_ERROR,
+				"Return negative dentry %p count %d\n",
+				dentry, atomic_read(&amp;dentry-&gt;d_count));
+			return NULL;
+		}
+		dprintk(DEBUG_ERROR, "walk error:%d\n", result);
+		goto FreeFcall;
+	}
+
+	result = v9fs_t_stat(v9ses, newfid, &amp;fcall);
+	if (result &lt; 0) {
+		dprintk(DEBUG_ERROR, "stat error\n");
+		goto FreeFcall;
+	}
+
+	v9fs_mistat2unix(fcall-&gt;params.rstat.stat, &amp;newstat, sb);
+	inode = v9fs_get_inode(sb, newstat.st_mode);
+
+	if (IS_ERR(inode) &amp;&amp; (PTR_ERR(inode) == -ENOSPC)) {
+		eprintk(KERN_WARNING, "inode alloc failes, returns %ld\n",
+			PTR_ERR(inode));
+
+		result = -ENOSPC;
+		goto FreeFcall;
+	}
+
+	inode-&gt;i_ino = v9fs_qid2ino(&amp;fcall-&gt;params.rstat.stat-&gt;qid);
+
+	fid = v9fs_fid_create(dentry);
+	if (fid == NULL) {
+		dprintk(DEBUG_ERROR, "couldn't insert\n");
+		result = -ENOMEM;
+		goto FreeFcall;
+	}
+
+	fid-&gt;fid = newfid;
+	fid-&gt;fidopen = 0;
+	fid-&gt;v9ses = v9ses;
+	fid-&gt;qid = fcall-&gt;params.rstat.stat-&gt;qid;
+
+	dentry-&gt;d_op = &amp;v9fs_dentry_operations;
+	v9fs_mistat2inode(fcall-&gt;params.rstat.stat, inode, inode-&gt;i_sb);
+
+	d_add(dentry, inode);
+	kfree(fcall);
+
+	return NULL;
+
+      FreeFcall:
+	kfree(fcall);
+	return ERR_PTR(result);
+}
+
+/**
+ * v9fs_vfs_unlink - VFS unlink hook to delete an inode
+ * @i:  inode that is being unlinked
+ * @dentry: dentry that is being unlinked
+ *
+ */
+
+static int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
+{
+	return v9fs_remove(i, d, 0);
+}
+
+/**
+ * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
+ * @i:  inode that is being unlinked
+ * @dentry: dentry that is being unlinked
+ *
+ */
+
+static int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
+{
+	return v9fs_remove(i, d, 1);
+}
+
+/**
+ * v9fs_vfs_rename - VFS hook to rename an inode
+ * @old_dir:  old dir inode
+ * @old_dentry: old dentry
+ * @new_dir: new dir inode
+ * @new_dentry: new dentry
+ *
+ */
+
+static int
+v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
+		struct inode *new_dir, struct dentry *new_dentry)
+{
+	struct inode *old_inode = old_dentry-&gt;d_inode;
+	struct v9fs_session_info *v9ses = v9fs_inode2v9ses(old_inode);
+	struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry, FID_WALK);
+	struct v9fs_fid *olddirfid =
+	    v9fs_fid_lookup(old_dentry-&gt;d_parent, FID_WALK);
+	struct v9fs_fid *newdirfid =
+	    v9fs_fid_lookup(new_dentry-&gt;d_parent, FID_WALK);
+	struct v9fs_stat *mistat = kmalloc(v9ses-&gt;maxdata, GFP_KERNEL);
+	struct v9fs_fcall *fcall = NULL;
+	int fid = -1;
+	int olddirfidnum = -1;
+	int newdirfidnum = -1;
+	int retval = 0;
+
+	dprintk(DEBUG_VFS, "\n");
+
+	if ((!oldfid) || (!olddirfid) || (!newdirfid)) {
+		dprintk(DEBUG_ERROR, "problem with arguments\n");
+		return -EBADF;
+	}
+
+	/* 9P can only handle file rename in the same directory */
+	if (memcmp(&amp;olddirfid-&gt;qid, &amp;newdirfid-&gt;qid, sizeof(newdirfid-&gt;qid))) {
+		dprintk(DEBUG_ERROR, "old dir and new dir are different\n");
+		retval = -EPERM;
+		goto FreeFcallnBail;
+	}
+
+	fid = oldfid-&gt;fid;
+	olddirfidnum = olddirfid-&gt;fid;
+	newdirfidnum = newdirfid-&gt;fid;
+
+	if (fid &lt; 0) {
+		dprintk(DEBUG_ERROR, "no fid for old file #%lu\n",
+			old_inode-&gt;i_ino);
+		retval = -EBADF;
+		goto FreeFcallnBail;
+	}
+
+	v9fs_blank_mistat(v9ses, mistat);
+
+	strcpy(mistat-&gt;data + 1, v9ses-&gt;name);
+	mistat-&gt;name = mistat-&gt;data + 1 + strlen(v9ses-&gt;name);
+
+	if (new_dentry-&gt;d_name.len &gt;
+	    (v9ses-&gt;maxdata - strlen(v9ses-&gt;name) - sizeof(struct v9fs_stat))) {
+		dprintk(DEBUG_ERROR, "new name too long\n");
+		goto FreeFcallnBail;
+	}
+
+	strcpy(mistat-&gt;name, new_dentry-&gt;d_name.name);
+	retval = v9fs_t_wstat(v9ses, fid, mistat, &amp;fcall);
+
+      FreeFcallnBail:
+	kfree(mistat);
+
+	if (retval &lt; 0)
+		dprintk(DEBUG_ERROR, "v9fs_t_wstat error: %s\n",
+			FCALL_ERROR(fcall));
+
+	kfree(fcall);
+	return retval;
+}
+
+/**
+ * v9fs_vfs_getattr - retreive file metadata
+ * @mnt - mount information
+ * @dentry - file to get attributes on
+ * @stat - metadata structure to populate
+ *
+ */
+
+static int
+v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
+		 struct kstat *stat)
+{
+	struct v9fs_fcall *fcall = NULL;
+	struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry-&gt;d_inode);
+	struct v9fs_fid *fid = v9fs_fid_lookup(dentry, FID_OP);
+	int err = -EPERM;
+
+	dprintk(DEBUG_VFS, "dentry: %p\n", dentry);
+	if (!fid) {
+		dprintk(DEBUG_ERROR,
+			"couldn't find fid associated with dentry\n");
+		return -EBADF;
+	}
+
+	err = v9fs_t_stat(v9ses, fid-&gt;fid, &amp;fcall);
+
+	if (err &lt; 0)
+		dprintk(DEBUG_ERROR, "stat error\n");
+	else {
+		v9fs_mistat2inode(fcall-&gt;params.rstat.stat, dentry-&gt;d_inode,
+				  dentry-&gt;d_inode-&gt;i_sb);
+		generic_fillattr(dentry-&gt;d_inode, stat);
+	}
+
+	kfree(fcall);
+	return err;
+}
+
+/**
+ * v9fs_vfs_setattr - set file metadata
+ * @dentry: file whose metadata to set
+ * @iattr: metadata assignment structure
+ *
+ */
+
+static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
+{
+	struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry-&gt;d_inode);
+	struct v9fs_fid *fid = v9fs_fid_lookup(dentry, FID_OP);
+	struct v9fs_stat *mistat = kmalloc(v9ses-&gt;maxdata, GFP_KERNEL);
+	struct v9fs_fcall *fcall = NULL;
+	int res = -EPERM;
+
+	dprintk(DEBUG_VFS, "\n");
+	if (!fid) {
+		dprintk(DEBUG_ERROR,
+			"Couldn't find fid associated with dentry\n");
+		return -EBADF;
+	}
+
+	if (!mistat)
+		return -ENOMEM;
+
+	v9fs_blank_mistat(v9ses, mistat);
+	if (iattr-&gt;ia_valid &amp; ATTR_MODE)
+		mistat-&gt;mode = unixmode2p9mode(v9ses, iattr-&gt;ia_mode);
+
+	if (iattr-&gt;ia_valid &amp; ATTR_MTIME)
+		mistat-&gt;mtime = iattr-&gt;ia_mtime.tv_sec;
+
+	if (iattr-&gt;ia_valid &amp; ATTR_ATIME)
+		mistat-&gt;atime = iattr-&gt;ia_atime.tv_sec;
+
+	if (iattr-&gt;ia_valid &amp; ATTR_SIZE)
+		mistat-&gt;length = iattr-&gt;ia_size;
+
+	if (v9ses-&gt;extended) {
+		char *uid = kmalloc(strlen(mistat-&gt;uid), GFP_KERNEL);
+		char *gid = kmalloc(strlen(mistat-&gt;gid), GFP_KERNEL);
+		char *muid = kmalloc(strlen(mistat-&gt;muid), GFP_KERNEL);
+		char *name = kmalloc(strlen(mistat-&gt;name), GFP_KERNEL);
+		char *extension = kmalloc(strlen(mistat-&gt;extension),
+					  GFP_KERNEL);
+
+		if ((!uid) || (!gid) || (!muid) || (!name) || (!extension)) {
+			kfree(uid);
+			kfree(gid);
+			kfree(muid);
+			kfree(name);
+			kfree(extension);
+
+			return -ENOMEM;
+		}
+
+		strcpy(uid, mistat-&gt;uid);
+		strcpy(gid, mistat-&gt;gid);
+		strcpy(muid, mistat-&gt;muid);
+		strcpy(name, mistat-&gt;name);
+		strcpy(extension, mistat-&gt;extension);
+
+		if (iattr-&gt;ia_valid &amp; ATTR_UID) {
+			if (strlen(uid) != 8) {
+				dprintk(DEBUG_ERROR, "uid strlen is %u not 8\n",
+					(unsigned int)strlen(uid));
+				sprintf(uid, "%08x", iattr-&gt;ia_uid);
+			} else {
+				kfree(uid);
+				uid = kmalloc(9, GFP_KERNEL);
+			}
+
+			sprintf(uid, "%08x", iattr-&gt;ia_uid);
+			mistat-&gt;n_uid = iattr-&gt;ia_uid;
+		}
+
+		if (iattr-&gt;ia_valid &amp; ATTR_GID) {
+			if (strlen(gid) != 8)
+				dprintk(DEBUG_ERROR, "gid strlen is %u not 8\n",
+					(unsigned int)strlen(gid));
+			else {
+				kfree(gid);
+				gid = kmalloc(9, GFP_KERNEL);
+			}
+
+			sprintf(gid, "%08x", iattr-&gt;ia_gid);
+			mistat-&gt;n_gid = iattr-&gt;ia_gid;
+		}
+
+		mistat-&gt;uid = mistat-&gt;data;
+		strcpy(mistat-&gt;uid, uid);
+		mistat-&gt;gid = mistat-&gt;data + strlen(uid) + 1;
+		strcpy(mistat-&gt;gid, gid);
+		mistat-&gt;muid = mistat-&gt;gid + strlen(gid) + 1;
+		strcpy(mistat-&gt;muid, muid);
+		mistat-&gt;name = mistat-&gt;muid + strlen(muid) + 1;
+		strcpy(mistat-&gt;name, name);
+		mistat-&gt;extension = mistat-&gt;name + strlen(name) + 1;
+		strcpy(mistat-&gt;extension, extension);
+
+		kfree(uid);
+		kfree(gid);
+		kfree(muid);
+		kfree(name);
+		kfree(extension);
+	}
+
+	res = v9fs_t_wstat(v9ses, fid-&gt;fid, mistat, &amp;fcall);
+
+	if (res &lt; 0)
+		dprintk(DEBUG_ERROR, "wstat error: %s\n", FCALL_ERROR(fcall));
+
+	kfree(mistat);
+	kfree(fcall);
+
+	if (res &gt;= 0)
+		res = inode_setattr(dentry-&gt;d_inode, iattr);
+
+	return res;
+}
+
+/**
+ * v9fs_mistat2inode - populate an inode structure with mistat info
+ * @mistat: Plan 9 metadata (mistat) structure
+ * @inode: inode to populate
+ * @sb: superblock of filesystem
+ *
+ */
+
+void
+v9fs_mistat2inode(struct v9fs_stat *mistat, struct inode *inode,
+		  struct super_block *sb)
+{
+	struct v9fs_session_info *v9ses = sb ? sb-&gt;s_fs_info : NULL;
+
+	inode-&gt;i_nlink = 1;
+
+	inode-&gt;i_atime.tv_sec = mistat-&gt;atime;
+	inode-&gt;i_mtime.tv_sec = mistat-&gt;mtime;
+	inode-&gt;i_ctime.tv_sec = mistat-&gt;mtime;
+
+	inode-&gt;i_uid = -1;
+	inode-&gt;i_gid = -1;
+
+	if (v9ses &amp;&amp; v9ses-&gt;extended) {
+		/* TODO: string to uid mapping via user-space daemon */
+		inode-&gt;i_uid = mistat-&gt;n_uid;
+		inode-&gt;i_gid = mistat-&gt;n_gid;
+
+		if (mistat-&gt;n_uid == -1)
+			sscanf(mistat-&gt;uid, "%x", &amp;inode-&gt;i_uid);
+
+		if (mistat-&gt;n_gid == -1)
+			sscanf(mistat-&gt;gid, "%x", &amp;inode-&gt;i_gid);
+	}
+
+	if (inode-&gt;i_uid == -1)
+		inode-&gt;i_uid = v9ses-&gt;uid;
+	if (inode-&gt;i_gid == -1)
+		inode-&gt;i_gid = v9ses-&gt;gid;
+
+	inode-&gt;i_mode = p9mode2unixmode(v9ses, mistat-&gt;mode);
+	if ((S_ISBLK(inode-&gt;i_mode)) || (S_ISCHR(inode-&gt;i_mode))) {
+		char type = 0;
+		int major = -1;
+		int minor = -1;
+		sscanf(mistat-&gt;extension, "%c %u %u", &amp;type, &amp;major, &amp;minor);
+		switch (type) {
+		case 'c':
+			inode-&gt;i_mode &amp;= ~S_IFBLK;
+			inode-&gt;i_mode |= S_IFCHR;
+			break;
+		case 'b':
+			break;
+		default:
+			dprintk(DEBUG_ERROR, "Unknown special type %c (%s)\n",
+				type, mistat-&gt;extension);
+		};
+		inode-&gt;i_rdev = MKDEV(major, minor);
+	} else
+		inode-&gt;i_rdev = 0;
+
+	inode-&gt;i_size = mistat-&gt;length;
+
+	inode-&gt;i_blksize = sb-&gt;s_blocksize;
+	inode-&gt;i_blocks =
+	    (inode-&gt;i_size + inode-&gt;i_blksize - 1) &gt;&gt; sb-&gt;s_blocksize_bits;
+}
+
+/**
+ * v9fs_qid2ino - convert qid into inode number
+ * @qid: qid to hash
+ *
+ * BUG: potential for inode number collisions?
+ */
+
+ino_t v9fs_qid2ino(struct v9fs_qid *qid)
+{
+	u64 path = qid-&gt;path + 2;
+	ino_t i = 0;
+
+	if (sizeof(ino_t) == sizeof(path))
+		memcpy(&amp;i, &amp;path, sizeof(ino_t));
+	else
+		i = (ino_t) (path ^ (path &gt;&gt; 32));
+
+	return i;
+}
+
+/**
+ * v9fs_vfs_symlink - helper function to create symlinks
+ * @dir: directory inode containing symlink
+ * @dentry: dentry for symlink
+ * @symname: symlink data
+ *
+ * See 9P2000.u RFC for more information
+ *
+ */
+
+static int
+v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
+{
+	int retval = -EPERM;
+	struct v9fs_fid *newfid;
+	struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
+	struct super_block *sb = dir ? dir-&gt;i_sb : NULL;
+	struct v9fs_fcall *fcall = NULL;
+	struct v9fs_stat *mistat = kmalloc(v9ses-&gt;maxdata, GFP_KERNEL);
+
+	dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir-&gt;i_ino, dentry-&gt;d_name.name,
+		symname);
+
+	if ((!dentry) || (!sb) || (!v9ses)) {
+		dprintk(DEBUG_ERROR, "problem with arguments\n");
+		return -EBADF;
+	}
+
+	if (!v9ses-&gt;extended) {
+		dprintk(DEBUG_ERROR, "not extended\n");
+		goto FreeFcall;
+	}
+
+	/* issue a create */
+	retval = v9fs_create(dir, dentry, S_IFLNK, 0);
+	if (retval != 0)
+		goto FreeFcall;
+
+	newfid = v9fs_fid_lookup(dentry, FID_OP);
+
+	/* issue a twstat */
+	v9fs_blank_mistat(v9ses, mistat);
+	strcpy(mistat-&gt;data + 1, symname);
+	mistat-&gt;extension = mistat-&gt;data + 1;
+	retval = v9fs_t_wstat(v9ses, newfid-&gt;fid, mistat, &amp;fcall);
+	if (retval &lt; 0) {
+		dprintk(DEBUG_ERROR, "v9fs_t_wstat error: %s\n",
+			FCALL_ERROR(fcall));
+		goto FreeFcall;
+	}
+
+	/* need to update dcache so we show up */
+	kfree(fcall);
+	fcall = NULL;
+
+	if (v9fs_t_clunk(v9ses, newfid-&gt;fid, &amp;fcall)) {
+		dprintk(DEBUG_ERROR, "clunk for symlink failed: %s\n",
+			FCALL_ERROR(fcall));
+		goto FreeFcall;
+	}
+
+	d_drop(dentry);		/* FID - will this also clunk? */
+
+      FreeFcall:
+	kfree(mistat);
+	kfree(fcall);
+
+	return retval;
+}
+
+/**
+ * v9fs_readlink - read a symlink's location (internal version)
+ * @dentry: dentry for symlink
+ * @buf: buffer to load symlink location into
+ * @buflen: length of buffer
+ *
+ */
+
+static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
+{
+	int retval = -EPERM;
+
+	struct v9fs_fcall *fcall = NULL;
+	struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry-&gt;d_inode);
+	struct v9fs_fid *fid = v9fs_fid_lookup(dentry, FID_OP);
+
+	if (!fid) {
+		dprintk(DEBUG_ERROR, "could not resolve fid from dentry\n");
+		retval = -EBADF;
+		goto FreeFcall;
+	}
+
+	if (!v9ses-&gt;extended) {
+		retval = -EBADF;
+		dprintk(DEBUG_ERROR, "not extended\n");
+		goto FreeFcall;
+	}
+
+	dprintk(DEBUG_VFS, " %s\n", dentry-&gt;d_name.name);
+	retval = v9fs_t_stat(v9ses, fid-&gt;fid, &amp;fcall);
+
+	if (retval &lt; 0) {
+		dprintk(DEBUG_ERROR, "stat error\n");
+		goto FreeFcall;
+	}
+
+	if (!fcall)
+		return -EIO;
+
+	if (!(fcall-&gt;params.rstat.stat-&gt;mode &amp; V9FS_DMSYMLINK)) {
+		retval = -EINVAL;
+		goto FreeFcall;
+	}
+
+	/* copy extension buffer into buffer */
+	if (strlen(fcall-&gt;params.rstat.stat-&gt;extension) &lt; buflen)
+		buflen = strlen(fcall-&gt;params.rstat.stat-&gt;extension);
+
+	memcpy(buffer, fcall-&gt;params.rstat.stat-&gt;extension, buflen + 1);
+
+	retval = buflen;
+
+      FreeFcall:
+	kfree(fcall);
+
+	return retval;
+}
+
+/**
+ * v9fs_vfs_readlink - read a symlink's location
+ * @dentry: dentry for symlink
+ * @buf: buffer to load symlink location into
+ * @buflen: length of buffer
+ *
+ */
+
+static int v9fs_vfs_readlink(struct dentry *dentry, char __user * buffer,
+			     int buflen)
+{
+	int retval;
+	int ret;
+	char *link = __getname();
+
+	if (strlen(link) &lt; buflen)
+		buflen = strlen(link);
+
+	dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry-&gt;d_iname, dentry);
+
+	retval = v9fs_readlink(dentry, link, buflen);
+
+	if (retval &gt; 0) {
+		if ((ret = copy_to_user(buffer, link, retval)) != 0) {
+			dprintk(DEBUG_ERROR, "problem copying to user: %d\n",
+				ret);
+			retval = ret;
+		}
+	}
+
+	putname(link);
+	return retval;
+}
+
+/**
+ * v9fs_vfs_follow_link - follow a symlink path
+ * @dentry: dentry for symlink
+ * @nd: nameidata
+ *
+ */
+
+static int v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
+{
+	int len = 0;
+	char *link = __getname();
+
+	dprintk(DEBUG_VFS, "%s n", dentry-&gt;d_name.name);
+
+	if (!link)
+		link = ERR_PTR(-ENOMEM);
+	else {
+		len = v9fs_readlink(dentry, link, strlen(link));
+
+		if (len &lt; 0) {
+			putname(link);
+			link = ERR_PTR(len);
+		} else
+			link[len] = 0;
+	}
+	nd_set_link(nd, link);
+
+	return 0;
+}
+
+/**
+ * v9fs_vfs_put_link - release a symlink path
+ * @dentry: dentry for symlink
+ * @nd: nameidata
+ *
+ */
+
+static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd)
+{
+	char *s = nd_get_link(nd);
+
+	dprintk(DEBUG_VFS, " %s %s\n", dentry-&gt;d_name.name, s);
+	if (!IS_ERR(s))
+		putname(s);
+}
+
+/**
+ * v9fs_vfs_link - create a hardlink
+ * @old_dentry: dentry for file to link to
+ * @dir: inode destination for new link
+ * @new_dentry: dentry for link
+ *
+ */
+
+/* XXX - lots of code dup'd from symlink and creates,
+ * figure out a better reuse strategy
+ */
+
+static int
+v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
+	      struct dentry *dentry)
+{
+	int retval = -EPERM;
+	struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
+	struct super_block *sb = dir ? dir-&gt;i_sb : NULL;
+	struct v9fs_fcall *fcall = NULL;
+	struct v9fs_stat *mistat = kmalloc(v9ses-&gt;maxdata, GFP_KERNEL);
+	struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry, FID_OP);
+	struct v9fs_fid *newfid = NULL;
+	char *symname = __getname();
+
+	dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir-&gt;i_ino, dentry-&gt;d_name.name,
+		old_dentry-&gt;d_name.name);
+
+	if ((!dentry) || (!sb) || (!v9ses) || (!oldfid)) {
+		dprintk(DEBUG_ERROR, "problem with arguments\n");
+		retval = -EBADF;
+		goto FreeMem;
+	}
+
+	if (!v9ses-&gt;extended) {
+		dprintk(DEBUG_ERROR, "not extended\n");
+		goto FreeMem;
+	}
+
+	/* get fid of old_dentry */
+	sprintf(symname, "hardlink(%d)\n", oldfid-&gt;fid);
+
+	/* issue a create */
+	retval = v9fs_create(dir, dentry, V9FS_DMLINK, 0);
+	if (retval != 0)
+		goto FreeMem;
+
+	newfid = v9fs_fid_lookup(dentry, FID_OP);
+	if (!newfid) {
+		dprintk(DEBUG_ERROR, "couldn't resolve fid from dentry\n");
+		goto FreeMem;
+	}
+
+	/* issue a twstat */
+	v9fs_blank_mistat(v9ses, mistat);
+	strcpy(mistat-&gt;data + 1, symname);
+	mistat-&gt;extension = mistat-&gt;data + 1;
+	retval = v9fs_t_wstat(v9ses, newfid-&gt;fid, mistat, &amp;fcall);
+	if (retval &lt; 0) {
+		dprintk(DEBUG_ERROR, "v9fs_t_wstat error: %s\n",
+			FCALL_ERROR(fcall));
+		goto FreeMem;
+	}
+
+	/* need to update dcache so we show up */
+	kfree(fcall);
+	fcall = NULL;
+
+	if (v9fs_t_clunk(v9ses, newfid-&gt;fid, &amp;fcall)) {
+		dprintk(DEBUG_ERROR, "clunk for symlink failed: %s\n",
+			FCALL_ERROR(fcall));
+		goto FreeMem;
+	}
+
+	d_drop(dentry);		/* FID - will this also clunk? */
+
+	kfree(fcall);
+	fcall = NULL;
+
+      FreeMem:
+	kfree(mistat);
+	kfree(fcall);
+	putname(symname);
+	return retval;
+}
+
+/**
+ * v9fs_vfs_mknod - create a special file
+ * @dir: inode destination for new link
+ * @dentry: dentry for file
+ * @mode: mode for creation
+ * @dev_t: device associated with special file
+ *
+ */
+
+static int
+v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
+{
+	int retval = -EPERM;
+	struct v9fs_fid *newfid;
+	struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
+	struct super_block *sb = dir ? dir-&gt;i_sb : NULL;
+	struct v9fs_fcall *fcall = NULL;
+	struct v9fs_stat *mistat = kmalloc(v9ses-&gt;maxdata, GFP_KERNEL);
+	char *symname = __getname();
+
+	dprintk(DEBUG_VFS, " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir-&gt;i_ino,
+		dentry-&gt;d_name.name, mode, MAJOR(rdev), MINOR(rdev));
+
+	if (!new_valid_dev(rdev)) {
+		retval = -EINVAL;
+		goto FreeMem;
+	}
+
+	if ((!dentry) || (!sb) || (!v9ses)) {
+		dprintk(DEBUG_ERROR, "problem with arguments\n");
+		retval = -EBADF;
+		goto FreeMem;
+	}
+
+	if (!v9ses-&gt;extended) {
+		dprintk(DEBUG_ERROR, "not extended\n");
+		goto FreeMem;
+	}
+
+	/* issue a create */
+	retval = v9fs_create(dir, dentry, mode, 0);
+
+	if (retval != 0)
+		goto FreeMem;
+
+	newfid = v9fs_fid_lookup(dentry, FID_OP);
+	if (!newfid) {
+		dprintk(DEBUG_ERROR, "coudn't resove fid from dentry\n");
+		retval = -EINVAL;
+		goto FreeMem;
+	}
+
+	/* build extension */
+	if (S_ISBLK(mode))
+		sprintf(symname, "b %u %u", MAJOR(rdev), MINOR(rdev));
+	else if (S_ISCHR(mode))
+		sprintf(symname, "c %u %u", MAJOR(rdev), MINOR(rdev));
+	else if (S_ISFIFO(mode)) ;	/* DO NOTHING */
+	else {
+		retval = -EINVAL;
+		goto FreeMem;
+	}
+
+	if (!S_ISFIFO(mode)) {
+		/* issue a twstat */
+		v9fs_blank_mistat(v9ses, mistat);
+		strcpy(mistat-&gt;data + 1, symname);
+		mistat-&gt;extension = mistat-&gt;data + 1;
+		retval = v9fs_t_wstat(v9ses, newfid-&gt;fid, mistat, &amp;fcall);
+		if (retval &lt; 0) {
+			dprintk(DEBUG_ERROR, "v9fs_t_wstat error: %s\n",
+				FCALL_ERROR(fcall));
+			goto FreeMem;
+		}
+
+		kfree(fcall);
+	}
+
+	/* need to update dcache so we show up */
+	kfree(fcall);
+
+	if (v9fs_t_clunk(v9ses, newfid-&gt;fid, &amp;fcall)) {
+		dprintk(DEBUG_ERROR, "clunk for symlink failed: %s\n",
+			FCALL_ERROR(fcall));
+		goto FreeMem;
+	}
+
+	d_drop(dentry);		/* FID - will this also clunk? */
+
+      FreeMem:
+	kfree(mistat);
+	kfree(fcall);
+	putname(symname);
+
+	return retval;
+}
+
+static struct inode_operations v9fs_dir_inode_operations = {
+	.create = v9fs_vfs_create,
+	.lookup = v9fs_vfs_lookup,
+	.symlink = v9fs_vfs_symlink,
+	.link = v9fs_vfs_link,
+	.unlink = v9fs_vfs_unlink,
+	.mkdir = v9fs_vfs_mkdir,
+	.rmdir = v9fs_vfs_rmdir,
+	.mknod = v9fs_vfs_mknod,
+	.rename = v9fs_vfs_rename,
+	.readlink = v9fs_vfs_readlink,
+	.getattr = v9fs_vfs_getattr,
+	.setattr = v9fs_vfs_setattr,
+};
+
+static struct inode_operations v9fs_file_inode_operations = {
+	.getattr = v9fs_vfs_getattr,
+	.setattr = v9fs_vfs_setattr,
+};
+
+static struct inode_operations v9fs_symlink_inode_operations = {
+	.readlink = v9fs_vfs_readlink,
+	.follow_link = v9fs_vfs_follow_link,
+	.put_link = v9fs_vfs_put_link,
+	.getattr = v9fs_vfs_getattr,
+	.setattr = v9fs_vfs_setattr,
+};
_
</pre></body></html>