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