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