Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/9p/vfs_inode.c |
| 3 | * |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 4 | * This file contains vfs inode ops for the 9P2000 protocol. |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 5 | * |
| 6 | * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com> |
| 7 | * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Eric Van Hensbergen | 42e8c50 | 2006-03-25 03:07:28 -0800 | [diff] [blame] | 10 | * it under the terms of the GNU General Public License version 2 |
| 11 | * as published by the Free Software Foundation. |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 12 | * |
| 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. |
| 17 | * |
| 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 |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/fs.h> |
| 29 | #include <linux/file.h> |
| 30 | #include <linux/pagemap.h> |
| 31 | #include <linux/stat.h> |
| 32 | #include <linux/string.h> |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 33 | #include <linux/inet.h> |
| 34 | #include <linux/namei.h> |
| 35 | #include <linux/idr.h> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 36 | #include <linux/sched.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 38 | #include <net/9p/9p.h> |
| 39 | #include <net/9p/client.h> |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 40 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 41 | #include "v9fs.h" |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 42 | #include "v9fs_vfs.h" |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 43 | #include "fid.h" |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 44 | #include "cache.h" |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 45 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 46 | static const struct inode_operations v9fs_dir_inode_operations; |
| 47 | static const struct inode_operations v9fs_dir_inode_operations_ext; |
| 48 | static const struct inode_operations v9fs_file_inode_operations; |
| 49 | static const struct inode_operations v9fs_symlink_inode_operations; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * unixmode2p9mode - convert unix mode bits to plan 9 |
| 53 | * @v9ses: v9fs session information |
| 54 | * @mode: mode to convert |
| 55 | * |
| 56 | */ |
| 57 | |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 58 | static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 59 | { |
| 60 | int res; |
| 61 | res = mode & 0777; |
| 62 | if (S_ISDIR(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 63 | res |= P9_DMDIR; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 64 | if (v9fs_proto_dotu(v9ses)) { |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 65 | if (S_ISLNK(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 66 | res |= P9_DMSYMLINK; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 67 | if (v9ses->nodev == 0) { |
| 68 | if (S_ISSOCK(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 69 | res |= P9_DMSOCKET; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 70 | if (S_ISFIFO(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 71 | res |= P9_DMNAMEDPIPE; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 72 | if (S_ISBLK(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 73 | res |= P9_DMDEVICE; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 74 | if (S_ISCHR(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 75 | res |= P9_DMDEVICE; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | if ((mode & S_ISUID) == S_ISUID) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 79 | res |= P9_DMSETUID; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 80 | if ((mode & S_ISGID) == S_ISGID) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 81 | res |= P9_DMSETGID; |
Anthony Liguori | d199d65 | 2008-02-06 19:25:06 -0600 | [diff] [blame] | 82 | if ((mode & S_ISVTX) == S_ISVTX) |
| 83 | res |= P9_DMSETVTX; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 84 | if ((mode & P9_DMLINK)) |
| 85 | res |= P9_DMLINK; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | return res; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * p9mode2unixmode- convert plan9 mode bits to unix mode bits |
| 93 | * @v9ses: v9fs session information |
| 94 | * @mode: mode to convert |
| 95 | * |
| 96 | */ |
| 97 | |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 98 | static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 99 | { |
| 100 | int res; |
| 101 | |
| 102 | res = mode & 0777; |
| 103 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 104 | if ((mode & P9_DMDIR) == P9_DMDIR) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 105 | res |= S_IFDIR; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 106 | else if ((mode & P9_DMSYMLINK) && (v9fs_proto_dotu(v9ses))) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 107 | res |= S_IFLNK; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 108 | else if ((mode & P9_DMSOCKET) && (v9fs_proto_dotu(v9ses)) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 109 | && (v9ses->nodev == 0)) |
| 110 | res |= S_IFSOCK; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 111 | else if ((mode & P9_DMNAMEDPIPE) && (v9fs_proto_dotu(v9ses)) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 112 | && (v9ses->nodev == 0)) |
| 113 | res |= S_IFIFO; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 114 | else if ((mode & P9_DMDEVICE) && (v9fs_proto_dotu(v9ses)) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 115 | && (v9ses->nodev == 0)) |
| 116 | res |= S_IFBLK; |
| 117 | else |
| 118 | res |= S_IFREG; |
| 119 | |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 120 | if (v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 121 | if ((mode & P9_DMSETUID) == P9_DMSETUID) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 122 | res |= S_ISUID; |
| 123 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 124 | if ((mode & P9_DMSETGID) == P9_DMSETGID) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 125 | res |= S_ISGID; |
Anthony Liguori | d199d65 | 2008-02-06 19:25:06 -0600 | [diff] [blame] | 126 | |
| 127 | if ((mode & P9_DMSETVTX) == P9_DMSETVTX) |
| 128 | res |= S_ISVTX; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | return res; |
| 132 | } |
| 133 | |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 134 | /** |
| 135 | * v9fs_uflags2omode- convert posix open flags to plan 9 mode bits |
| 136 | * @uflags: flags to convert |
Eric Van Hensbergen | 2e4bef4 | 2008-06-24 17:39:39 -0500 | [diff] [blame] | 137 | * @extended: if .u extensions are active |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 138 | */ |
| 139 | |
Eric Van Hensbergen | 2e4bef4 | 2008-06-24 17:39:39 -0500 | [diff] [blame] | 140 | int v9fs_uflags2omode(int uflags, int extended) |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 141 | { |
| 142 | int ret; |
| 143 | |
| 144 | ret = 0; |
| 145 | switch (uflags&3) { |
| 146 | default: |
| 147 | case O_RDONLY: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 148 | ret = P9_OREAD; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 149 | break; |
| 150 | |
| 151 | case O_WRONLY: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 152 | ret = P9_OWRITE; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 153 | break; |
| 154 | |
| 155 | case O_RDWR: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 156 | ret = P9_ORDWR; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 157 | break; |
| 158 | } |
| 159 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 160 | if (uflags & O_TRUNC) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 161 | ret |= P9_OTRUNC; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 162 | |
Eric Van Hensbergen | 2e4bef4 | 2008-06-24 17:39:39 -0500 | [diff] [blame] | 163 | if (extended) { |
| 164 | if (uflags & O_EXCL) |
| 165 | ret |= P9_OEXCL; |
| 166 | |
| 167 | if (uflags & O_APPEND) |
| 168 | ret |= P9_OAPPEND; |
| 169 | } |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 170 | |
| 171 | return ret; |
| 172 | } |
| 173 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 174 | /** |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 175 | * v9fs_blank_wstat - helper function to setup a 9P stat structure |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 176 | * @wstat: structure to initialize |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 177 | * |
| 178 | */ |
| 179 | |
M. Mohan Kumar | 7a4439c | 2010-02-08 15:36:48 -0600 | [diff] [blame] | 180 | void |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 181 | v9fs_blank_wstat(struct p9_wstat *wstat) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 182 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 183 | wstat->type = ~0; |
| 184 | wstat->dev = ~0; |
| 185 | wstat->qid.type = ~0; |
| 186 | wstat->qid.version = ~0; |
| 187 | *((long long *)&wstat->qid.path) = ~0; |
| 188 | wstat->mode = ~0; |
| 189 | wstat->atime = ~0; |
| 190 | wstat->mtime = ~0; |
| 191 | wstat->length = ~0; |
| 192 | wstat->name = NULL; |
| 193 | wstat->uid = NULL; |
| 194 | wstat->gid = NULL; |
| 195 | wstat->muid = NULL; |
| 196 | wstat->n_uid = ~0; |
| 197 | wstat->n_gid = ~0; |
| 198 | wstat->n_muid = ~0; |
| 199 | wstat->extension = NULL; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 202 | #ifdef CONFIG_9P_FSCACHE |
| 203 | /** |
| 204 | * v9fs_alloc_inode - helper function to allocate an inode |
| 205 | * This callback is executed before setting up the inode so that we |
| 206 | * can associate a vcookie with each inode. |
| 207 | * |
| 208 | */ |
| 209 | |
| 210 | struct inode *v9fs_alloc_inode(struct super_block *sb) |
| 211 | { |
| 212 | struct v9fs_cookie *vcookie; |
| 213 | vcookie = (struct v9fs_cookie *)kmem_cache_alloc(vcookie_cache, |
| 214 | GFP_KERNEL); |
| 215 | if (!vcookie) |
| 216 | return NULL; |
| 217 | |
| 218 | vcookie->fscache = NULL; |
| 219 | vcookie->qid = NULL; |
| 220 | spin_lock_init(&vcookie->lock); |
| 221 | return &vcookie->inode; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * v9fs_destroy_inode - destroy an inode |
| 226 | * |
| 227 | */ |
| 228 | |
| 229 | void v9fs_destroy_inode(struct inode *inode) |
| 230 | { |
| 231 | kmem_cache_free(vcookie_cache, v9fs_inode2cookie(inode)); |
| 232 | } |
| 233 | #endif |
| 234 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 235 | /** |
| 236 | * v9fs_get_inode - helper function to setup an inode |
| 237 | * @sb: superblock |
| 238 | * @mode: mode to setup inode with |
| 239 | * |
| 240 | */ |
| 241 | |
| 242 | struct inode *v9fs_get_inode(struct super_block *sb, int mode) |
| 243 | { |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 244 | int err; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 245 | struct inode *inode; |
Eric Van Hensbergen | b501611 | 2005-09-09 13:04:27 -0700 | [diff] [blame] | 246 | struct v9fs_session_info *v9ses = sb->s_fs_info; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 247 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 248 | P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 249 | |
| 250 | inode = new_inode(sb); |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 251 | if (!inode) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 252 | P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n"); |
Abhishek Kulkarni | 48559b4c | 2009-08-17 16:32:18 -0500 | [diff] [blame] | 253 | return ERR_PTR(-ENOMEM); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 254 | } |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 255 | |
| 256 | inode->i_mode = mode; |
| 257 | inode->i_uid = current_fsuid(); |
| 258 | inode->i_gid = current_fsgid(); |
| 259 | inode->i_blocks = 0; |
| 260 | inode->i_rdev = 0; |
| 261 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 262 | inode->i_mapping->a_ops = &v9fs_addr_operations; |
| 263 | |
| 264 | switch (mode & S_IFMT) { |
| 265 | case S_IFIFO: |
| 266 | case S_IFBLK: |
| 267 | case S_IFCHR: |
| 268 | case S_IFSOCK: |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 269 | if (!v9fs_proto_dotu(v9ses)) { |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 270 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 271 | "special files without extended mode\n"); |
| 272 | err = -EINVAL; |
| 273 | goto error; |
| 274 | } |
| 275 | init_special_inode(inode, inode->i_mode, inode->i_rdev); |
| 276 | break; |
| 277 | case S_IFREG: |
| 278 | inode->i_op = &v9fs_file_inode_operations; |
| 279 | inode->i_fop = &v9fs_file_operations; |
| 280 | break; |
| 281 | case S_IFLNK: |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 282 | if (!v9fs_proto_dotu(v9ses)) { |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 283 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 284 | "extended modes used w/o 9P2000.u\n"); |
| 285 | err = -EINVAL; |
| 286 | goto error; |
| 287 | } |
| 288 | inode->i_op = &v9fs_symlink_inode_operations; |
| 289 | break; |
| 290 | case S_IFDIR: |
| 291 | inc_nlink(inode); |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 292 | if (v9fs_proto_dotu(v9ses)) |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 293 | inode->i_op = &v9fs_dir_inode_operations_ext; |
| 294 | else |
| 295 | inode->i_op = &v9fs_dir_inode_operations; |
| 296 | inode->i_fop = &v9fs_dir_operations; |
| 297 | break; |
| 298 | default: |
| 299 | P9_DPRINTK(P9_DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n", |
| 300 | mode, mode & S_IFMT); |
| 301 | err = -EINVAL; |
| 302 | goto error; |
| 303 | } |
| 304 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 305 | return inode; |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 306 | |
| 307 | error: |
| 308 | iput(inode); |
| 309 | return ERR_PTR(err); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 312 | /* |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 313 | static struct v9fs_fid* |
| 314 | v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry) |
| 315 | { |
| 316 | int err; |
Mika Kukkonen | 736c4b85 | 2006-12-06 20:36:29 -0800 | [diff] [blame] | 317 | int nfid; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 318 | struct v9fs_fid *ret; |
| 319 | struct v9fs_fcall *fcall; |
| 320 | |
| 321 | nfid = v9fs_get_idpool(&v9ses->fidpool); |
| 322 | if (nfid < 0) { |
| 323 | eprintk(KERN_WARNING, "no free fids available\n"); |
Latchesar Ionkov | 731805b | 2006-03-07 21:55:42 -0800 | [diff] [blame] | 324 | return ERR_PTR(-ENOSPC); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name, |
| 328 | &fcall); |
| 329 | |
| 330 | if (err < 0) { |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 331 | if (fcall && fcall->id == RWALK) |
| 332 | goto clunk_fid; |
| 333 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 334 | PRINT_FCALL_ERROR("walk error", fcall); |
| 335 | v9fs_put_idpool(nfid, &v9ses->fidpool); |
| 336 | goto error; |
| 337 | } |
| 338 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 339 | kfree(fcall); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 340 | fcall = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 341 | ret = v9fs_fid_create(v9ses, nfid); |
| 342 | if (!ret) { |
| 343 | err = -ENOMEM; |
| 344 | goto clunk_fid; |
| 345 | } |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 346 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 347 | err = v9fs_fid_insert(ret, dentry); |
| 348 | if (err < 0) { |
| 349 | v9fs_fid_destroy(ret); |
| 350 | goto clunk_fid; |
Latchesar Ionkov | 0b8dd17 | 2005-09-27 21:45:24 -0700 | [diff] [blame] | 351 | } |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 352 | |
| 353 | return ret; |
| 354 | |
| 355 | clunk_fid: |
| 356 | v9fs_t_clunk(v9ses, nfid); |
| 357 | |
| 358 | error: |
| 359 | kfree(fcall); |
| 360 | return ERR_PTR(err); |
| 361 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 362 | */ |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 363 | |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 364 | |
| 365 | /** |
| 366 | * v9fs_clear_inode - release an inode |
| 367 | * @inode: inode to release |
| 368 | * |
| 369 | */ |
| 370 | void v9fs_clear_inode(struct inode *inode) |
| 371 | { |
| 372 | filemap_fdatawrite(inode->i_mapping); |
| 373 | |
| 374 | #ifdef CONFIG_9P_FSCACHE |
| 375 | v9fs_cache_inode_put_cookie(inode); |
| 376 | #endif |
| 377 | } |
| 378 | |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 379 | /** |
| 380 | * v9fs_inode_from_fid - populate an inode by issuing a attribute request |
| 381 | * @v9ses: session information |
| 382 | * @fid: fid to issue attribute request for |
| 383 | * @sb: superblock on which to create inode |
| 384 | * |
| 385 | */ |
| 386 | |
Latchesar Ionkov | 5174fda | 2006-03-25 03:07:25 -0800 | [diff] [blame] | 387 | static struct inode * |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 388 | v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 389 | struct super_block *sb) |
| 390 | { |
| 391 | int err, umode; |
| 392 | struct inode *ret; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 393 | struct p9_wstat *st; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 394 | |
| 395 | ret = NULL; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 396 | st = p9_client_stat(fid); |
Abhishek Kulkarni | 02bc356 | 2009-07-19 13:41:54 -0600 | [diff] [blame] | 397 | if (IS_ERR(st)) |
| 398 | return ERR_CAST(st); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 399 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 400 | umode = p9mode2unixmode(v9ses, st->mode); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 401 | ret = v9fs_get_inode(sb, umode); |
| 402 | if (IS_ERR(ret)) { |
| 403 | err = PTR_ERR(ret); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 404 | goto error; |
| 405 | } |
| 406 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 407 | v9fs_stat2inode(st, ret, sb); |
| 408 | ret->i_ino = v9fs_qid2ino(&st->qid); |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 409 | |
| 410 | #ifdef CONFIG_9P_FSCACHE |
| 411 | v9fs_vcookie_set_qid(ret, &st->qid); |
| 412 | v9fs_cache_inode_get_cookie(ret); |
| 413 | #endif |
Abhishek Kulkarni | 02bc356 | 2009-07-19 13:41:54 -0600 | [diff] [blame] | 414 | p9stat_free(st); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 415 | kfree(st); |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 416 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 417 | return ret; |
| 418 | |
| 419 | error: |
Abhishek Kulkarni | 02bc356 | 2009-07-19 13:41:54 -0600 | [diff] [blame] | 420 | p9stat_free(st); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 421 | kfree(st); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 422 | return ERR_PTR(err); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | /** |
| 426 | * v9fs_remove - helper function to remove files and directories |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 427 | * @dir: directory inode that is being deleted |
| 428 | * @file: dentry that is being deleted |
| 429 | * @rmdir: removing a directory |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 430 | * |
| 431 | */ |
| 432 | |
| 433 | static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir) |
| 434 | { |
Aneesh Kumar K.V | d994f40 | 2010-03-29 18:14:50 -0500 | [diff] [blame] | 435 | int retval; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 436 | struct inode *file_inode; |
| 437 | struct v9fs_session_info *v9ses; |
| 438 | struct p9_fid *v9fid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 439 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 440 | P9_DPRINTK(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 441 | rmdir); |
| 442 | |
| 443 | file_inode = file->d_inode; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 444 | v9ses = v9fs_inode2v9ses(file_inode); |
Latchesar Ionkov | c959df9 | 2007-04-23 14:41:11 -0700 | [diff] [blame] | 445 | v9fid = v9fs_fid_clone(file); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 446 | if (IS_ERR(v9fid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 447 | return PTR_ERR(v9fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 448 | |
Aneesh Kumar K.V | d994f40 | 2010-03-29 18:14:50 -0500 | [diff] [blame] | 449 | retval = p9_client_remove(v9fid); |
| 450 | if (!retval) |
| 451 | drop_nlink(file_inode); |
| 452 | return retval; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 455 | static int |
| 456 | v9fs_open_created(struct inode *inode, struct file *file) |
| 457 | { |
| 458 | return 0; |
| 459 | } |
| 460 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 461 | |
| 462 | /** |
| 463 | * v9fs_create - Create a file |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 464 | * @v9ses: session information |
| 465 | * @dir: directory that dentry is being created in |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 466 | * @dentry: dentry that is being created |
Abhishek Kulkarni | 0e15597 | 2009-07-19 13:41:55 -0600 | [diff] [blame] | 467 | * @extension: 9p2000.u extension string to support devices, etc. |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 468 | * @perm: create permissions |
| 469 | * @mode: open mode |
| 470 | * |
| 471 | */ |
| 472 | static struct p9_fid * |
| 473 | v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir, |
| 474 | struct dentry *dentry, char *extension, u32 perm, u8 mode) |
| 475 | { |
| 476 | int err; |
| 477 | char *name; |
| 478 | struct p9_fid *dfid, *ofid, *fid; |
| 479 | struct inode *inode; |
| 480 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 481 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name); |
| 482 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 483 | err = 0; |
| 484 | ofid = NULL; |
| 485 | fid = NULL; |
| 486 | name = (char *) dentry->d_name.name; |
| 487 | dfid = v9fs_fid_clone(dentry->d_parent); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 488 | if (IS_ERR(dfid)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 489 | err = PTR_ERR(dfid); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 490 | P9_DPRINTK(P9_DEBUG_VFS, "fid clone failed %d\n", err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 491 | dfid = NULL; |
| 492 | goto error; |
| 493 | } |
| 494 | |
| 495 | /* clone a fid to use for creation */ |
| 496 | ofid = p9_client_walk(dfid, 0, NULL, 1); |
| 497 | if (IS_ERR(ofid)) { |
| 498 | err = PTR_ERR(ofid); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 499 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 500 | ofid = NULL; |
| 501 | goto error; |
| 502 | } |
| 503 | |
| 504 | err = p9_client_fcreate(ofid, name, perm, mode, extension); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 505 | if (err < 0) { |
| 506 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 507 | goto error; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 508 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 509 | |
| 510 | /* now walk from the parent so we can get unopened fid */ |
| 511 | fid = p9_client_walk(dfid, 1, &name, 0); |
| 512 | if (IS_ERR(fid)) { |
| 513 | err = PTR_ERR(fid); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 514 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 515 | fid = NULL; |
| 516 | goto error; |
| 517 | } else |
| 518 | dfid = NULL; |
| 519 | |
| 520 | /* instantiate inode and assign the unopened fid to the dentry */ |
| 521 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
| 522 | if (IS_ERR(inode)) { |
| 523 | err = PTR_ERR(inode); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 524 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 525 | goto error; |
| 526 | } |
| 527 | |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 528 | if (v9ses->cache) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 529 | dentry->d_op = &v9fs_cached_dentry_operations; |
| 530 | else |
| 531 | dentry->d_op = &v9fs_dentry_operations; |
| 532 | |
| 533 | d_instantiate(dentry, inode); |
Abhishek Kulkarni | 50fb6d2 | 2009-07-19 13:41:57 -0600 | [diff] [blame] | 534 | err = v9fs_fid_add(dentry, fid); |
| 535 | if (err < 0) |
| 536 | goto error; |
| 537 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 538 | return ofid; |
| 539 | |
| 540 | error: |
| 541 | if (dfid) |
| 542 | p9_client_clunk(dfid); |
| 543 | |
| 544 | if (ofid) |
| 545 | p9_client_clunk(ofid); |
| 546 | |
| 547 | if (fid) |
| 548 | p9_client_clunk(fid); |
| 549 | |
| 550 | return ERR_PTR(err); |
| 551 | } |
| 552 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 553 | /** |
| 554 | * v9fs_vfs_create - VFS hook to create files |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 555 | * @dir: directory inode that is being created |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 556 | * @dentry: dentry that is being deleted |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 557 | * @mode: create permissions |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 558 | * @nd: path information |
| 559 | * |
| 560 | */ |
| 561 | |
| 562 | static int |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 563 | v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 564 | struct nameidata *nd) |
| 565 | { |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 566 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 567 | u32 perm; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 568 | int flags; |
| 569 | struct v9fs_session_info *v9ses; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 570 | struct p9_fid *fid; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 571 | struct file *filp; |
| 572 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 573 | err = 0; |
| 574 | fid = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 575 | v9ses = v9fs_inode2v9ses(dir); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 576 | perm = unixmode2p9mode(v9ses, mode); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 577 | if (nd && nd->flags & LOOKUP_OPEN) |
| 578 | flags = nd->intent.open.flags - 1; |
| 579 | else |
| 580 | flags = O_RDWR; |
| 581 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 582 | fid = v9fs_create(v9ses, dir, dentry, NULL, perm, |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 583 | v9fs_uflags2omode(flags, |
| 584 | v9fs_proto_dotu(v9ses))); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 585 | if (IS_ERR(fid)) { |
| 586 | err = PTR_ERR(fid); |
| 587 | fid = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 588 | goto error; |
| 589 | } |
| 590 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 591 | /* if we are opening a file, assign the open fid to the file */ |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 592 | if (nd && nd->flags & LOOKUP_OPEN) { |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 593 | filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created); |
| 594 | if (IS_ERR(filp)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 595 | err = PTR_ERR(filp); |
| 596 | goto error; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 597 | } |
| 598 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 599 | filp->private_data = fid; |
| 600 | } else |
| 601 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 602 | |
| 603 | return 0; |
| 604 | |
| 605 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 606 | if (fid) |
| 607 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 608 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 609 | return err; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | /** |
| 613 | * v9fs_vfs_mkdir - VFS mkdir hook to create a directory |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 614 | * @dir: inode that is being unlinked |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 615 | * @dentry: dentry that is being unlinked |
| 616 | * @mode: mode for new directory |
| 617 | * |
| 618 | */ |
| 619 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 620 | static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 621 | { |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 622 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 623 | u32 perm; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 624 | struct v9fs_session_info *v9ses; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 625 | struct p9_fid *fid; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 626 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 627 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name); |
| 628 | err = 0; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 629 | v9ses = v9fs_inode2v9ses(dir); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 630 | perm = unixmode2p9mode(v9ses, mode | S_IFDIR); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 631 | fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_OREAD); |
| 632 | if (IS_ERR(fid)) { |
| 633 | err = PTR_ERR(fid); |
| 634 | fid = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 635 | } |
| 636 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 637 | if (fid) |
| 638 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 639 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 640 | return err; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | /** |
| 644 | * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode |
| 645 | * @dir: inode that is being walked from |
| 646 | * @dentry: dentry that is being walked to? |
| 647 | * @nameidata: path data |
| 648 | * |
| 649 | */ |
| 650 | |
| 651 | static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, |
| 652 | struct nameidata *nameidata) |
| 653 | { |
| 654 | struct super_block *sb; |
| 655 | struct v9fs_session_info *v9ses; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 656 | struct p9_fid *dfid, *fid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 657 | struct inode *inode; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 658 | char *name; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 659 | int result = 0; |
| 660 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 661 | P9_DPRINTK(P9_DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n", |
Latchesar Ionkov | 731805b | 2006-03-07 21:55:42 -0800 | [diff] [blame] | 662 | dir, dentry->d_name.name, dentry, nameidata); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 663 | |
Sripathi Kodi | 11e9b49 | 2010-03-29 18:13:59 -0500 | [diff] [blame] | 664 | if (dentry->d_name.len > NAME_MAX) |
| 665 | return ERR_PTR(-ENAMETOOLONG); |
| 666 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 667 | sb = dir->i_sb; |
| 668 | v9ses = v9fs_inode2v9ses(dir); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 669 | dfid = v9fs_fid_lookup(dentry->d_parent); |
| 670 | if (IS_ERR(dfid)) |
David Howells | e231c2e | 2008-02-07 00:15:26 -0800 | [diff] [blame] | 671 | return ERR_CAST(dfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 672 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 673 | name = (char *) dentry->d_name.name; |
| 674 | fid = p9_client_walk(dfid, 1, &name, 1); |
| 675 | if (IS_ERR(fid)) { |
| 676 | result = PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 677 | if (result == -ENOENT) { |
| 678 | d_add(dentry, NULL); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 679 | return NULL; |
| 680 | } |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 681 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 682 | return ERR_PTR(result); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 685 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
| 686 | if (IS_ERR(inode)) { |
| 687 | result = PTR_ERR(inode); |
| 688 | inode = NULL; |
| 689 | goto error; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 690 | } |
| 691 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 692 | result = v9fs_fid_add(dentry, fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 693 | if (result < 0) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 694 | goto error; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 695 | |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 696 | if ((fid->qid.version) && (v9ses->cache)) |
Eric Van Hensbergen | e03abc0 | 2007-02-11 13:21:39 -0600 | [diff] [blame] | 697 | dentry->d_op = &v9fs_cached_dentry_operations; |
| 698 | else |
| 699 | dentry->d_op = &v9fs_dentry_operations; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 700 | |
| 701 | d_add(dentry, inode); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 702 | return NULL; |
| 703 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 704 | error: |
Julien Brunel | 62aa528 | 2008-09-24 16:22:22 -0500 | [diff] [blame] | 705 | p9_client_clunk(fid); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 706 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 707 | return ERR_PTR(result); |
| 708 | } |
| 709 | |
| 710 | /** |
| 711 | * v9fs_vfs_unlink - VFS unlink hook to delete an inode |
| 712 | * @i: inode that is being unlinked |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 713 | * @d: dentry that is being unlinked |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 714 | * |
| 715 | */ |
| 716 | |
| 717 | static int v9fs_vfs_unlink(struct inode *i, struct dentry *d) |
| 718 | { |
| 719 | return v9fs_remove(i, d, 0); |
| 720 | } |
| 721 | |
| 722 | /** |
| 723 | * v9fs_vfs_rmdir - VFS unlink hook to delete a directory |
| 724 | * @i: inode that is being unlinked |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 725 | * @d: dentry that is being unlinked |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 726 | * |
| 727 | */ |
| 728 | |
| 729 | static int v9fs_vfs_rmdir(struct inode *i, struct dentry *d) |
| 730 | { |
| 731 | return v9fs_remove(i, d, 1); |
| 732 | } |
| 733 | |
| 734 | /** |
| 735 | * v9fs_vfs_rename - VFS hook to rename an inode |
| 736 | * @old_dir: old dir inode |
| 737 | * @old_dentry: old dentry |
| 738 | * @new_dir: new dir inode |
| 739 | * @new_dentry: new dentry |
| 740 | * |
| 741 | */ |
| 742 | |
| 743 | static int |
| 744 | v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 745 | struct inode *new_dir, struct dentry *new_dentry) |
| 746 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 747 | struct inode *old_inode; |
| 748 | struct v9fs_session_info *v9ses; |
| 749 | struct p9_fid *oldfid; |
| 750 | struct p9_fid *olddirfid; |
| 751 | struct p9_fid *newdirfid; |
| 752 | struct p9_wstat wstat; |
| 753 | int retval; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 754 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 755 | P9_DPRINTK(P9_DEBUG_VFS, "\n"); |
| 756 | retval = 0; |
| 757 | old_inode = old_dentry->d_inode; |
| 758 | v9ses = v9fs_inode2v9ses(old_inode); |
| 759 | oldfid = v9fs_fid_lookup(old_dentry); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 760 | if (IS_ERR(oldfid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 761 | return PTR_ERR(oldfid); |
| 762 | |
| 763 | olddirfid = v9fs_fid_clone(old_dentry->d_parent); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 764 | if (IS_ERR(olddirfid)) { |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 765 | retval = PTR_ERR(olddirfid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 766 | goto done; |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | newdirfid = v9fs_fid_clone(new_dentry->d_parent); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 770 | if (IS_ERR(newdirfid)) { |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 771 | retval = PTR_ERR(newdirfid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 772 | goto clunk_olddir; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | /* 9P can only handle file rename in the same directory */ |
| 776 | if (memcmp(&olddirfid->qid, &newdirfid->qid, sizeof(newdirfid->qid))) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 777 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 778 | "old dir and new dir are different\n"); |
Eric Van Hensbergen | 621997c | 2007-01-26 00:57:04 -0800 | [diff] [blame] | 779 | retval = -EXDEV; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 780 | goto clunk_newdir; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 781 | } |
| 782 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 783 | v9fs_blank_wstat(&wstat); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 784 | wstat.muid = v9ses->uname; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 785 | wstat.name = (char *) new_dentry->d_name.name; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 786 | retval = p9_client_wstat(oldfid, &wstat); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 787 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 788 | clunk_newdir: |
Latchesar Ionkov | 22150c4 | 2007-10-23 13:48:33 -0500 | [diff] [blame] | 789 | p9_client_clunk(newdirfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 790 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 791 | clunk_olddir: |
Latchesar Ionkov | 22150c4 | 2007-10-23 13:48:33 -0500 | [diff] [blame] | 792 | p9_client_clunk(olddirfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 793 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 794 | done: |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 795 | return retval; |
| 796 | } |
| 797 | |
| 798 | /** |
Adrian Bunk | 943ffb5 | 2006-01-10 00:10:13 +0100 | [diff] [blame] | 799 | * v9fs_vfs_getattr - retrieve file metadata |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 800 | * @mnt: mount information |
| 801 | * @dentry: file to get attributes on |
| 802 | * @stat: metadata structure to populate |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 803 | * |
| 804 | */ |
| 805 | |
| 806 | static int |
| 807 | v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 808 | struct kstat *stat) |
| 809 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 810 | int err; |
| 811 | struct v9fs_session_info *v9ses; |
| 812 | struct p9_fid *fid; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 813 | struct p9_wstat *st; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 814 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 815 | P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry); |
| 816 | err = -EPERM; |
| 817 | v9ses = v9fs_inode2v9ses(dentry->d_inode); |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 818 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) |
Eric Van Hensbergen | 9523a84 | 2007-07-13 13:01:27 -0500 | [diff] [blame] | 819 | return simple_getattr(mnt, dentry, stat); |
| 820 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 821 | fid = v9fs_fid_lookup(dentry); |
| 822 | if (IS_ERR(fid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 823 | return PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 824 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 825 | st = p9_client_stat(fid); |
| 826 | if (IS_ERR(st)) |
| 827 | return PTR_ERR(st); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 828 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 829 | v9fs_stat2inode(st, dentry->d_inode, dentry->d_inode->i_sb); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 830 | generic_fillattr(dentry->d_inode, stat); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 831 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 832 | kfree(st); |
| 833 | return 0; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | /** |
| 837 | * v9fs_vfs_setattr - set file metadata |
| 838 | * @dentry: file whose metadata to set |
| 839 | * @iattr: metadata assignment structure |
| 840 | * |
| 841 | */ |
| 842 | |
| 843 | static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) |
| 844 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 845 | int retval; |
| 846 | struct v9fs_session_info *v9ses; |
| 847 | struct p9_fid *fid; |
| 848 | struct p9_wstat wstat; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 849 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 850 | P9_DPRINTK(P9_DEBUG_VFS, "\n"); |
| 851 | retval = -EPERM; |
| 852 | v9ses = v9fs_inode2v9ses(dentry->d_inode); |
| 853 | fid = v9fs_fid_lookup(dentry); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 854 | if(IS_ERR(fid)) |
| 855 | return PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 856 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 857 | v9fs_blank_wstat(&wstat); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 858 | if (iattr->ia_valid & ATTR_MODE) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 859 | wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 860 | |
| 861 | if (iattr->ia_valid & ATTR_MTIME) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 862 | wstat.mtime = iattr->ia_mtime.tv_sec; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 863 | |
| 864 | if (iattr->ia_valid & ATTR_ATIME) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 865 | wstat.atime = iattr->ia_atime.tv_sec; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 866 | |
| 867 | if (iattr->ia_valid & ATTR_SIZE) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 868 | wstat.length = iattr->ia_size; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 869 | |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 870 | if (v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 871 | if (iattr->ia_valid & ATTR_UID) |
| 872 | wstat.n_uid = iattr->ia_uid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 873 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 874 | if (iattr->ia_valid & ATTR_GID) |
| 875 | wstat.n_gid = iattr->ia_gid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 878 | retval = p9_client_wstat(fid, &wstat); |
| 879 | if (retval >= 0) |
| 880 | retval = inode_setattr(dentry->d_inode, iattr); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 881 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 882 | return retval; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | /** |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 886 | * v9fs_stat2inode - populate an inode structure with mistat info |
| 887 | * @stat: Plan 9 metadata (mistat) structure |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 888 | * @inode: inode to populate |
| 889 | * @sb: superblock of filesystem |
| 890 | * |
| 891 | */ |
| 892 | |
| 893 | void |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 894 | v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode, |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 895 | struct super_block *sb) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 896 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 897 | char ext[32]; |
Aneesh Kumar K.V | 5717144 | 2010-03-05 14:43:43 -0600 | [diff] [blame] | 898 | char tag_name[14]; |
| 899 | unsigned int i_nlink; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 900 | struct v9fs_session_info *v9ses = sb->s_fs_info; |
| 901 | |
| 902 | inode->i_nlink = 1; |
| 903 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 904 | inode->i_atime.tv_sec = stat->atime; |
| 905 | inode->i_mtime.tv_sec = stat->mtime; |
| 906 | inode->i_ctime.tv_sec = stat->mtime; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 907 | |
Latchesar Ionkov | bd32b82 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 908 | inode->i_uid = v9ses->dfltuid; |
| 909 | inode->i_gid = v9ses->dfltgid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 910 | |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 911 | if (v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 912 | inode->i_uid = stat->n_uid; |
| 913 | inode->i_gid = stat->n_gid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 914 | } |
Aneesh Kumar K.V | 5717144 | 2010-03-05 14:43:43 -0600 | [diff] [blame] | 915 | if ((S_ISREG(inode->i_mode)) || (S_ISDIR(inode->i_mode))) { |
| 916 | if (v9fs_proto_dotu(v9ses) && (stat->extension[0] != '\0')) { |
| 917 | /* |
| 918 | * Hadlink support got added later to |
| 919 | * to the .u extension. So there can be |
| 920 | * server out there that doesn't support |
| 921 | * this even with .u extension. So check |
| 922 | * for non NULL stat->extension |
| 923 | */ |
| 924 | strncpy(ext, stat->extension, sizeof(ext)); |
| 925 | /* HARDLINKCOUNT %u */ |
| 926 | sscanf(ext, "%13s %u", tag_name, &i_nlink); |
| 927 | if (!strncmp(tag_name, "HARDLINKCOUNT", 13)) |
| 928 | inode->i_nlink = i_nlink; |
| 929 | } |
| 930 | } |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 931 | inode->i_mode = p9mode2unixmode(v9ses, stat->mode); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 932 | if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) { |
| 933 | char type = 0; |
| 934 | int major = -1; |
| 935 | int minor = -1; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 936 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 937 | strncpy(ext, stat->extension, sizeof(ext)); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 938 | sscanf(ext, "%c %u %u", &type, &major, &minor); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 939 | switch (type) { |
| 940 | case 'c': |
| 941 | inode->i_mode &= ~S_IFBLK; |
| 942 | inode->i_mode |= S_IFCHR; |
| 943 | break; |
| 944 | case 'b': |
| 945 | break; |
| 946 | default: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 947 | P9_DPRINTK(P9_DEBUG_ERROR, |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 948 | "Unknown special type %c %s\n", type, |
| 949 | stat->extension); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 950 | }; |
| 951 | inode->i_rdev = MKDEV(major, minor); |
Magnus Deininger | 57c7b4e | 2008-10-17 12:44:46 -0500 | [diff] [blame] | 952 | init_special_inode(inode, inode->i_mode, inode->i_rdev); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 953 | } else |
| 954 | inode->i_rdev = 0; |
| 955 | |
Abhishek Kulkarni | 7549ae3e | 2009-09-22 11:34:05 -0500 | [diff] [blame] | 956 | i_size_write(inode, stat->length); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 957 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 958 | /* not real number of blocks, but 512 byte ones ... */ |
Abhishek Kulkarni | 7549ae3e | 2009-09-22 11:34:05 -0500 | [diff] [blame] | 959 | inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | /** |
| 963 | * v9fs_qid2ino - convert qid into inode number |
| 964 | * @qid: qid to hash |
| 965 | * |
| 966 | * BUG: potential for inode number collisions? |
| 967 | */ |
| 968 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 969 | ino_t v9fs_qid2ino(struct p9_qid *qid) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 970 | { |
| 971 | u64 path = qid->path + 2; |
| 972 | ino_t i = 0; |
| 973 | |
| 974 | if (sizeof(ino_t) == sizeof(path)) |
| 975 | memcpy(&i, &path, sizeof(ino_t)); |
| 976 | else |
| 977 | i = (ino_t) (path ^ (path >> 32)); |
| 978 | |
| 979 | return i; |
| 980 | } |
| 981 | |
| 982 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 983 | * v9fs_readlink - read a symlink's location (internal version) |
| 984 | * @dentry: dentry for symlink |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 985 | * @buffer: buffer to load symlink location into |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 986 | * @buflen: length of buffer |
| 987 | * |
| 988 | */ |
| 989 | |
| 990 | static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen) |
| 991 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 992 | int retval; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 993 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 994 | struct v9fs_session_info *v9ses; |
| 995 | struct p9_fid *fid; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 996 | struct p9_wstat *st; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 997 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 998 | P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name); |
| 999 | retval = -EPERM; |
| 1000 | v9ses = v9fs_inode2v9ses(dentry->d_inode); |
| 1001 | fid = v9fs_fid_lookup(dentry); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1002 | if (IS_ERR(fid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1003 | return PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1004 | |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 1005 | if (!v9fs_proto_dotu(v9ses)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1006 | return -EBADF; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1007 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1008 | st = p9_client_stat(fid); |
| 1009 | if (IS_ERR(st)) |
| 1010 | return PTR_ERR(st); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1011 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1012 | if (!(st->mode & P9_DMSYMLINK)) { |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1013 | retval = -EINVAL; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1014 | goto done; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | /* copy extension buffer into buffer */ |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1018 | strncpy(buffer, st->extension, buflen); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1019 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1020 | P9_DPRINTK(P9_DEBUG_VFS, |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1021 | "%s -> %s (%s)\n", dentry->d_name.name, st->extension, buffer); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1022 | |
Martin Stava | 2511cd0 | 2009-11-02 08:39:34 -0600 | [diff] [blame] | 1023 | retval = strnlen(buffer, buflen); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1024 | done: |
| 1025 | kfree(st); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1026 | return retval; |
| 1027 | } |
| 1028 | |
| 1029 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1030 | * v9fs_vfs_follow_link - follow a symlink path |
| 1031 | * @dentry: dentry for symlink |
| 1032 | * @nd: nameidata |
| 1033 | * |
| 1034 | */ |
| 1035 | |
| 1036 | static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 1037 | { |
| 1038 | int len = 0; |
| 1039 | char *link = __getname(); |
| 1040 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1041 | P9_DPRINTK(P9_DEBUG_VFS, "%s n", dentry->d_name.name); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1042 | |
| 1043 | if (!link) |
| 1044 | link = ERR_PTR(-ENOMEM); |
| 1045 | else { |
Latchesar Ionkov | 16cce6d | 2006-03-25 03:07:26 -0800 | [diff] [blame] | 1046 | len = v9fs_readlink(dentry, link, PATH_MAX); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1047 | |
| 1048 | if (len < 0) { |
Davi Arnaut | ce44eeb | 2005-11-07 00:59:36 -0800 | [diff] [blame] | 1049 | __putname(link); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1050 | link = ERR_PTR(len); |
| 1051 | } else |
Martin Stava | 2511cd0 | 2009-11-02 08:39:34 -0600 | [diff] [blame] | 1052 | link[min(len, PATH_MAX-1)] = 0; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1053 | } |
| 1054 | nd_set_link(nd, link); |
| 1055 | |
| 1056 | return NULL; |
| 1057 | } |
| 1058 | |
| 1059 | /** |
| 1060 | * v9fs_vfs_put_link - release a symlink path |
| 1061 | * @dentry: dentry for symlink |
| 1062 | * @nd: nameidata |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1063 | * @p: unused |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1064 | * |
| 1065 | */ |
| 1066 | |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1067 | static void |
| 1068 | v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1069 | { |
| 1070 | char *s = nd_get_link(nd); |
| 1071 | |
Duane Griffin | 6ff2320 | 2008-12-19 16:45:21 -0600 | [diff] [blame] | 1072 | P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name, |
| 1073 | IS_ERR(s) ? "<error>" : s); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1074 | if (!IS_ERR(s)) |
Davi Arnaut | ce44eeb | 2005-11-07 00:59:36 -0800 | [diff] [blame] | 1075 | __putname(s); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1078 | /** |
| 1079 | * v9fs_vfs_mkspecial - create a special file |
| 1080 | * @dir: inode to create special file in |
| 1081 | * @dentry: dentry to create |
| 1082 | * @mode: mode to create special file |
| 1083 | * @extension: 9p2000.u format extension string representing special file |
| 1084 | * |
| 1085 | */ |
| 1086 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1087 | static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry, |
| 1088 | int mode, const char *extension) |
| 1089 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1090 | u32 perm; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1091 | struct v9fs_session_info *v9ses; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1092 | struct p9_fid *fid; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1093 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 1094 | v9ses = v9fs_inode2v9ses(dir); |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 1095 | if (!v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1096 | P9_DPRINTK(P9_DEBUG_ERROR, "not extended\n"); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 1097 | return -EPERM; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1098 | } |
| 1099 | |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1100 | perm = unixmode2p9mode(v9ses, mode); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1101 | fid = v9fs_create(v9ses, dir, dentry, (char *) extension, perm, |
| 1102 | P9_OREAD); |
| 1103 | if (IS_ERR(fid)) |
| 1104 | return PTR_ERR(fid); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1105 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1106 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 1107 | return 0; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | /** |
| 1111 | * v9fs_vfs_symlink - helper function to create symlinks |
| 1112 | * @dir: directory inode containing symlink |
| 1113 | * @dentry: dentry for symlink |
| 1114 | * @symname: symlink data |
| 1115 | * |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1116 | * See Also: 9P2000.u RFC for more information |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1117 | * |
| 1118 | */ |
| 1119 | |
| 1120 | static int |
| 1121 | v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) |
| 1122 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1123 | P9_DPRINTK(P9_DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, |
| 1124 | dentry->d_name.name, symname); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1125 | |
| 1126 | return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname); |
| 1127 | } |
| 1128 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1129 | /** |
| 1130 | * v9fs_vfs_link - create a hardlink |
| 1131 | * @old_dentry: dentry for file to link to |
| 1132 | * @dir: inode destination for new link |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1133 | * @dentry: dentry for link |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1134 | * |
| 1135 | */ |
| 1136 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1137 | static int |
| 1138 | v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, |
| 1139 | struct dentry *dentry) |
| 1140 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1141 | int retval; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1142 | struct p9_fid *oldfid; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1143 | char *name; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1144 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1145 | P9_DPRINTK(P9_DEBUG_VFS, |
| 1146 | " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1147 | old_dentry->d_name.name); |
| 1148 | |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1149 | oldfid = v9fs_fid_clone(old_dentry); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1150 | if (IS_ERR(oldfid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1151 | return PTR_ERR(oldfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1152 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1153 | name = __getname(); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1154 | if (unlikely(!name)) { |
| 1155 | retval = -ENOMEM; |
| 1156 | goto clunk_fid; |
| 1157 | } |
Florin Malita | 0710d36 | 2006-06-25 05:48:31 -0700 | [diff] [blame] | 1158 | |
Latchesar Ionkov | 16cce6d | 2006-03-25 03:07:26 -0800 | [diff] [blame] | 1159 | sprintf(name, "%d\n", oldfid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1160 | retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1161 | __putname(name); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1162 | |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1163 | clunk_fid: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1164 | p9_client_clunk(oldfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1165 | return retval; |
| 1166 | } |
| 1167 | |
| 1168 | /** |
| 1169 | * v9fs_vfs_mknod - create a special file |
| 1170 | * @dir: inode destination for new link |
| 1171 | * @dentry: dentry for file |
| 1172 | * @mode: mode for creation |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1173 | * @rdev: device associated with special file |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1174 | * |
| 1175 | */ |
| 1176 | |
| 1177 | static int |
| 1178 | v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) |
| 1179 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1180 | int retval; |
| 1181 | char *name; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1182 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1183 | P9_DPRINTK(P9_DEBUG_VFS, |
| 1184 | " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1185 | dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev)); |
| 1186 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1187 | if (!new_valid_dev(rdev)) |
| 1188 | return -EINVAL; |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1189 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1190 | name = __getname(); |
Eugene Teo | c0291a0 | 2006-03-25 03:07:27 -0800 | [diff] [blame] | 1191 | if (!name) |
| 1192 | return -ENOMEM; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1193 | /* build extension */ |
| 1194 | if (S_ISBLK(mode)) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1195 | sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev)); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1196 | else if (S_ISCHR(mode)) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1197 | sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev)); |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1198 | else if (S_ISFIFO(mode)) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1199 | *name = 0; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1200 | else { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1201 | __putname(name); |
| 1202 | return -EINVAL; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1203 | } |
| 1204 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1205 | retval = v9fs_vfs_mkspecial(dir, dentry, mode, name); |
| 1206 | __putname(name); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1207 | |
| 1208 | return retval; |
| 1209 | } |
| 1210 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1211 | static const struct inode_operations v9fs_dir_inode_operations_ext = { |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1212 | .create = v9fs_vfs_create, |
| 1213 | .lookup = v9fs_vfs_lookup, |
| 1214 | .symlink = v9fs_vfs_symlink, |
| 1215 | .link = v9fs_vfs_link, |
| 1216 | .unlink = v9fs_vfs_unlink, |
| 1217 | .mkdir = v9fs_vfs_mkdir, |
| 1218 | .rmdir = v9fs_vfs_rmdir, |
| 1219 | .mknod = v9fs_vfs_mknod, |
| 1220 | .rename = v9fs_vfs_rename, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1221 | .getattr = v9fs_vfs_getattr, |
| 1222 | .setattr = v9fs_vfs_setattr, |
| 1223 | }; |
| 1224 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1225 | static const struct inode_operations v9fs_dir_inode_operations = { |
Eric Van Hensbergen | b501611 | 2005-09-09 13:04:27 -0700 | [diff] [blame] | 1226 | .create = v9fs_vfs_create, |
| 1227 | .lookup = v9fs_vfs_lookup, |
| 1228 | .unlink = v9fs_vfs_unlink, |
| 1229 | .mkdir = v9fs_vfs_mkdir, |
| 1230 | .rmdir = v9fs_vfs_rmdir, |
| 1231 | .mknod = v9fs_vfs_mknod, |
| 1232 | .rename = v9fs_vfs_rename, |
| 1233 | .getattr = v9fs_vfs_getattr, |
| 1234 | .setattr = v9fs_vfs_setattr, |
| 1235 | }; |
| 1236 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1237 | static const struct inode_operations v9fs_file_inode_operations = { |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1238 | .getattr = v9fs_vfs_getattr, |
| 1239 | .setattr = v9fs_vfs_setattr, |
| 1240 | }; |
| 1241 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1242 | static const struct inode_operations v9fs_symlink_inode_operations = { |
Al Viro | 204f2f0 | 2009-12-23 00:35:54 -0500 | [diff] [blame] | 1243 | .readlink = generic_readlink, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1244 | .follow_link = v9fs_vfs_follow_link, |
| 1245 | .put_link = v9fs_vfs_put_link, |
| 1246 | .getattr = v9fs_vfs_getattr, |
| 1247 | .setattr = v9fs_vfs_setattr, |
| 1248 | }; |