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