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