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> |
Aneesh Kumar K.V | ebf4626 | 2010-05-31 13:22:56 +0530 | [diff] [blame^] | 38 | #include <linux/xattr.h> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 39 | #include <net/9p/9p.h> |
| 40 | #include <net/9p/client.h> |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 41 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 42 | #include "v9fs.h" |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 43 | #include "v9fs_vfs.h" |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 44 | #include "fid.h" |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 45 | #include "cache.h" |
Aneesh Kumar K.V | ebf4626 | 2010-05-31 13:22:56 +0530 | [diff] [blame^] | 46 | #include "xattr.h" |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 47 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 48 | static const struct inode_operations v9fs_dir_inode_operations; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 49 | static const struct inode_operations v9fs_dir_inode_operations_dotu; |
| 50 | static const struct inode_operations v9fs_dir_inode_operations_dotl; |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 51 | static const struct inode_operations v9fs_file_inode_operations; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 52 | static const struct inode_operations v9fs_file_inode_operations_dotl; |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 53 | static const struct inode_operations v9fs_symlink_inode_operations; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 54 | static const struct inode_operations v9fs_symlink_inode_operations_dotl; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * unixmode2p9mode - convert unix mode bits to plan 9 |
| 58 | * @v9ses: v9fs session information |
| 59 | * @mode: mode to convert |
| 60 | * |
| 61 | */ |
| 62 | |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 63 | static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 64 | { |
| 65 | int res; |
| 66 | res = mode & 0777; |
| 67 | if (S_ISDIR(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 68 | res |= P9_DMDIR; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 69 | if (v9fs_proto_dotu(v9ses)) { |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 70 | if (S_ISLNK(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 71 | res |= P9_DMSYMLINK; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 72 | if (v9ses->nodev == 0) { |
| 73 | if (S_ISSOCK(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 74 | res |= P9_DMSOCKET; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 75 | if (S_ISFIFO(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 76 | res |= P9_DMNAMEDPIPE; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 77 | if (S_ISBLK(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 78 | res |= P9_DMDEVICE; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 79 | if (S_ISCHR(mode)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 80 | res |= P9_DMDEVICE; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | if ((mode & S_ISUID) == S_ISUID) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 84 | res |= P9_DMSETUID; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 85 | if ((mode & S_ISGID) == S_ISGID) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 86 | res |= P9_DMSETGID; |
Anthony Liguori | d199d65 | 2008-02-06 19:25:06 -0600 | [diff] [blame] | 87 | if ((mode & S_ISVTX) == S_ISVTX) |
| 88 | res |= P9_DMSETVTX; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 89 | if ((mode & P9_DMLINK)) |
| 90 | res |= P9_DMLINK; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | return res; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * p9mode2unixmode- convert plan9 mode bits to unix mode bits |
| 98 | * @v9ses: v9fs session information |
| 99 | * @mode: mode to convert |
| 100 | * |
| 101 | */ |
| 102 | |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 103 | static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 104 | { |
| 105 | int res; |
| 106 | |
| 107 | res = mode & 0777; |
| 108 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 109 | if ((mode & P9_DMDIR) == P9_DMDIR) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 110 | res |= S_IFDIR; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 111 | else if ((mode & P9_DMSYMLINK) && (v9fs_proto_dotu(v9ses))) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 112 | res |= S_IFLNK; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 113 | else if ((mode & P9_DMSOCKET) && (v9fs_proto_dotu(v9ses)) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 114 | && (v9ses->nodev == 0)) |
| 115 | res |= S_IFSOCK; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 116 | else if ((mode & P9_DMNAMEDPIPE) && (v9fs_proto_dotu(v9ses)) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 117 | && (v9ses->nodev == 0)) |
| 118 | res |= S_IFIFO; |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 119 | else if ((mode & P9_DMDEVICE) && (v9fs_proto_dotu(v9ses)) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 120 | && (v9ses->nodev == 0)) |
| 121 | res |= S_IFBLK; |
| 122 | else |
| 123 | res |= S_IFREG; |
| 124 | |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 125 | if (v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 126 | if ((mode & P9_DMSETUID) == P9_DMSETUID) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 127 | res |= S_ISUID; |
| 128 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 129 | if ((mode & P9_DMSETGID) == P9_DMSETGID) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 130 | res |= S_ISGID; |
Anthony Liguori | d199d65 | 2008-02-06 19:25:06 -0600 | [diff] [blame] | 131 | |
| 132 | if ((mode & P9_DMSETVTX) == P9_DMSETVTX) |
| 133 | res |= S_ISVTX; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | return res; |
| 137 | } |
| 138 | |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 139 | /** |
| 140 | * v9fs_uflags2omode- convert posix open flags to plan 9 mode bits |
| 141 | * @uflags: flags to convert |
Eric Van Hensbergen | 2e4bef4 | 2008-06-24 17:39:39 -0500 | [diff] [blame] | 142 | * @extended: if .u extensions are active |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 143 | */ |
| 144 | |
Eric Van Hensbergen | 2e4bef4 | 2008-06-24 17:39:39 -0500 | [diff] [blame] | 145 | int v9fs_uflags2omode(int uflags, int extended) |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 146 | { |
| 147 | int ret; |
| 148 | |
| 149 | ret = 0; |
| 150 | switch (uflags&3) { |
| 151 | default: |
| 152 | case O_RDONLY: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 153 | ret = P9_OREAD; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 154 | break; |
| 155 | |
| 156 | case O_WRONLY: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 157 | ret = P9_OWRITE; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 158 | break; |
| 159 | |
| 160 | case O_RDWR: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 161 | ret = P9_ORDWR; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 162 | break; |
| 163 | } |
| 164 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 165 | if (uflags & O_TRUNC) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 166 | ret |= P9_OTRUNC; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 167 | |
Eric Van Hensbergen | 2e4bef4 | 2008-06-24 17:39:39 -0500 | [diff] [blame] | 168 | if (extended) { |
| 169 | if (uflags & O_EXCL) |
| 170 | ret |= P9_OEXCL; |
| 171 | |
| 172 | if (uflags & O_APPEND) |
| 173 | ret |= P9_OAPPEND; |
| 174 | } |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 175 | |
| 176 | return ret; |
| 177 | } |
| 178 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 179 | /** |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 180 | * v9fs_blank_wstat - helper function to setup a 9P stat structure |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 181 | * @wstat: structure to initialize |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 182 | * |
| 183 | */ |
| 184 | |
M. Mohan Kumar | 7a4439c | 2010-02-08 15:36:48 -0600 | [diff] [blame] | 185 | void |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 186 | v9fs_blank_wstat(struct p9_wstat *wstat) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 187 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 188 | wstat->type = ~0; |
| 189 | wstat->dev = ~0; |
| 190 | wstat->qid.type = ~0; |
| 191 | wstat->qid.version = ~0; |
| 192 | *((long long *)&wstat->qid.path) = ~0; |
| 193 | wstat->mode = ~0; |
| 194 | wstat->atime = ~0; |
| 195 | wstat->mtime = ~0; |
| 196 | wstat->length = ~0; |
| 197 | wstat->name = NULL; |
| 198 | wstat->uid = NULL; |
| 199 | wstat->gid = NULL; |
| 200 | wstat->muid = NULL; |
| 201 | wstat->n_uid = ~0; |
| 202 | wstat->n_gid = ~0; |
| 203 | wstat->n_muid = ~0; |
| 204 | wstat->extension = NULL; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 207 | #ifdef CONFIG_9P_FSCACHE |
| 208 | /** |
| 209 | * v9fs_alloc_inode - helper function to allocate an inode |
| 210 | * This callback is executed before setting up the inode so that we |
| 211 | * can associate a vcookie with each inode. |
| 212 | * |
| 213 | */ |
| 214 | |
| 215 | struct inode *v9fs_alloc_inode(struct super_block *sb) |
| 216 | { |
| 217 | struct v9fs_cookie *vcookie; |
| 218 | vcookie = (struct v9fs_cookie *)kmem_cache_alloc(vcookie_cache, |
| 219 | GFP_KERNEL); |
| 220 | if (!vcookie) |
| 221 | return NULL; |
| 222 | |
| 223 | vcookie->fscache = NULL; |
| 224 | vcookie->qid = NULL; |
| 225 | spin_lock_init(&vcookie->lock); |
| 226 | return &vcookie->inode; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * v9fs_destroy_inode - destroy an inode |
| 231 | * |
| 232 | */ |
| 233 | |
| 234 | void v9fs_destroy_inode(struct inode *inode) |
| 235 | { |
| 236 | kmem_cache_free(vcookie_cache, v9fs_inode2cookie(inode)); |
| 237 | } |
| 238 | #endif |
| 239 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 240 | /** |
Eric Van Hensbergen | 09d34ee | 2010-08-02 14:28:09 -0500 | [diff] [blame] | 241 | * v9fs_get_fsgid_for_create - Helper function to get the gid for creating a |
| 242 | * new file system object. This checks the S_ISGID to determine the owning |
| 243 | * group of the new file system object. |
| 244 | */ |
| 245 | |
| 246 | static gid_t v9fs_get_fsgid_for_create(struct inode *dir_inode) |
| 247 | { |
| 248 | BUG_ON(dir_inode == NULL); |
| 249 | |
| 250 | if (dir_inode->i_mode & S_ISGID) { |
| 251 | /* set_gid bit is set.*/ |
| 252 | return dir_inode->i_gid; |
| 253 | } |
| 254 | return current_fsgid(); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * v9fs_dentry_from_dir_inode - helper function to get the dentry from |
| 259 | * dir inode. |
| 260 | * |
| 261 | */ |
| 262 | |
| 263 | struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode) |
| 264 | { |
| 265 | struct dentry *dentry; |
| 266 | |
| 267 | spin_lock(&dcache_lock); |
| 268 | /* Directory should have only one entry. */ |
| 269 | BUG_ON(S_ISDIR(inode->i_mode) && !list_is_singular(&inode->i_dentry)); |
| 270 | dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias); |
| 271 | spin_unlock(&dcache_lock); |
| 272 | return dentry; |
| 273 | } |
| 274 | |
| 275 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 276 | * v9fs_get_inode - helper function to setup an inode |
| 277 | * @sb: superblock |
| 278 | * @mode: mode to setup inode with |
| 279 | * |
| 280 | */ |
| 281 | |
| 282 | struct inode *v9fs_get_inode(struct super_block *sb, int mode) |
| 283 | { |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 284 | int err; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 285 | struct inode *inode; |
Eric Van Hensbergen | b501611 | 2005-09-09 13:04:27 -0700 | [diff] [blame] | 286 | struct v9fs_session_info *v9ses = sb->s_fs_info; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 287 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 288 | 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] | 289 | |
| 290 | inode = new_inode(sb); |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 291 | if (!inode) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 292 | P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n"); |
Abhishek Kulkarni | 48559b4c | 2009-08-17 16:32:18 -0500 | [diff] [blame] | 293 | return ERR_PTR(-ENOMEM); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 294 | } |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 295 | |
Dmitry Monakhov | 217f206 | 2010-03-04 17:30:57 +0300 | [diff] [blame] | 296 | inode_init_owner(inode, NULL, mode); |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 297 | inode->i_blocks = 0; |
| 298 | inode->i_rdev = 0; |
| 299 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 300 | inode->i_mapping->a_ops = &v9fs_addr_operations; |
| 301 | |
| 302 | switch (mode & S_IFMT) { |
| 303 | case S_IFIFO: |
| 304 | case S_IFBLK: |
| 305 | case S_IFCHR: |
| 306 | case S_IFSOCK: |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 307 | if (v9fs_proto_dotl(v9ses)) { |
| 308 | inode->i_op = &v9fs_file_inode_operations_dotl; |
| 309 | inode->i_fop = &v9fs_file_operations_dotl; |
| 310 | } else if (v9fs_proto_dotu(v9ses)) { |
| 311 | inode->i_op = &v9fs_file_inode_operations; |
| 312 | inode->i_fop = &v9fs_file_operations; |
| 313 | } else { |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 314 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 315 | "special files without extended mode\n"); |
| 316 | err = -EINVAL; |
| 317 | goto error; |
| 318 | } |
| 319 | init_special_inode(inode, inode->i_mode, inode->i_rdev); |
| 320 | break; |
| 321 | case S_IFREG: |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 322 | if (v9fs_proto_dotl(v9ses)) { |
| 323 | inode->i_op = &v9fs_file_inode_operations_dotl; |
| 324 | inode->i_fop = &v9fs_file_operations_dotl; |
| 325 | } else { |
| 326 | inode->i_op = &v9fs_file_inode_operations; |
| 327 | inode->i_fop = &v9fs_file_operations; |
| 328 | } |
| 329 | |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 330 | break; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 331 | |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 332 | case S_IFLNK: |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 333 | if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) { |
| 334 | P9_DPRINTK(P9_DEBUG_ERROR, "extended modes used with " |
| 335 | "legacy protocol.\n"); |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 336 | err = -EINVAL; |
| 337 | goto error; |
| 338 | } |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 339 | |
| 340 | if (v9fs_proto_dotl(v9ses)) |
| 341 | inode->i_op = &v9fs_symlink_inode_operations_dotl; |
| 342 | else |
| 343 | inode->i_op = &v9fs_symlink_inode_operations; |
| 344 | |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 345 | break; |
| 346 | case S_IFDIR: |
| 347 | inc_nlink(inode); |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 348 | if (v9fs_proto_dotl(v9ses)) |
| 349 | inode->i_op = &v9fs_dir_inode_operations_dotl; |
| 350 | else if (v9fs_proto_dotu(v9ses)) |
| 351 | inode->i_op = &v9fs_dir_inode_operations_dotu; |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 352 | else |
| 353 | inode->i_op = &v9fs_dir_inode_operations; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 354 | |
| 355 | if (v9fs_proto_dotl(v9ses)) |
| 356 | inode->i_fop = &v9fs_dir_operations_dotl; |
| 357 | else |
| 358 | inode->i_fop = &v9fs_dir_operations; |
| 359 | |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 360 | break; |
| 361 | default: |
| 362 | P9_DPRINTK(P9_DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n", |
| 363 | mode, mode & S_IFMT); |
| 364 | err = -EINVAL; |
| 365 | goto error; |
| 366 | } |
| 367 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 368 | return inode; |
Abhishek Kulkarni | 2bb5411 | 2009-07-19 13:41:56 -0600 | [diff] [blame] | 369 | |
| 370 | error: |
| 371 | iput(inode); |
| 372 | return ERR_PTR(err); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 375 | /* |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 376 | static struct v9fs_fid* |
| 377 | v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry) |
| 378 | { |
| 379 | int err; |
Mika Kukkonen | 736c4b8 | 2006-12-06 20:36:29 -0800 | [diff] [blame] | 380 | int nfid; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 381 | struct v9fs_fid *ret; |
| 382 | struct v9fs_fcall *fcall; |
| 383 | |
| 384 | nfid = v9fs_get_idpool(&v9ses->fidpool); |
| 385 | if (nfid < 0) { |
| 386 | eprintk(KERN_WARNING, "no free fids available\n"); |
Latchesar Ionkov | 731805b | 2006-03-07 21:55:42 -0800 | [diff] [blame] | 387 | return ERR_PTR(-ENOSPC); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name, |
| 391 | &fcall); |
| 392 | |
| 393 | if (err < 0) { |
Latchesar Ionkov | 41e5a6a | 2006-05-15 09:44:21 -0700 | [diff] [blame] | 394 | if (fcall && fcall->id == RWALK) |
| 395 | goto clunk_fid; |
| 396 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 397 | PRINT_FCALL_ERROR("walk error", fcall); |
| 398 | v9fs_put_idpool(nfid, &v9ses->fidpool); |
| 399 | goto error; |
| 400 | } |
| 401 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 402 | kfree(fcall); |
Latchesar Ionkov | 3cf6429 | 2006-01-08 01:04:58 -0800 | [diff] [blame] | 403 | fcall = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 404 | ret = v9fs_fid_create(v9ses, nfid); |
| 405 | if (!ret) { |
| 406 | err = -ENOMEM; |
| 407 | goto clunk_fid; |
| 408 | } |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 409 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 410 | err = v9fs_fid_insert(ret, dentry); |
| 411 | if (err < 0) { |
| 412 | v9fs_fid_destroy(ret); |
| 413 | goto clunk_fid; |
Latchesar Ionkov | 0b8dd17 | 2005-09-27 21:45:24 -0700 | [diff] [blame] | 414 | } |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 415 | |
| 416 | return ret; |
| 417 | |
| 418 | clunk_fid: |
| 419 | v9fs_t_clunk(v9ses, nfid); |
| 420 | |
| 421 | error: |
| 422 | kfree(fcall); |
| 423 | return ERR_PTR(err); |
| 424 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 425 | */ |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 426 | |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 427 | |
| 428 | /** |
| 429 | * v9fs_clear_inode - release an inode |
| 430 | * @inode: inode to release |
| 431 | * |
| 432 | */ |
| 433 | void v9fs_clear_inode(struct inode *inode) |
| 434 | { |
| 435 | filemap_fdatawrite(inode->i_mapping); |
| 436 | |
| 437 | #ifdef CONFIG_9P_FSCACHE |
| 438 | v9fs_cache_inode_put_cookie(inode); |
| 439 | #endif |
| 440 | } |
| 441 | |
Latchesar Ionkov | 5174fda | 2006-03-25 03:07:25 -0800 | [diff] [blame] | 442 | static struct inode * |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 443 | v9fs_inode(struct v9fs_session_info *v9ses, struct p9_fid *fid, |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 444 | struct super_block *sb) |
| 445 | { |
| 446 | int err, umode; |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 447 | struct inode *ret = NULL; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 448 | struct p9_wstat *st; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 449 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 450 | st = p9_client_stat(fid); |
Abhishek Kulkarni | 02bc356 | 2009-07-19 13:41:54 -0600 | [diff] [blame] | 451 | if (IS_ERR(st)) |
| 452 | return ERR_CAST(st); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 453 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 454 | umode = p9mode2unixmode(v9ses, st->mode); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 455 | ret = v9fs_get_inode(sb, umode); |
| 456 | if (IS_ERR(ret)) { |
| 457 | err = PTR_ERR(ret); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 458 | goto error; |
| 459 | } |
| 460 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 461 | v9fs_stat2inode(st, ret, sb); |
| 462 | ret->i_ino = v9fs_qid2ino(&st->qid); |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 463 | |
| 464 | #ifdef CONFIG_9P_FSCACHE |
| 465 | v9fs_vcookie_set_qid(ret, &st->qid); |
| 466 | v9fs_cache_inode_get_cookie(ret); |
| 467 | #endif |
Abhishek Kulkarni | 02bc356 | 2009-07-19 13:41:54 -0600 | [diff] [blame] | 468 | p9stat_free(st); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 469 | kfree(st); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 470 | return ret; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 471 | error: |
Abhishek Kulkarni | 02bc356 | 2009-07-19 13:41:54 -0600 | [diff] [blame] | 472 | p9stat_free(st); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 473 | kfree(st); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 474 | return ERR_PTR(err); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 477 | static struct inode * |
| 478 | v9fs_inode_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid, |
| 479 | struct super_block *sb) |
| 480 | { |
| 481 | struct inode *ret = NULL; |
| 482 | int err; |
| 483 | struct p9_stat_dotl *st; |
| 484 | |
| 485 | st = p9_client_getattr_dotl(fid, P9_STATS_BASIC); |
| 486 | if (IS_ERR(st)) |
| 487 | return ERR_CAST(st); |
| 488 | |
| 489 | ret = v9fs_get_inode(sb, st->st_mode); |
| 490 | if (IS_ERR(ret)) { |
| 491 | err = PTR_ERR(ret); |
| 492 | goto error; |
| 493 | } |
| 494 | |
| 495 | v9fs_stat2inode_dotl(st, ret); |
| 496 | ret->i_ino = v9fs_qid2ino(&st->qid); |
| 497 | #ifdef CONFIG_9P_FSCACHE |
| 498 | v9fs_vcookie_set_qid(ret, &st->qid); |
| 499 | v9fs_cache_inode_get_cookie(ret); |
| 500 | #endif |
| 501 | kfree(st); |
| 502 | return ret; |
| 503 | error: |
| 504 | kfree(st); |
| 505 | return ERR_PTR(err); |
| 506 | } |
| 507 | |
| 508 | /** |
| 509 | * v9fs_inode_from_fid - Helper routine to populate an inode by |
| 510 | * issuing a attribute request |
| 511 | * @v9ses: session information |
| 512 | * @fid: fid to issue attribute request for |
| 513 | * @sb: superblock on which to create inode |
| 514 | * |
| 515 | */ |
| 516 | static inline struct inode * |
| 517 | v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid, |
| 518 | struct super_block *sb) |
| 519 | { |
| 520 | if (v9fs_proto_dotl(v9ses)) |
| 521 | return v9fs_inode_dotl(v9ses, fid, sb); |
| 522 | else |
| 523 | return v9fs_inode(v9ses, fid, sb); |
| 524 | } |
| 525 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 526 | /** |
| 527 | * v9fs_remove - helper function to remove files and directories |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 528 | * @dir: directory inode that is being deleted |
| 529 | * @file: dentry that is being deleted |
| 530 | * @rmdir: removing a directory |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 531 | * |
| 532 | */ |
| 533 | |
| 534 | static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir) |
| 535 | { |
Aneesh Kumar K.V | d994f40 | 2010-03-29 18:14:50 -0500 | [diff] [blame] | 536 | int retval; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 537 | struct inode *file_inode; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 538 | struct p9_fid *v9fid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 539 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 540 | 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] | 541 | rmdir); |
| 542 | |
| 543 | file_inode = file->d_inode; |
Latchesar Ionkov | c959df9 | 2007-04-23 14:41:11 -0700 | [diff] [blame] | 544 | v9fid = v9fs_fid_clone(file); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 545 | if (IS_ERR(v9fid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 546 | return PTR_ERR(v9fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 547 | |
Aneesh Kumar K.V | d994f40 | 2010-03-29 18:14:50 -0500 | [diff] [blame] | 548 | retval = p9_client_remove(v9fid); |
| 549 | if (!retval) |
| 550 | drop_nlink(file_inode); |
| 551 | return retval; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 554 | static int |
| 555 | v9fs_open_created(struct inode *inode, struct file *file) |
| 556 | { |
| 557 | return 0; |
| 558 | } |
| 559 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 560 | |
| 561 | /** |
| 562 | * v9fs_create - Create a file |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 563 | * @v9ses: session information |
| 564 | * @dir: directory that dentry is being created in |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 565 | * @dentry: dentry that is being created |
Abhishek Kulkarni | 0e15597 | 2009-07-19 13:41:55 -0600 | [diff] [blame] | 566 | * @extension: 9p2000.u extension string to support devices, etc. |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 567 | * @perm: create permissions |
| 568 | * @mode: open mode |
| 569 | * |
| 570 | */ |
| 571 | static struct p9_fid * |
| 572 | v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir, |
| 573 | struct dentry *dentry, char *extension, u32 perm, u8 mode) |
| 574 | { |
| 575 | int err; |
| 576 | char *name; |
| 577 | struct p9_fid *dfid, *ofid, *fid; |
| 578 | struct inode *inode; |
| 579 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 580 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name); |
| 581 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 582 | err = 0; |
| 583 | ofid = NULL; |
| 584 | fid = NULL; |
| 585 | name = (char *) dentry->d_name.name; |
Venkateswararao Jujjuri | 6d27e64 | 2010-05-10 18:08:28 +0000 | [diff] [blame] | 586 | dfid = v9fs_fid_lookup(dentry->d_parent); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 587 | if (IS_ERR(dfid)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 588 | err = PTR_ERR(dfid); |
Venkateswararao Jujjuri | 6d27e64 | 2010-05-10 18:08:28 +0000 | [diff] [blame] | 589 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); |
| 590 | return ERR_PTR(err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | /* clone a fid to use for creation */ |
| 594 | ofid = p9_client_walk(dfid, 0, NULL, 1); |
| 595 | if (IS_ERR(ofid)) { |
| 596 | err = PTR_ERR(ofid); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 597 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); |
Venkateswararao Jujjuri | 6d27e64 | 2010-05-10 18:08:28 +0000 | [diff] [blame] | 598 | return ERR_PTR(err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | err = p9_client_fcreate(ofid, name, perm, mode, extension); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 602 | if (err < 0) { |
| 603 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 604 | goto error; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 605 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 606 | |
| 607 | /* now walk from the parent so we can get unopened fid */ |
Venkateswararao Jujjuri | 6d27e64 | 2010-05-10 18:08:28 +0000 | [diff] [blame] | 608 | fid = p9_client_walk(dfid, 1, &name, 1); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 609 | if (IS_ERR(fid)) { |
| 610 | err = PTR_ERR(fid); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 611 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 612 | fid = NULL; |
| 613 | goto error; |
Venkateswararao Jujjuri | 6d27e64 | 2010-05-10 18:08:28 +0000 | [diff] [blame] | 614 | } |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 615 | |
| 616 | /* instantiate inode and assign the unopened fid to the dentry */ |
| 617 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
| 618 | if (IS_ERR(inode)) { |
| 619 | err = PTR_ERR(inode); |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 620 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 621 | goto error; |
| 622 | } |
| 623 | |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 624 | if (v9ses->cache) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 625 | dentry->d_op = &v9fs_cached_dentry_operations; |
| 626 | else |
| 627 | dentry->d_op = &v9fs_dentry_operations; |
| 628 | |
| 629 | d_instantiate(dentry, inode); |
Abhishek Kulkarni | 50fb6d2 | 2009-07-19 13:41:57 -0600 | [diff] [blame] | 630 | err = v9fs_fid_add(dentry, fid); |
| 631 | if (err < 0) |
| 632 | goto error; |
| 633 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 634 | return ofid; |
| 635 | |
| 636 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 637 | if (ofid) |
| 638 | p9_client_clunk(ofid); |
| 639 | |
| 640 | if (fid) |
| 641 | p9_client_clunk(fid); |
| 642 | |
| 643 | return ERR_PTR(err); |
| 644 | } |
| 645 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 646 | /** |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 647 | * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol. |
| 648 | * @dir: directory inode that is being created |
| 649 | * @dentry: dentry that is being deleted |
| 650 | * @mode: create permissions |
| 651 | * @nd: path information |
| 652 | * |
| 653 | */ |
| 654 | |
| 655 | static int |
| 656 | v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int mode, |
| 657 | struct nameidata *nd) |
| 658 | { |
| 659 | int err = 0; |
| 660 | char *name = NULL; |
| 661 | gid_t gid; |
| 662 | int flags; |
| 663 | struct v9fs_session_info *v9ses; |
| 664 | struct p9_fid *fid = NULL; |
| 665 | struct p9_fid *dfid, *ofid; |
| 666 | struct file *filp; |
| 667 | struct p9_qid qid; |
| 668 | struct inode *inode; |
| 669 | |
| 670 | v9ses = v9fs_inode2v9ses(dir); |
| 671 | if (nd && nd->flags & LOOKUP_OPEN) |
| 672 | flags = nd->intent.open.flags - 1; |
| 673 | else |
| 674 | flags = O_RDWR; |
| 675 | |
| 676 | name = (char *) dentry->d_name.name; |
| 677 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_create_dotl: name:%s flags:0x%x " |
| 678 | "mode:0x%x\n", name, flags, mode); |
| 679 | |
| 680 | dfid = v9fs_fid_lookup(dentry->d_parent); |
| 681 | if (IS_ERR(dfid)) { |
| 682 | err = PTR_ERR(dfid); |
| 683 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); |
| 684 | return err; |
| 685 | } |
| 686 | |
| 687 | /* clone a fid to use for creation */ |
| 688 | ofid = p9_client_walk(dfid, 0, NULL, 1); |
| 689 | if (IS_ERR(ofid)) { |
| 690 | err = PTR_ERR(ofid); |
| 691 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); |
| 692 | return err; |
| 693 | } |
| 694 | |
| 695 | gid = v9fs_get_fsgid_for_create(dir); |
| 696 | err = p9_client_create_dotl(ofid, name, flags, mode, gid, &qid); |
| 697 | if (err < 0) { |
| 698 | P9_DPRINTK(P9_DEBUG_VFS, |
| 699 | "p9_client_open_dotl failed in creat %d\n", |
| 700 | err); |
| 701 | goto error; |
| 702 | } |
| 703 | |
| 704 | /* No need to populate the inode if we are not opening the file AND |
| 705 | * not in cached mode. |
| 706 | */ |
| 707 | if (!v9ses->cache && !(nd && nd->flags & LOOKUP_OPEN)) { |
| 708 | /* Not in cached mode. No need to populate inode with stat */ |
| 709 | dentry->d_op = &v9fs_dentry_operations; |
| 710 | p9_client_clunk(ofid); |
| 711 | d_instantiate(dentry, NULL); |
| 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | /* Now walk from the parent so we can get an unopened fid. */ |
| 716 | fid = p9_client_walk(dfid, 1, &name, 1); |
| 717 | if (IS_ERR(fid)) { |
| 718 | err = PTR_ERR(fid); |
| 719 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err); |
| 720 | fid = NULL; |
| 721 | goto error; |
| 722 | } |
| 723 | |
| 724 | /* instantiate inode and assign the unopened fid to dentry */ |
| 725 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
| 726 | if (IS_ERR(inode)) { |
| 727 | err = PTR_ERR(inode); |
| 728 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err); |
| 729 | goto error; |
| 730 | } |
| 731 | dentry->d_op = &v9fs_cached_dentry_operations; |
| 732 | d_instantiate(dentry, inode); |
| 733 | err = v9fs_fid_add(dentry, fid); |
| 734 | if (err < 0) |
| 735 | goto error; |
| 736 | |
| 737 | /* if we are opening a file, assign the open fid to the file */ |
| 738 | if (nd && nd->flags & LOOKUP_OPEN) { |
| 739 | filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created); |
| 740 | if (IS_ERR(filp)) { |
| 741 | p9_client_clunk(ofid); |
| 742 | return PTR_ERR(filp); |
| 743 | } |
| 744 | filp->private_data = ofid; |
| 745 | } else |
| 746 | p9_client_clunk(ofid); |
| 747 | |
| 748 | return 0; |
| 749 | |
| 750 | error: |
| 751 | if (ofid) |
| 752 | p9_client_clunk(ofid); |
| 753 | if (fid) |
| 754 | p9_client_clunk(fid); |
| 755 | return err; |
| 756 | } |
| 757 | |
| 758 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 759 | * v9fs_vfs_create - VFS hook to create files |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 760 | * @dir: directory inode that is being created |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 761 | * @dentry: dentry that is being deleted |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 762 | * @mode: create permissions |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 763 | * @nd: path information |
| 764 | * |
| 765 | */ |
| 766 | |
| 767 | static int |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 768 | v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 769 | struct nameidata *nd) |
| 770 | { |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 771 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 772 | u32 perm; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 773 | int flags; |
| 774 | struct v9fs_session_info *v9ses; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 775 | struct p9_fid *fid; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 776 | struct file *filp; |
| 777 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 778 | err = 0; |
| 779 | fid = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 780 | v9ses = v9fs_inode2v9ses(dir); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 781 | perm = unixmode2p9mode(v9ses, mode); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 782 | if (nd && nd->flags & LOOKUP_OPEN) |
| 783 | flags = nd->intent.open.flags - 1; |
| 784 | else |
| 785 | flags = O_RDWR; |
| 786 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 787 | fid = v9fs_create(v9ses, dir, dentry, NULL, perm, |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 788 | v9fs_uflags2omode(flags, |
| 789 | v9fs_proto_dotu(v9ses))); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 790 | if (IS_ERR(fid)) { |
| 791 | err = PTR_ERR(fid); |
| 792 | fid = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 793 | goto error; |
| 794 | } |
| 795 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 796 | /* 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] | 797 | if (nd && nd->flags & LOOKUP_OPEN) { |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 798 | filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created); |
| 799 | if (IS_ERR(filp)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 800 | err = PTR_ERR(filp); |
| 801 | goto error; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 802 | } |
| 803 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 804 | filp->private_data = fid; |
| 805 | } else |
| 806 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 807 | |
| 808 | return 0; |
| 809 | |
| 810 | error: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 811 | if (fid) |
| 812 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 813 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 814 | return err; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /** |
| 818 | * v9fs_vfs_mkdir - VFS mkdir hook to create a directory |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 819 | * @dir: inode that is being unlinked |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 820 | * @dentry: dentry that is being unlinked |
| 821 | * @mode: mode for new directory |
| 822 | * |
| 823 | */ |
| 824 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 825 | 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] | 826 | { |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 827 | int err; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 828 | u32 perm; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 829 | struct v9fs_session_info *v9ses; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 830 | struct p9_fid *fid; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 831 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 832 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name); |
| 833 | err = 0; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 834 | v9ses = v9fs_inode2v9ses(dir); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 835 | perm = unixmode2p9mode(v9ses, mode | S_IFDIR); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 836 | fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_OREAD); |
| 837 | if (IS_ERR(fid)) { |
| 838 | err = PTR_ERR(fid); |
| 839 | fid = NULL; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 840 | } |
| 841 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 842 | if (fid) |
| 843 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 844 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 845 | return err; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 846 | } |
| 847 | |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 848 | |
| 849 | /** |
| 850 | * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory |
| 851 | * @dir: inode that is being unlinked |
| 852 | * @dentry: dentry that is being unlinked |
| 853 | * @mode: mode for new directory |
| 854 | * |
| 855 | */ |
| 856 | |
| 857 | static int v9fs_vfs_mkdir_dotl(struct inode *dir, struct dentry *dentry, |
| 858 | int mode) |
| 859 | { |
| 860 | int err; |
| 861 | struct v9fs_session_info *v9ses; |
| 862 | struct p9_fid *fid = NULL, *dfid = NULL; |
| 863 | gid_t gid; |
| 864 | char *name; |
| 865 | struct inode *inode; |
| 866 | struct p9_qid qid; |
| 867 | struct dentry *dir_dentry; |
| 868 | |
| 869 | P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name); |
| 870 | err = 0; |
| 871 | v9ses = v9fs_inode2v9ses(dir); |
| 872 | |
| 873 | mode |= S_IFDIR; |
| 874 | dir_dentry = v9fs_dentry_from_dir_inode(dir); |
| 875 | dfid = v9fs_fid_lookup(dir_dentry); |
| 876 | if (IS_ERR(dfid)) { |
| 877 | err = PTR_ERR(dfid); |
| 878 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); |
| 879 | dfid = NULL; |
| 880 | goto error; |
| 881 | } |
| 882 | |
| 883 | gid = v9fs_get_fsgid_for_create(dir); |
| 884 | if (gid < 0) { |
| 885 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_fsgid_for_create failed\n"); |
| 886 | goto error; |
| 887 | } |
| 888 | |
| 889 | name = (char *) dentry->d_name.name; |
| 890 | err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid); |
| 891 | if (err < 0) |
| 892 | goto error; |
| 893 | |
| 894 | /* instantiate inode and assign the unopened fid to the dentry */ |
| 895 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { |
| 896 | fid = p9_client_walk(dfid, 1, &name, 1); |
| 897 | if (IS_ERR(fid)) { |
| 898 | err = PTR_ERR(fid); |
| 899 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", |
| 900 | err); |
| 901 | fid = NULL; |
| 902 | goto error; |
| 903 | } |
| 904 | |
| 905 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
| 906 | if (IS_ERR(inode)) { |
| 907 | err = PTR_ERR(inode); |
| 908 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", |
| 909 | err); |
| 910 | goto error; |
| 911 | } |
| 912 | dentry->d_op = &v9fs_cached_dentry_operations; |
| 913 | d_instantiate(dentry, inode); |
| 914 | err = v9fs_fid_add(dentry, fid); |
| 915 | if (err < 0) |
| 916 | goto error; |
| 917 | fid = NULL; |
| 918 | } |
| 919 | error: |
| 920 | if (fid) |
| 921 | p9_client_clunk(fid); |
| 922 | return err; |
| 923 | } |
| 924 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 925 | /** |
| 926 | * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode |
| 927 | * @dir: inode that is being walked from |
| 928 | * @dentry: dentry that is being walked to? |
| 929 | * @nameidata: path data |
| 930 | * |
| 931 | */ |
| 932 | |
| 933 | static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, |
| 934 | struct nameidata *nameidata) |
| 935 | { |
| 936 | struct super_block *sb; |
| 937 | struct v9fs_session_info *v9ses; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 938 | struct p9_fid *dfid, *fid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 939 | struct inode *inode; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 940 | char *name; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 941 | int result = 0; |
| 942 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 943 | 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] | 944 | dir, dentry->d_name.name, dentry, nameidata); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 945 | |
Sripathi Kodi | 11e9b49 | 2010-03-29 18:13:59 -0500 | [diff] [blame] | 946 | if (dentry->d_name.len > NAME_MAX) |
| 947 | return ERR_PTR(-ENAMETOOLONG); |
| 948 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 949 | sb = dir->i_sb; |
| 950 | v9ses = v9fs_inode2v9ses(dir); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 951 | dfid = v9fs_fid_lookup(dentry->d_parent); |
| 952 | if (IS_ERR(dfid)) |
David Howells | e231c2e | 2008-02-07 00:15:26 -0800 | [diff] [blame] | 953 | return ERR_CAST(dfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 954 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 955 | name = (char *) dentry->d_name.name; |
| 956 | fid = p9_client_walk(dfid, 1, &name, 1); |
| 957 | if (IS_ERR(fid)) { |
| 958 | result = PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 959 | if (result == -ENOENT) { |
Aneesh Kumar K.V | 85e0df2 | 2010-05-14 13:04:39 +0000 | [diff] [blame] | 960 | inode = NULL; |
| 961 | goto inst_out; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 962 | } |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 963 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 964 | return ERR_PTR(result); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 965 | } |
| 966 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 967 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
| 968 | if (IS_ERR(inode)) { |
| 969 | result = PTR_ERR(inode); |
| 970 | inode = NULL; |
| 971 | goto error; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 972 | } |
| 973 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 974 | result = v9fs_fid_add(dentry, fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 975 | if (result < 0) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 976 | goto error; |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 977 | |
Aneesh Kumar K.V | 85e0df2 | 2010-05-14 13:04:39 +0000 | [diff] [blame] | 978 | inst_out: |
| 979 | if (v9ses->cache) |
Eric Van Hensbergen | e03abc0 | 2007-02-11 13:21:39 -0600 | [diff] [blame] | 980 | dentry->d_op = &v9fs_cached_dentry_operations; |
| 981 | else |
| 982 | dentry->d_op = &v9fs_dentry_operations; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 983 | |
| 984 | d_add(dentry, inode); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 985 | return NULL; |
| 986 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 987 | error: |
Julien Brunel | 62aa528 | 2008-09-24 16:22:22 -0500 | [diff] [blame] | 988 | p9_client_clunk(fid); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 989 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 990 | return ERR_PTR(result); |
| 991 | } |
| 992 | |
| 993 | /** |
| 994 | * v9fs_vfs_unlink - VFS unlink hook to delete an inode |
| 995 | * @i: inode that is being unlinked |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 996 | * @d: dentry that is being unlinked |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 997 | * |
| 998 | */ |
| 999 | |
| 1000 | static int v9fs_vfs_unlink(struct inode *i, struct dentry *d) |
| 1001 | { |
| 1002 | return v9fs_remove(i, d, 0); |
| 1003 | } |
| 1004 | |
| 1005 | /** |
| 1006 | * v9fs_vfs_rmdir - VFS unlink hook to delete a directory |
| 1007 | * @i: inode that is being unlinked |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1008 | * @d: dentry that is being unlinked |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1009 | * |
| 1010 | */ |
| 1011 | |
| 1012 | static int v9fs_vfs_rmdir(struct inode *i, struct dentry *d) |
| 1013 | { |
| 1014 | return v9fs_remove(i, d, 1); |
| 1015 | } |
| 1016 | |
| 1017 | /** |
| 1018 | * v9fs_vfs_rename - VFS hook to rename an inode |
| 1019 | * @old_dir: old dir inode |
| 1020 | * @old_dentry: old dentry |
| 1021 | * @new_dir: new dir inode |
| 1022 | * @new_dentry: new dentry |
| 1023 | * |
| 1024 | */ |
| 1025 | |
| 1026 | static int |
| 1027 | v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, |
| 1028 | struct inode *new_dir, struct dentry *new_dentry) |
| 1029 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1030 | struct inode *old_inode; |
| 1031 | struct v9fs_session_info *v9ses; |
| 1032 | struct p9_fid *oldfid; |
| 1033 | struct p9_fid *olddirfid; |
| 1034 | struct p9_fid *newdirfid; |
| 1035 | struct p9_wstat wstat; |
| 1036 | int retval; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1037 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1038 | P9_DPRINTK(P9_DEBUG_VFS, "\n"); |
| 1039 | retval = 0; |
| 1040 | old_inode = old_dentry->d_inode; |
| 1041 | v9ses = v9fs_inode2v9ses(old_inode); |
| 1042 | oldfid = v9fs_fid_lookup(old_dentry); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1043 | if (IS_ERR(oldfid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1044 | return PTR_ERR(oldfid); |
| 1045 | |
| 1046 | olddirfid = v9fs_fid_clone(old_dentry->d_parent); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1047 | if (IS_ERR(olddirfid)) { |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1048 | retval = PTR_ERR(olddirfid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1049 | goto done; |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | newdirfid = v9fs_fid_clone(new_dentry->d_parent); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1053 | if (IS_ERR(newdirfid)) { |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1054 | retval = PTR_ERR(newdirfid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1055 | goto clunk_olddir; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
Sripathi Kodi | 4681dbd | 2010-03-25 12:47:26 +0000 | [diff] [blame] | 1058 | if (v9fs_proto_dotl(v9ses)) { |
| 1059 | retval = p9_client_rename(oldfid, newdirfid, |
| 1060 | (char *) new_dentry->d_name.name); |
| 1061 | if (retval != -ENOSYS) |
| 1062 | goto clunk_newdir; |
| 1063 | } |
| 1064 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1065 | /* 9P can only handle file rename in the same directory */ |
| 1066 | if (memcmp(&olddirfid->qid, &newdirfid->qid, sizeof(newdirfid->qid))) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1067 | P9_DPRINTK(P9_DEBUG_ERROR, |
| 1068 | "old dir and new dir are different\n"); |
Eric Van Hensbergen | 621997c | 2007-01-26 00:57:04 -0800 | [diff] [blame] | 1069 | retval = -EXDEV; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1070 | goto clunk_newdir; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1073 | v9fs_blank_wstat(&wstat); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1074 | wstat.muid = v9ses->uname; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1075 | wstat.name = (char *) new_dentry->d_name.name; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1076 | retval = p9_client_wstat(oldfid, &wstat); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1077 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1078 | clunk_newdir: |
Latchesar Ionkov | 22150c4 | 2007-10-23 13:48:33 -0500 | [diff] [blame] | 1079 | p9_client_clunk(newdirfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1080 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1081 | clunk_olddir: |
Latchesar Ionkov | 22150c4 | 2007-10-23 13:48:33 -0500 | [diff] [blame] | 1082 | p9_client_clunk(olddirfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1083 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1084 | done: |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1085 | return retval; |
| 1086 | } |
| 1087 | |
| 1088 | /** |
Adrian Bunk | 943ffb5 | 2006-01-10 00:10:13 +0100 | [diff] [blame] | 1089 | * v9fs_vfs_getattr - retrieve file metadata |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1090 | * @mnt: mount information |
| 1091 | * @dentry: file to get attributes on |
| 1092 | * @stat: metadata structure to populate |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1093 | * |
| 1094 | */ |
| 1095 | |
| 1096 | static int |
| 1097 | v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 1098 | struct kstat *stat) |
| 1099 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1100 | int err; |
| 1101 | struct v9fs_session_info *v9ses; |
| 1102 | struct p9_fid *fid; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1103 | struct p9_wstat *st; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1104 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1105 | P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry); |
| 1106 | err = -EPERM; |
| 1107 | v9ses = v9fs_inode2v9ses(dentry->d_inode); |
Abhishek Kulkarni | 60e78d2 | 2009-09-23 13:00:27 -0500 | [diff] [blame] | 1108 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) |
Eric Van Hensbergen | 9523a84 | 2007-07-13 13:01:27 -0500 | [diff] [blame] | 1109 | return simple_getattr(mnt, dentry, stat); |
| 1110 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1111 | fid = v9fs_fid_lookup(dentry); |
| 1112 | if (IS_ERR(fid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1113 | return PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1114 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1115 | st = p9_client_stat(fid); |
| 1116 | if (IS_ERR(st)) |
| 1117 | return PTR_ERR(st); |
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 | v9fs_stat2inode(st, dentry->d_inode, dentry->d_inode->i_sb); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1120 | generic_fillattr(dentry->d_inode, stat); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1121 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1122 | kfree(st); |
| 1123 | return 0; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1126 | static int |
| 1127 | v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry, |
| 1128 | struct kstat *stat) |
| 1129 | { |
| 1130 | int err; |
| 1131 | struct v9fs_session_info *v9ses; |
| 1132 | struct p9_fid *fid; |
| 1133 | struct p9_stat_dotl *st; |
| 1134 | |
| 1135 | P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry); |
| 1136 | err = -EPERM; |
| 1137 | v9ses = v9fs_inode2v9ses(dentry->d_inode); |
| 1138 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) |
| 1139 | return simple_getattr(mnt, dentry, stat); |
| 1140 | |
| 1141 | fid = v9fs_fid_lookup(dentry); |
| 1142 | if (IS_ERR(fid)) |
| 1143 | return PTR_ERR(fid); |
| 1144 | |
| 1145 | /* Ask for all the fields in stat structure. Server will return |
| 1146 | * whatever it supports |
| 1147 | */ |
| 1148 | |
| 1149 | st = p9_client_getattr_dotl(fid, P9_STATS_ALL); |
| 1150 | if (IS_ERR(st)) |
| 1151 | return PTR_ERR(st); |
| 1152 | |
| 1153 | v9fs_stat2inode_dotl(st, dentry->d_inode); |
| 1154 | generic_fillattr(dentry->d_inode, stat); |
| 1155 | /* Change block size to what the server returned */ |
| 1156 | stat->blksize = st->st_blksize; |
| 1157 | |
| 1158 | kfree(st); |
| 1159 | return 0; |
| 1160 | } |
| 1161 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1162 | /** |
| 1163 | * v9fs_vfs_setattr - set file metadata |
| 1164 | * @dentry: file whose metadata to set |
| 1165 | * @iattr: metadata assignment structure |
| 1166 | * |
| 1167 | */ |
| 1168 | |
| 1169 | static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) |
| 1170 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1171 | int retval; |
| 1172 | struct v9fs_session_info *v9ses; |
| 1173 | struct p9_fid *fid; |
| 1174 | struct p9_wstat wstat; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1175 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1176 | P9_DPRINTK(P9_DEBUG_VFS, "\n"); |
| 1177 | retval = -EPERM; |
| 1178 | v9ses = v9fs_inode2v9ses(dentry->d_inode); |
| 1179 | fid = v9fs_fid_lookup(dentry); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1180 | if(IS_ERR(fid)) |
| 1181 | return PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1182 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1183 | v9fs_blank_wstat(&wstat); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1184 | if (iattr->ia_valid & ATTR_MODE) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1185 | wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1186 | |
| 1187 | if (iattr->ia_valid & ATTR_MTIME) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1188 | wstat.mtime = iattr->ia_mtime.tv_sec; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1189 | |
| 1190 | if (iattr->ia_valid & ATTR_ATIME) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1191 | wstat.atime = iattr->ia_atime.tv_sec; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1192 | |
| 1193 | if (iattr->ia_valid & ATTR_SIZE) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1194 | wstat.length = iattr->ia_size; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1195 | |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 1196 | if (v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1197 | if (iattr->ia_valid & ATTR_UID) |
| 1198 | wstat.n_uid = iattr->ia_uid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1199 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1200 | if (iattr->ia_valid & ATTR_GID) |
| 1201 | wstat.n_gid = iattr->ia_gid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1204 | retval = p9_client_wstat(fid, &wstat); |
| 1205 | if (retval >= 0) |
| 1206 | retval = inode_setattr(dentry->d_inode, iattr); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1207 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1208 | return retval; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | /** |
Sripathi Kodi | 87d7845 | 2010-06-18 11:50:10 +0530 | [diff] [blame] | 1212 | * v9fs_vfs_setattr_dotl - set file metadata |
| 1213 | * @dentry: file whose metadata to set |
| 1214 | * @iattr: metadata assignment structure |
| 1215 | * |
| 1216 | */ |
| 1217 | |
| 1218 | static int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr) |
| 1219 | { |
| 1220 | int retval; |
| 1221 | struct v9fs_session_info *v9ses; |
| 1222 | struct p9_fid *fid; |
| 1223 | struct p9_iattr_dotl p9attr; |
| 1224 | |
| 1225 | P9_DPRINTK(P9_DEBUG_VFS, "\n"); |
| 1226 | |
| 1227 | retval = inode_change_ok(dentry->d_inode, iattr); |
| 1228 | if (retval) |
| 1229 | return retval; |
| 1230 | |
| 1231 | p9attr.valid = iattr->ia_valid; |
| 1232 | p9attr.mode = iattr->ia_mode; |
| 1233 | p9attr.uid = iattr->ia_uid; |
| 1234 | p9attr.gid = iattr->ia_gid; |
| 1235 | p9attr.size = iattr->ia_size; |
| 1236 | p9attr.atime_sec = iattr->ia_atime.tv_sec; |
| 1237 | p9attr.atime_nsec = iattr->ia_atime.tv_nsec; |
| 1238 | p9attr.mtime_sec = iattr->ia_mtime.tv_sec; |
| 1239 | p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec; |
| 1240 | |
| 1241 | retval = -EPERM; |
| 1242 | v9ses = v9fs_inode2v9ses(dentry->d_inode); |
| 1243 | fid = v9fs_fid_lookup(dentry); |
| 1244 | if (IS_ERR(fid)) |
| 1245 | return PTR_ERR(fid); |
| 1246 | |
| 1247 | retval = p9_client_setattr(fid, &p9attr); |
| 1248 | if (retval >= 0) |
| 1249 | retval = inode_setattr(dentry->d_inode, iattr); |
| 1250 | |
| 1251 | return retval; |
| 1252 | } |
| 1253 | |
| 1254 | /** |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1255 | * v9fs_stat2inode - populate an inode structure with mistat info |
| 1256 | * @stat: Plan 9 metadata (mistat) structure |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1257 | * @inode: inode to populate |
| 1258 | * @sb: superblock of filesystem |
| 1259 | * |
| 1260 | */ |
| 1261 | |
| 1262 | void |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1263 | v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode, |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1264 | struct super_block *sb) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1265 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1266 | char ext[32]; |
Aneesh Kumar K.V | 5717144 | 2010-03-05 14:43:43 -0600 | [diff] [blame] | 1267 | char tag_name[14]; |
| 1268 | unsigned int i_nlink; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1269 | struct v9fs_session_info *v9ses = sb->s_fs_info; |
| 1270 | |
| 1271 | inode->i_nlink = 1; |
| 1272 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1273 | inode->i_atime.tv_sec = stat->atime; |
| 1274 | inode->i_mtime.tv_sec = stat->mtime; |
| 1275 | inode->i_ctime.tv_sec = stat->mtime; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1276 | |
Latchesar Ionkov | bd32b82 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1277 | inode->i_uid = v9ses->dfltuid; |
| 1278 | inode->i_gid = v9ses->dfltgid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1279 | |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 1280 | if (v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1281 | inode->i_uid = stat->n_uid; |
| 1282 | inode->i_gid = stat->n_gid; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1283 | } |
Aneesh Kumar K.V | 5717144 | 2010-03-05 14:43:43 -0600 | [diff] [blame] | 1284 | if ((S_ISREG(inode->i_mode)) || (S_ISDIR(inode->i_mode))) { |
| 1285 | if (v9fs_proto_dotu(v9ses) && (stat->extension[0] != '\0')) { |
| 1286 | /* |
| 1287 | * Hadlink support got added later to |
| 1288 | * to the .u extension. So there can be |
| 1289 | * server out there that doesn't support |
| 1290 | * this even with .u extension. So check |
| 1291 | * for non NULL stat->extension |
| 1292 | */ |
| 1293 | strncpy(ext, stat->extension, sizeof(ext)); |
| 1294 | /* HARDLINKCOUNT %u */ |
| 1295 | sscanf(ext, "%13s %u", tag_name, &i_nlink); |
| 1296 | if (!strncmp(tag_name, "HARDLINKCOUNT", 13)) |
| 1297 | inode->i_nlink = i_nlink; |
| 1298 | } |
| 1299 | } |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1300 | inode->i_mode = p9mode2unixmode(v9ses, stat->mode); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1301 | if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) { |
| 1302 | char type = 0; |
| 1303 | int major = -1; |
| 1304 | int minor = -1; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1305 | |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1306 | strncpy(ext, stat->extension, sizeof(ext)); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1307 | sscanf(ext, "%c %u %u", &type, &major, &minor); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1308 | switch (type) { |
| 1309 | case 'c': |
| 1310 | inode->i_mode &= ~S_IFBLK; |
| 1311 | inode->i_mode |= S_IFCHR; |
| 1312 | break; |
| 1313 | case 'b': |
| 1314 | break; |
| 1315 | default: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1316 | P9_DPRINTK(P9_DEBUG_ERROR, |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1317 | "Unknown special type %c %s\n", type, |
| 1318 | stat->extension); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1319 | }; |
| 1320 | inode->i_rdev = MKDEV(major, minor); |
Magnus Deininger | 57c7b4e | 2008-10-17 12:44:46 -0500 | [diff] [blame] | 1321 | init_special_inode(inode, inode->i_mode, inode->i_rdev); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1322 | } else |
| 1323 | inode->i_rdev = 0; |
| 1324 | |
Abhishek Kulkarni | 7549ae3 | 2009-09-22 11:34:05 -0500 | [diff] [blame] | 1325 | i_size_write(inode, stat->length); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1326 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1327 | /* not real number of blocks, but 512 byte ones ... */ |
Abhishek Kulkarni | 7549ae3 | 2009-09-22 11:34:05 -0500 | [diff] [blame] | 1328 | inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | /** |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1332 | * v9fs_stat2inode_dotl - populate an inode structure with stat info |
| 1333 | * @stat: stat structure |
| 1334 | * @inode: inode to populate |
| 1335 | * @sb: superblock of filesystem |
| 1336 | * |
| 1337 | */ |
| 1338 | |
| 1339 | void |
| 1340 | v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode) |
| 1341 | { |
| 1342 | |
| 1343 | if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) { |
| 1344 | inode->i_atime.tv_sec = stat->st_atime_sec; |
| 1345 | inode->i_atime.tv_nsec = stat->st_atime_nsec; |
| 1346 | inode->i_mtime.tv_sec = stat->st_mtime_sec; |
| 1347 | inode->i_mtime.tv_nsec = stat->st_mtime_nsec; |
| 1348 | inode->i_ctime.tv_sec = stat->st_ctime_sec; |
| 1349 | inode->i_ctime.tv_nsec = stat->st_ctime_nsec; |
| 1350 | inode->i_uid = stat->st_uid; |
| 1351 | inode->i_gid = stat->st_gid; |
| 1352 | inode->i_nlink = stat->st_nlink; |
| 1353 | inode->i_mode = stat->st_mode; |
| 1354 | inode->i_rdev = new_decode_dev(stat->st_rdev); |
| 1355 | |
| 1356 | if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) |
| 1357 | init_special_inode(inode, inode->i_mode, inode->i_rdev); |
| 1358 | |
| 1359 | i_size_write(inode, stat->st_size); |
| 1360 | inode->i_blocks = stat->st_blocks; |
| 1361 | } else { |
| 1362 | if (stat->st_result_mask & P9_STATS_ATIME) { |
| 1363 | inode->i_atime.tv_sec = stat->st_atime_sec; |
| 1364 | inode->i_atime.tv_nsec = stat->st_atime_nsec; |
| 1365 | } |
| 1366 | if (stat->st_result_mask & P9_STATS_MTIME) { |
| 1367 | inode->i_mtime.tv_sec = stat->st_mtime_sec; |
| 1368 | inode->i_mtime.tv_nsec = stat->st_mtime_nsec; |
| 1369 | } |
| 1370 | if (stat->st_result_mask & P9_STATS_CTIME) { |
| 1371 | inode->i_ctime.tv_sec = stat->st_ctime_sec; |
| 1372 | inode->i_ctime.tv_nsec = stat->st_ctime_nsec; |
| 1373 | } |
| 1374 | if (stat->st_result_mask & P9_STATS_UID) |
| 1375 | inode->i_uid = stat->st_uid; |
| 1376 | if (stat->st_result_mask & P9_STATS_GID) |
| 1377 | inode->i_gid = stat->st_gid; |
| 1378 | if (stat->st_result_mask & P9_STATS_NLINK) |
| 1379 | inode->i_nlink = stat->st_nlink; |
| 1380 | if (stat->st_result_mask & P9_STATS_MODE) { |
| 1381 | inode->i_mode = stat->st_mode; |
| 1382 | if ((S_ISBLK(inode->i_mode)) || |
| 1383 | (S_ISCHR(inode->i_mode))) |
| 1384 | init_special_inode(inode, inode->i_mode, |
| 1385 | inode->i_rdev); |
| 1386 | } |
| 1387 | if (stat->st_result_mask & P9_STATS_RDEV) |
| 1388 | inode->i_rdev = new_decode_dev(stat->st_rdev); |
| 1389 | if (stat->st_result_mask & P9_STATS_SIZE) |
| 1390 | i_size_write(inode, stat->st_size); |
| 1391 | if (stat->st_result_mask & P9_STATS_BLOCKS) |
| 1392 | inode->i_blocks = stat->st_blocks; |
| 1393 | } |
| 1394 | if (stat->st_result_mask & P9_STATS_GEN) |
| 1395 | inode->i_generation = stat->st_gen; |
| 1396 | |
| 1397 | /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION |
| 1398 | * because the inode structure does not have fields for them. |
| 1399 | */ |
| 1400 | } |
| 1401 | |
| 1402 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1403 | * v9fs_qid2ino - convert qid into inode number |
| 1404 | * @qid: qid to hash |
| 1405 | * |
| 1406 | * BUG: potential for inode number collisions? |
| 1407 | */ |
| 1408 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1409 | ino_t v9fs_qid2ino(struct p9_qid *qid) |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1410 | { |
| 1411 | u64 path = qid->path + 2; |
| 1412 | ino_t i = 0; |
| 1413 | |
| 1414 | if (sizeof(ino_t) == sizeof(path)) |
| 1415 | memcpy(&i, &path, sizeof(ino_t)); |
| 1416 | else |
| 1417 | i = (ino_t) (path ^ (path >> 32)); |
| 1418 | |
| 1419 | return i; |
| 1420 | } |
| 1421 | |
| 1422 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1423 | * v9fs_readlink - read a symlink's location (internal version) |
| 1424 | * @dentry: dentry for symlink |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1425 | * @buffer: buffer to load symlink location into |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1426 | * @buflen: length of buffer |
| 1427 | * |
| 1428 | */ |
| 1429 | |
| 1430 | static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen) |
| 1431 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1432 | int retval; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1433 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1434 | struct v9fs_session_info *v9ses; |
| 1435 | struct p9_fid *fid; |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1436 | struct p9_wstat *st; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1437 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1438 | P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name); |
| 1439 | retval = -EPERM; |
| 1440 | v9ses = v9fs_inode2v9ses(dentry->d_inode); |
| 1441 | fid = v9fs_fid_lookup(dentry); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1442 | if (IS_ERR(fid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1443 | return PTR_ERR(fid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1444 | |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1445 | if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1446 | return -EBADF; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1447 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1448 | st = p9_client_stat(fid); |
| 1449 | if (IS_ERR(st)) |
| 1450 | return PTR_ERR(st); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1451 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1452 | if (!(st->mode & P9_DMSYMLINK)) { |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1453 | retval = -EINVAL; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1454 | goto done; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | /* copy extension buffer into buffer */ |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1458 | strncpy(buffer, st->extension, buflen); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1459 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1460 | P9_DPRINTK(P9_DEBUG_VFS, |
Eric Van Hensbergen | 51a87c5 | 2008-10-16 08:30:07 -0500 | [diff] [blame] | 1461 | "%s -> %s (%s)\n", dentry->d_name.name, st->extension, buffer); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1462 | |
Martin Stava | 2511cd0 | 2009-11-02 08:39:34 -0600 | [diff] [blame] | 1463 | retval = strnlen(buffer, buflen); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1464 | done: |
| 1465 | kfree(st); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1466 | return retval; |
| 1467 | } |
| 1468 | |
| 1469 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1470 | * v9fs_vfs_follow_link - follow a symlink path |
| 1471 | * @dentry: dentry for symlink |
| 1472 | * @nd: nameidata |
| 1473 | * |
| 1474 | */ |
| 1475 | |
| 1476 | static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 1477 | { |
| 1478 | int len = 0; |
| 1479 | char *link = __getname(); |
| 1480 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1481 | P9_DPRINTK(P9_DEBUG_VFS, "%s n", dentry->d_name.name); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1482 | |
| 1483 | if (!link) |
| 1484 | link = ERR_PTR(-ENOMEM); |
| 1485 | else { |
Latchesar Ionkov | 16cce6d | 2006-03-25 03:07:26 -0800 | [diff] [blame] | 1486 | len = v9fs_readlink(dentry, link, PATH_MAX); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1487 | |
| 1488 | if (len < 0) { |
Davi Arnaut | ce44eeb | 2005-11-07 00:59:36 -0800 | [diff] [blame] | 1489 | __putname(link); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1490 | link = ERR_PTR(len); |
| 1491 | } else |
Martin Stava | 2511cd0 | 2009-11-02 08:39:34 -0600 | [diff] [blame] | 1492 | link[min(len, PATH_MAX-1)] = 0; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1493 | } |
| 1494 | nd_set_link(nd, link); |
| 1495 | |
| 1496 | return NULL; |
| 1497 | } |
| 1498 | |
| 1499 | /** |
| 1500 | * v9fs_vfs_put_link - release a symlink path |
| 1501 | * @dentry: dentry for symlink |
| 1502 | * @nd: nameidata |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1503 | * @p: unused |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1504 | * |
| 1505 | */ |
| 1506 | |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1507 | static void |
| 1508 | 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] | 1509 | { |
| 1510 | char *s = nd_get_link(nd); |
| 1511 | |
Duane Griffin | 6ff2320 | 2008-12-19 16:45:21 -0600 | [diff] [blame] | 1512 | P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name, |
| 1513 | IS_ERR(s) ? "<error>" : s); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1514 | if (!IS_ERR(s)) |
Davi Arnaut | ce44eeb | 2005-11-07 00:59:36 -0800 | [diff] [blame] | 1515 | __putname(s); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1518 | /** |
| 1519 | * v9fs_vfs_mkspecial - create a special file |
| 1520 | * @dir: inode to create special file in |
| 1521 | * @dentry: dentry to create |
| 1522 | * @mode: mode to create special file |
| 1523 | * @extension: 9p2000.u format extension string representing special file |
| 1524 | * |
| 1525 | */ |
| 1526 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1527 | static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry, |
| 1528 | int mode, const char *extension) |
| 1529 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1530 | u32 perm; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1531 | struct v9fs_session_info *v9ses; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1532 | struct p9_fid *fid; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1533 | |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 1534 | v9ses = v9fs_inode2v9ses(dir); |
Sripathi Kodi | dd6102f | 2010-03-05 18:48:00 +0000 | [diff] [blame] | 1535 | if (!v9fs_proto_dotu(v9ses)) { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1536 | P9_DPRINTK(P9_DEBUG_ERROR, "not extended\n"); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 1537 | return -EPERM; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1538 | } |
| 1539 | |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1540 | perm = unixmode2p9mode(v9ses, mode); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1541 | fid = v9fs_create(v9ses, dir, dentry, (char *) extension, perm, |
| 1542 | P9_OREAD); |
| 1543 | if (IS_ERR(fid)) |
| 1544 | return PTR_ERR(fid); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1545 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1546 | p9_client_clunk(fid); |
Latchesar Ionkov | 6a3124a | 2006-03-02 02:54:30 -0800 | [diff] [blame] | 1547 | return 0; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | /** |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1551 | * v9fs_vfs_symlink_dotl - helper function to create symlinks |
| 1552 | * @dir: directory inode containing symlink |
| 1553 | * @dentry: dentry for symlink |
| 1554 | * @symname: symlink data |
| 1555 | * |
| 1556 | * See Also: 9P2000.L RFC for more information |
| 1557 | * |
| 1558 | */ |
| 1559 | |
| 1560 | static int |
| 1561 | v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry, |
| 1562 | const char *symname) |
| 1563 | { |
| 1564 | struct v9fs_session_info *v9ses; |
| 1565 | struct p9_fid *dfid; |
| 1566 | struct p9_fid *fid = NULL; |
| 1567 | struct inode *inode; |
| 1568 | struct p9_qid qid; |
| 1569 | char *name; |
| 1570 | int err; |
| 1571 | gid_t gid; |
| 1572 | |
| 1573 | name = (char *) dentry->d_name.name; |
| 1574 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n", |
| 1575 | dir->i_ino, name, symname); |
| 1576 | v9ses = v9fs_inode2v9ses(dir); |
| 1577 | |
| 1578 | dfid = v9fs_fid_lookup(dentry->d_parent); |
| 1579 | if (IS_ERR(dfid)) { |
| 1580 | err = PTR_ERR(dfid); |
| 1581 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); |
| 1582 | return err; |
| 1583 | } |
| 1584 | |
| 1585 | gid = v9fs_get_fsgid_for_create(dir); |
| 1586 | |
| 1587 | if (gid < 0) { |
| 1588 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_egid failed %d\n", gid); |
| 1589 | goto error; |
| 1590 | } |
| 1591 | |
| 1592 | /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */ |
| 1593 | err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid); |
| 1594 | |
| 1595 | if (err < 0) { |
| 1596 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err); |
| 1597 | goto error; |
| 1598 | } |
| 1599 | |
| 1600 | if (v9ses->cache) { |
| 1601 | /* Now walk from the parent so we can get an unopened fid. */ |
| 1602 | fid = p9_client_walk(dfid, 1, &name, 1); |
| 1603 | if (IS_ERR(fid)) { |
| 1604 | err = PTR_ERR(fid); |
| 1605 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", |
| 1606 | err); |
| 1607 | fid = NULL; |
| 1608 | goto error; |
| 1609 | } |
| 1610 | |
| 1611 | /* instantiate inode and assign the unopened fid to dentry */ |
| 1612 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
| 1613 | if (IS_ERR(inode)) { |
| 1614 | err = PTR_ERR(inode); |
| 1615 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", |
| 1616 | err); |
| 1617 | goto error; |
| 1618 | } |
| 1619 | dentry->d_op = &v9fs_cached_dentry_operations; |
| 1620 | d_instantiate(dentry, inode); |
| 1621 | err = v9fs_fid_add(dentry, fid); |
| 1622 | if (err < 0) |
| 1623 | goto error; |
| 1624 | fid = NULL; |
| 1625 | } else { |
| 1626 | /* Not in cached mode. No need to populate inode with stat */ |
| 1627 | inode = v9fs_get_inode(dir->i_sb, S_IFLNK); |
| 1628 | if (IS_ERR(inode)) { |
| 1629 | err = PTR_ERR(inode); |
| 1630 | goto error; |
| 1631 | } |
| 1632 | dentry->d_op = &v9fs_dentry_operations; |
| 1633 | d_instantiate(dentry, inode); |
| 1634 | } |
| 1635 | |
| 1636 | error: |
| 1637 | if (fid) |
| 1638 | p9_client_clunk(fid); |
| 1639 | |
| 1640 | return err; |
| 1641 | } |
| 1642 | |
| 1643 | /** |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1644 | * v9fs_vfs_symlink - helper function to create symlinks |
| 1645 | * @dir: directory inode containing symlink |
| 1646 | * @dentry: dentry for symlink |
| 1647 | * @symname: symlink data |
| 1648 | * |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1649 | * See Also: 9P2000.u RFC for more information |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1650 | * |
| 1651 | */ |
| 1652 | |
| 1653 | static int |
| 1654 | v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) |
| 1655 | { |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1656 | P9_DPRINTK(P9_DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, |
| 1657 | dentry->d_name.name, symname); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1658 | |
| 1659 | return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname); |
| 1660 | } |
| 1661 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1662 | /** |
| 1663 | * v9fs_vfs_link - create a hardlink |
| 1664 | * @old_dentry: dentry for file to link to |
| 1665 | * @dir: inode destination for new link |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1666 | * @dentry: dentry for link |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1667 | * |
| 1668 | */ |
| 1669 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1670 | static int |
| 1671 | v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir, |
| 1672 | struct dentry *dentry) |
| 1673 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1674 | int retval; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1675 | struct p9_fid *oldfid; |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1676 | char *name; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1677 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1678 | P9_DPRINTK(P9_DEBUG_VFS, |
| 1679 | " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1680 | old_dentry->d_name.name); |
| 1681 | |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1682 | oldfid = v9fs_fid_clone(old_dentry); |
Latchesar Ionkov | ba17674 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 1683 | if (IS_ERR(oldfid)) |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1684 | return PTR_ERR(oldfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1685 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1686 | name = __getname(); |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1687 | if (unlikely(!name)) { |
| 1688 | retval = -ENOMEM; |
| 1689 | goto clunk_fid; |
| 1690 | } |
Florin Malita | 0710d36 | 2006-06-25 05:48:31 -0700 | [diff] [blame] | 1691 | |
Latchesar Ionkov | 16cce6d | 2006-03-25 03:07:26 -0800 | [diff] [blame] | 1692 | sprintf(name, "%d\n", oldfid->fid); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1693 | retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name); |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1694 | __putname(name); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1695 | |
Eric Van Hensbergen | da977b2 | 2007-01-26 00:57:06 -0800 | [diff] [blame] | 1696 | clunk_fid: |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1697 | p9_client_clunk(oldfid); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1698 | return retval; |
| 1699 | } |
| 1700 | |
| 1701 | /** |
Eric Van Hensbergen | 09d34ee | 2010-08-02 14:28:09 -0500 | [diff] [blame] | 1702 | * v9fs_vfs_link_dotl - create a hardlink for dotl |
| 1703 | * @old_dentry: dentry for file to link to |
| 1704 | * @dir: inode destination for new link |
| 1705 | * @dentry: dentry for link |
| 1706 | * |
| 1707 | */ |
| 1708 | |
| 1709 | static int |
| 1710 | v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir, |
| 1711 | struct dentry *dentry) |
| 1712 | { |
| 1713 | int err; |
| 1714 | struct p9_fid *dfid, *oldfid; |
| 1715 | char *name; |
| 1716 | struct v9fs_session_info *v9ses; |
| 1717 | struct dentry *dir_dentry; |
| 1718 | |
| 1719 | P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n", |
| 1720 | dir->i_ino, old_dentry->d_name.name, |
| 1721 | dentry->d_name.name); |
| 1722 | |
| 1723 | v9ses = v9fs_inode2v9ses(dir); |
| 1724 | dir_dentry = v9fs_dentry_from_dir_inode(dir); |
| 1725 | dfid = v9fs_fid_lookup(dir_dentry); |
| 1726 | if (IS_ERR(dfid)) |
| 1727 | return PTR_ERR(dfid); |
| 1728 | |
| 1729 | oldfid = v9fs_fid_lookup(old_dentry); |
| 1730 | if (IS_ERR(oldfid)) |
| 1731 | return PTR_ERR(oldfid); |
| 1732 | |
| 1733 | name = (char *) dentry->d_name.name; |
| 1734 | |
| 1735 | err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name); |
| 1736 | |
| 1737 | if (err < 0) { |
| 1738 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err); |
| 1739 | return err; |
| 1740 | } |
| 1741 | |
| 1742 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { |
| 1743 | /* Get the latest stat info from server. */ |
| 1744 | struct p9_fid *fid; |
| 1745 | struct p9_stat_dotl *st; |
| 1746 | |
| 1747 | fid = v9fs_fid_lookup(old_dentry); |
| 1748 | if (IS_ERR(fid)) |
| 1749 | return PTR_ERR(fid); |
| 1750 | |
| 1751 | st = p9_client_getattr_dotl(fid, P9_STATS_BASIC); |
| 1752 | if (IS_ERR(st)) |
| 1753 | return PTR_ERR(st); |
| 1754 | |
| 1755 | v9fs_stat2inode_dotl(st, old_dentry->d_inode); |
| 1756 | |
| 1757 | kfree(st); |
| 1758 | } else { |
| 1759 | /* Caching disabled. No need to get upto date stat info. |
| 1760 | * This dentry will be released immediately. So, just i_count++ |
| 1761 | */ |
| 1762 | atomic_inc(&old_dentry->d_inode->i_count); |
| 1763 | } |
| 1764 | |
| 1765 | dentry->d_op = old_dentry->d_op; |
| 1766 | d_instantiate(dentry, old_dentry->d_inode); |
| 1767 | |
| 1768 | return err; |
| 1769 | } |
| 1770 | |
| 1771 | /** |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1772 | * v9fs_vfs_mknod - create a special file |
| 1773 | * @dir: inode destination for new link |
| 1774 | * @dentry: dentry for file |
| 1775 | * @mode: mode for creation |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 1776 | * @rdev: device associated with special file |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1777 | * |
| 1778 | */ |
| 1779 | |
| 1780 | static int |
| 1781 | v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) |
| 1782 | { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1783 | int retval; |
| 1784 | char *name; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1785 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 1786 | P9_DPRINTK(P9_DEBUG_VFS, |
| 1787 | " %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] | 1788 | dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev)); |
| 1789 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1790 | if (!new_valid_dev(rdev)) |
| 1791 | return -EINVAL; |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1792 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1793 | name = __getname(); |
Eugene Teo | c0291a0 | 2006-03-25 03:07:27 -0800 | [diff] [blame] | 1794 | if (!name) |
| 1795 | return -ENOMEM; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1796 | /* build extension */ |
| 1797 | if (S_ISBLK(mode)) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1798 | sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev)); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1799 | else if (S_ISCHR(mode)) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1800 | sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev)); |
Eric Van Hensbergen | 73c592b | 2005-09-09 13:04:26 -0700 | [diff] [blame] | 1801 | else if (S_ISFIFO(mode)) |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1802 | *name = 0; |
Venkateswararao Jujjuri | 75cc5c9 | 2010-05-22 12:20:30 -0500 | [diff] [blame] | 1803 | else if (S_ISSOCK(mode)) |
| 1804 | *name = 0; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1805 | else { |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1806 | __putname(name); |
| 1807 | return -EINVAL; |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
Latchesar Ionkov | 531b109 | 2006-01-08 01:05:00 -0800 | [diff] [blame] | 1810 | retval = v9fs_vfs_mkspecial(dir, dentry, mode, name); |
| 1811 | __putname(name); |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1812 | |
| 1813 | return retval; |
| 1814 | } |
| 1815 | |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 1816 | /** |
| 1817 | * v9fs_vfs_mknod_dotl - create a special file |
| 1818 | * @dir: inode destination for new link |
| 1819 | * @dentry: dentry for file |
| 1820 | * @mode: mode for creation |
| 1821 | * @rdev: device associated with special file |
| 1822 | * |
| 1823 | */ |
| 1824 | static int |
| 1825 | v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int mode, |
| 1826 | dev_t rdev) |
| 1827 | { |
| 1828 | int err; |
| 1829 | char *name; |
| 1830 | struct v9fs_session_info *v9ses; |
| 1831 | struct p9_fid *fid = NULL, *dfid = NULL; |
| 1832 | struct inode *inode; |
| 1833 | gid_t gid; |
| 1834 | struct p9_qid qid; |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 1835 | struct dentry *dir_dentry; |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 1836 | |
| 1837 | P9_DPRINTK(P9_DEBUG_VFS, |
| 1838 | " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino, |
| 1839 | dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev)); |
| 1840 | |
| 1841 | if (!new_valid_dev(rdev)) |
| 1842 | return -EINVAL; |
| 1843 | |
| 1844 | v9ses = v9fs_inode2v9ses(dir); |
| 1845 | dir_dentry = v9fs_dentry_from_dir_inode(dir); |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 1846 | dfid = v9fs_fid_lookup(dir_dentry); |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 1847 | if (IS_ERR(dfid)) { |
| 1848 | err = PTR_ERR(dfid); |
| 1849 | P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err); |
| 1850 | dfid = NULL; |
| 1851 | goto error; |
| 1852 | } |
| 1853 | |
| 1854 | gid = v9fs_get_fsgid_for_create(dir); |
| 1855 | if (gid < 0) { |
| 1856 | P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_fsgid_for_create failed\n"); |
| 1857 | goto error; |
| 1858 | } |
| 1859 | |
| 1860 | name = (char *) dentry->d_name.name; |
| 1861 | |
| 1862 | err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid); |
| 1863 | if (err < 0) |
| 1864 | goto error; |
| 1865 | |
| 1866 | /* instantiate inode and assign the unopened fid to the dentry */ |
| 1867 | if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) { |
| 1868 | fid = p9_client_walk(dfid, 1, &name, 1); |
| 1869 | if (IS_ERR(fid)) { |
| 1870 | err = PTR_ERR(fid); |
| 1871 | P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", |
| 1872 | err); |
| 1873 | fid = NULL; |
| 1874 | goto error; |
| 1875 | } |
| 1876 | |
| 1877 | inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb); |
| 1878 | if (IS_ERR(inode)) { |
| 1879 | err = PTR_ERR(inode); |
| 1880 | P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", |
| 1881 | err); |
| 1882 | goto error; |
| 1883 | } |
| 1884 | dentry->d_op = &v9fs_cached_dentry_operations; |
| 1885 | d_instantiate(dentry, inode); |
| 1886 | err = v9fs_fid_add(dentry, fid); |
| 1887 | if (err < 0) |
| 1888 | goto error; |
| 1889 | fid = NULL; |
| 1890 | } else { |
| 1891 | /* |
| 1892 | * Not in cached mode. No need to populate inode with stat. |
| 1893 | * socket syscall returns a fd, so we need instantiate |
| 1894 | */ |
| 1895 | inode = v9fs_get_inode(dir->i_sb, mode); |
| 1896 | if (IS_ERR(inode)) { |
| 1897 | err = PTR_ERR(inode); |
| 1898 | goto error; |
| 1899 | } |
| 1900 | dentry->d_op = &v9fs_dentry_operations; |
| 1901 | d_instantiate(dentry, inode); |
| 1902 | } |
| 1903 | |
| 1904 | error: |
| 1905 | if (fid) |
| 1906 | p9_client_clunk(fid); |
| 1907 | return err; |
| 1908 | } |
| 1909 | |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 1910 | static const struct inode_operations v9fs_dir_inode_operations_dotu = { |
| 1911 | .create = v9fs_vfs_create, |
| 1912 | .lookup = v9fs_vfs_lookup, |
| 1913 | .symlink = v9fs_vfs_symlink, |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1914 | .link = v9fs_vfs_link, |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 1915 | .unlink = v9fs_vfs_unlink, |
| 1916 | .mkdir = v9fs_vfs_mkdir, |
| 1917 | .rmdir = v9fs_vfs_rmdir, |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 1918 | .mknod = v9fs_vfs_mknod_dotl, |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 1919 | .rename = v9fs_vfs_rename, |
| 1920 | .getattr = v9fs_vfs_getattr, |
| 1921 | .setattr = v9fs_vfs_setattr, |
| 1922 | }; |
| 1923 | |
| 1924 | static const struct inode_operations v9fs_dir_inode_operations_dotl = { |
Venkateswararao Jujjuri (JV) | 5643135 | 2010-06-17 18:27:46 -0700 | [diff] [blame] | 1925 | .create = v9fs_vfs_create_dotl, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1926 | .lookup = v9fs_vfs_lookup, |
Venkateswararao Jujjuri (JV) | 50cc42f | 2010-06-09 15:59:31 -0700 | [diff] [blame] | 1927 | .link = v9fs_vfs_link_dotl, |
| 1928 | .symlink = v9fs_vfs_symlink_dotl, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1929 | .unlink = v9fs_vfs_unlink, |
M. Mohan Kumar | 01a622b | 2010-06-16 14:27:22 +0530 | [diff] [blame] | 1930 | .mkdir = v9fs_vfs_mkdir_dotl, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1931 | .rmdir = v9fs_vfs_rmdir, |
M. Mohan Kumar | 4b43516 | 2010-06-16 14:27:01 +0530 | [diff] [blame] | 1932 | .mknod = v9fs_vfs_mknod_dotl, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1933 | .rename = v9fs_vfs_rename, |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1934 | .getattr = v9fs_vfs_getattr_dotl, |
Sripathi Kodi | 87d7845 | 2010-06-18 11:50:10 +0530 | [diff] [blame] | 1935 | .setattr = v9fs_vfs_setattr_dotl, |
Aneesh Kumar K.V | ebf4626 | 2010-05-31 13:22:56 +0530 | [diff] [blame^] | 1936 | .setxattr = generic_setxattr, |
| 1937 | .getxattr = generic_getxattr, |
| 1938 | .removexattr = generic_removexattr, |
| 1939 | .listxattr = v9fs_listxattr, |
| 1940 | |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1941 | }; |
| 1942 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1943 | static const struct inode_operations v9fs_dir_inode_operations = { |
Eric Van Hensbergen | b501611 | 2005-09-09 13:04:27 -0700 | [diff] [blame] | 1944 | .create = v9fs_vfs_create, |
| 1945 | .lookup = v9fs_vfs_lookup, |
| 1946 | .unlink = v9fs_vfs_unlink, |
| 1947 | .mkdir = v9fs_vfs_mkdir, |
| 1948 | .rmdir = v9fs_vfs_rmdir, |
| 1949 | .mknod = v9fs_vfs_mknod, |
| 1950 | .rename = v9fs_vfs_rename, |
| 1951 | .getattr = v9fs_vfs_getattr, |
| 1952 | .setattr = v9fs_vfs_setattr, |
| 1953 | }; |
| 1954 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1955 | static const struct inode_operations v9fs_file_inode_operations = { |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1956 | .getattr = v9fs_vfs_getattr, |
| 1957 | .setattr = v9fs_vfs_setattr, |
| 1958 | }; |
| 1959 | |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 1960 | static const struct inode_operations v9fs_file_inode_operations_dotl = { |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1961 | .getattr = v9fs_vfs_getattr_dotl, |
Sripathi Kodi | 87d7845 | 2010-06-18 11:50:10 +0530 | [diff] [blame] | 1962 | .setattr = v9fs_vfs_setattr_dotl, |
Aneesh Kumar K.V | ebf4626 | 2010-05-31 13:22:56 +0530 | [diff] [blame^] | 1963 | .setxattr = generic_setxattr, |
| 1964 | .getxattr = generic_getxattr, |
| 1965 | .removexattr = generic_removexattr, |
| 1966 | .listxattr = v9fs_listxattr, |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 1967 | }; |
| 1968 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 1969 | static const struct inode_operations v9fs_symlink_inode_operations = { |
Al Viro | 204f2f0 | 2009-12-23 00:35:54 -0500 | [diff] [blame] | 1970 | .readlink = generic_readlink, |
Eric Van Hensbergen | 2bad847 | 2005-09-09 13:04:19 -0700 | [diff] [blame] | 1971 | .follow_link = v9fs_vfs_follow_link, |
| 1972 | .put_link = v9fs_vfs_put_link, |
| 1973 | .getattr = v9fs_vfs_getattr, |
| 1974 | .setattr = v9fs_vfs_setattr, |
| 1975 | }; |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 1976 | |
| 1977 | static const struct inode_operations v9fs_symlink_inode_operations_dotl = { |
| 1978 | .readlink = generic_readlink, |
| 1979 | .follow_link = v9fs_vfs_follow_link, |
| 1980 | .put_link = v9fs_vfs_put_link, |
Sripathi Kodi | f085312 | 2010-07-12 20:07:23 +0530 | [diff] [blame] | 1981 | .getattr = v9fs_vfs_getattr_dotl, |
Sripathi Kodi | 87d7845 | 2010-06-18 11:50:10 +0530 | [diff] [blame] | 1982 | .setattr = v9fs_vfs_setattr_dotl, |
Aneesh Kumar K.V | ebf4626 | 2010-05-31 13:22:56 +0530 | [diff] [blame^] | 1983 | .setxattr = generic_setxattr, |
| 1984 | .getxattr = generic_getxattr, |
| 1985 | .removexattr = generic_removexattr, |
| 1986 | .listxattr = v9fs_listxattr, |
Sripathi Kodi | 9b6533c | 2010-03-25 12:41:54 +0000 | [diff] [blame] | 1987 | }; |