blob: f2434fc9d2c44f620e2e579a19318321e12d6e71 [file] [log] [blame]
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001/*
2 * linux/fs/9p/vfs_inode.c
3 *
Eric Van Hensbergen73c592b2005-09-09 13:04:26 -07004 * This file contains vfs inode ops for the 9P2000 protocol.
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07005 *
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 Hensbergen42e8c502006-03-25 03:07:28 -080010 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070012 *
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 Hensbergen2bad8472005-09-09 13:04:19 -070033#include <linux/inet.h>
34#include <linux/namei.h>
35#include <linux/idr.h>
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +040036#include <linux/sched.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050038#include <net/9p/9p.h>
39#include <net/9p/client.h>
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070040
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070041#include "v9fs.h"
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070042#include "v9fs_vfs.h"
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070043#include "fid.h"
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -050044#include "cache.h"
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070045
Arjan van de Ven754661f2007-02-12 00:55:38 -080046static const struct inode_operations v9fs_dir_inode_operations;
47static const struct inode_operations v9fs_dir_inode_operations_ext;
48static const struct inode_operations v9fs_file_inode_operations;
49static const struct inode_operations v9fs_symlink_inode_operations;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070050
51/**
52 * unixmode2p9mode - convert unix mode bits to plan 9
53 * @v9ses: v9fs session information
54 * @mode: mode to convert
55 *
56 */
57
Eric Van Hensbergen73c592b2005-09-09 13:04:26 -070058static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode)
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070059{
60 int res;
61 res = mode & 0777;
62 if (S_ISDIR(mode))
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050063 res |= P9_DMDIR;
Sripathi Kodidd6102f2010-03-05 18:48:00 +000064 if (v9fs_proto_dotu(v9ses)) {
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070065 if (S_ISLNK(mode))
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050066 res |= P9_DMSYMLINK;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070067 if (v9ses->nodev == 0) {
68 if (S_ISSOCK(mode))
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050069 res |= P9_DMSOCKET;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070070 if (S_ISFIFO(mode))
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050071 res |= P9_DMNAMEDPIPE;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070072 if (S_ISBLK(mode))
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050073 res |= P9_DMDEVICE;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070074 if (S_ISCHR(mode))
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050075 res |= P9_DMDEVICE;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070076 }
77
78 if ((mode & S_ISUID) == S_ISUID)
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050079 res |= P9_DMSETUID;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070080 if ((mode & S_ISGID) == S_ISGID)
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050081 res |= P9_DMSETGID;
Anthony Liguorid199d652008-02-06 19:25:06 -060082 if ((mode & S_ISVTX) == S_ISVTX)
83 res |= P9_DMSETVTX;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050084 if ((mode & P9_DMLINK))
85 res |= P9_DMLINK;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070086 }
87
88 return res;
89}
90
91/**
92 * p9mode2unixmode- convert plan9 mode bits to unix mode bits
93 * @v9ses: v9fs session information
94 * @mode: mode to convert
95 *
96 */
97
Eric Van Hensbergen73c592b2005-09-09 13:04:26 -070098static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode)
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -070099{
100 int res;
101
102 res = mode & 0777;
103
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500104 if ((mode & P9_DMDIR) == P9_DMDIR)
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700105 res |= S_IFDIR;
Sripathi Kodidd6102f2010-03-05 18:48:00 +0000106 else if ((mode & P9_DMSYMLINK) && (v9fs_proto_dotu(v9ses)))
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700107 res |= S_IFLNK;
Sripathi Kodidd6102f2010-03-05 18:48:00 +0000108 else if ((mode & P9_DMSOCKET) && (v9fs_proto_dotu(v9ses))
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700109 && (v9ses->nodev == 0))
110 res |= S_IFSOCK;
Sripathi Kodidd6102f2010-03-05 18:48:00 +0000111 else if ((mode & P9_DMNAMEDPIPE) && (v9fs_proto_dotu(v9ses))
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700112 && (v9ses->nodev == 0))
113 res |= S_IFIFO;
Sripathi Kodidd6102f2010-03-05 18:48:00 +0000114 else if ((mode & P9_DMDEVICE) && (v9fs_proto_dotu(v9ses))
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700115 && (v9ses->nodev == 0))
116 res |= S_IFBLK;
117 else
118 res |= S_IFREG;
119
Sripathi Kodidd6102f2010-03-05 18:48:00 +0000120 if (v9fs_proto_dotu(v9ses)) {
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500121 if ((mode & P9_DMSETUID) == P9_DMSETUID)
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700122 res |= S_ISUID;
123
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500124 if ((mode & P9_DMSETGID) == P9_DMSETGID)
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700125 res |= S_ISGID;
Anthony Liguorid199d652008-02-06 19:25:06 -0600126
127 if ((mode & P9_DMSETVTX) == P9_DMSETVTX)
128 res |= S_ISVTX;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700129 }
130
131 return res;
132}
133
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600134/**
135 * v9fs_uflags2omode- convert posix open flags to plan 9 mode bits
136 * @uflags: flags to convert
Eric Van Hensbergen2e4bef42008-06-24 17:39:39 -0500137 * @extended: if .u extensions are active
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600138 */
139
Eric Van Hensbergen2e4bef42008-06-24 17:39:39 -0500140int v9fs_uflags2omode(int uflags, int extended)
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800141{
142 int ret;
143
144 ret = 0;
145 switch (uflags&3) {
146 default:
147 case O_RDONLY:
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500148 ret = P9_OREAD;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800149 break;
150
151 case O_WRONLY:
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500152 ret = P9_OWRITE;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800153 break;
154
155 case O_RDWR:
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500156 ret = P9_ORDWR;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800157 break;
158 }
159
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800160 if (uflags & O_TRUNC)
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500161 ret |= P9_OTRUNC;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800162
Eric Van Hensbergen2e4bef42008-06-24 17:39:39 -0500163 if (extended) {
164 if (uflags & O_EXCL)
165 ret |= P9_OEXCL;
166
167 if (uflags & O_APPEND)
168 ret |= P9_OAPPEND;
169 }
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800170
171 return ret;
172}
173
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700174/**
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800175 * v9fs_blank_wstat - helper function to setup a 9P stat structure
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800176 * @wstat: structure to initialize
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700177 *
178 */
179
M. Mohan Kumar7a4439c2010-02-08 15:36:48 -0600180void
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500181v9fs_blank_wstat(struct p9_wstat *wstat)
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700182{
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800183 wstat->type = ~0;
184 wstat->dev = ~0;
185 wstat->qid.type = ~0;
186 wstat->qid.version = ~0;
187 *((long long *)&wstat->qid.path) = ~0;
188 wstat->mode = ~0;
189 wstat->atime = ~0;
190 wstat->mtime = ~0;
191 wstat->length = ~0;
192 wstat->name = NULL;
193 wstat->uid = NULL;
194 wstat->gid = NULL;
195 wstat->muid = NULL;
196 wstat->n_uid = ~0;
197 wstat->n_gid = ~0;
198 wstat->n_muid = ~0;
199 wstat->extension = NULL;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700200}
201
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -0500202#ifdef CONFIG_9P_FSCACHE
203/**
204 * v9fs_alloc_inode - helper function to allocate an inode
205 * This callback is executed before setting up the inode so that we
206 * can associate a vcookie with each inode.
207 *
208 */
209
210struct inode *v9fs_alloc_inode(struct super_block *sb)
211{
212 struct v9fs_cookie *vcookie;
213 vcookie = (struct v9fs_cookie *)kmem_cache_alloc(vcookie_cache,
214 GFP_KERNEL);
215 if (!vcookie)
216 return NULL;
217
218 vcookie->fscache = NULL;
219 vcookie->qid = NULL;
220 spin_lock_init(&vcookie->lock);
221 return &vcookie->inode;
222}
223
224/**
225 * v9fs_destroy_inode - destroy an inode
226 *
227 */
228
229void v9fs_destroy_inode(struct inode *inode)
230{
231 kmem_cache_free(vcookie_cache, v9fs_inode2cookie(inode));
232}
233#endif
234
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700235/**
236 * v9fs_get_inode - helper function to setup an inode
237 * @sb: superblock
238 * @mode: mode to setup inode with
239 *
240 */
241
242struct inode *v9fs_get_inode(struct super_block *sb, int mode)
243{
Abhishek Kulkarni2bb54112009-07-19 13:41:56 -0600244 int err;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800245 struct inode *inode;
Eric Van Hensbergenb5016112005-09-09 13:04:27 -0700246 struct v9fs_session_info *v9ses = sb->s_fs_info;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700247
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500248 P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700249
250 inode = new_inode(sb);
Abhishek Kulkarni2bb54112009-07-19 13:41:56 -0600251 if (!inode) {
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500252 P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n");
Abhishek Kulkarni48559b4c2009-08-17 16:32:18 -0500253 return ERR_PTR(-ENOMEM);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700254 }
Abhishek Kulkarni2bb54112009-07-19 13:41:56 -0600255
256 inode->i_mode = mode;
257 inode->i_uid = current_fsuid();
258 inode->i_gid = current_fsgid();
259 inode->i_blocks = 0;
260 inode->i_rdev = 0;
261 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
262 inode->i_mapping->a_ops = &v9fs_addr_operations;
263
264 switch (mode & S_IFMT) {
265 case S_IFIFO:
266 case S_IFBLK:
267 case S_IFCHR:
268 case S_IFSOCK:
Sripathi Kodidd6102f2010-03-05 18:48:00 +0000269 if (!v9fs_proto_dotu(v9ses)) {
Abhishek Kulkarni2bb54112009-07-19 13:41:56 -0600270 P9_DPRINTK(P9_DEBUG_ERROR,
271 "special files without extended mode\n");
272 err = -EINVAL;
273 goto error;
274 }
275 init_special_inode(inode, inode->i_mode, inode->i_rdev);
276 break;
277 case S_IFREG:
278 inode->i_op = &v9fs_file_inode_operations;
279 inode->i_fop = &v9fs_file_operations;
280 break;
281 case S_IFLNK:
Sripathi Kodidd6102f2010-03-05 18:48:00 +0000282 if (!v9fs_proto_dotu(v9ses)) {
Abhishek Kulkarni2bb54112009-07-19 13:41:56 -0600283 P9_DPRINTK(P9_DEBUG_ERROR,
284 "extended modes used w/o 9P2000.u\n");
285 err = -EINVAL;
286 goto error;
287 }
288 inode->i_op = &v9fs_symlink_inode_operations;
289 break;
290 case S_IFDIR:
291 inc_nlink(inode);
Sripathi Kodidd6102f2010-03-05 18:48:00 +0000292 if (v9fs_proto_dotu(v9ses))
Abhishek Kulkarni2bb54112009-07-19 13:41:56 -0600293 inode->i_op = &v9fs_dir_inode_operations_ext;
294 else
295 inode->i_op = &v9fs_dir_inode_operations;
296 inode->i_fop = &v9fs_dir_operations;
297 break;
298 default:
299 P9_DPRINTK(P9_DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n",
300 mode, mode & S_IFMT);
301 err = -EINVAL;
302 goto error;
303 }
304
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700305 return inode;
Abhishek Kulkarni2bb54112009-07-19 13:41:56 -0600306
307error:
308 iput(inode);
309 return ERR_PTR(err);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700310}
311
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500312/*
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800313static struct v9fs_fid*
314v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry)
315{
316 int err;
Mika Kukkonen736c4b852006-12-06 20:36:29 -0800317 int nfid;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800318 struct v9fs_fid *ret;
319 struct v9fs_fcall *fcall;
320
321 nfid = v9fs_get_idpool(&v9ses->fidpool);
322 if (nfid < 0) {
323 eprintk(KERN_WARNING, "no free fids available\n");
Latchesar Ionkov731805b2006-03-07 21:55:42 -0800324 return ERR_PTR(-ENOSPC);
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800325 }
326
327 err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name,
328 &fcall);
329
330 if (err < 0) {
Latchesar Ionkov41e5a6a2006-05-15 09:44:21 -0700331 if (fcall && fcall->id == RWALK)
332 goto clunk_fid;
333
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800334 PRINT_FCALL_ERROR("walk error", fcall);
335 v9fs_put_idpool(nfid, &v9ses->fidpool);
336 goto error;
337 }
338
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700339 kfree(fcall);
Latchesar Ionkov3cf64292006-01-08 01:04:58 -0800340 fcall = NULL;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800341 ret = v9fs_fid_create(v9ses, nfid);
342 if (!ret) {
343 err = -ENOMEM;
344 goto clunk_fid;
345 }
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700346
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800347 err = v9fs_fid_insert(ret, dentry);
348 if (err < 0) {
349 v9fs_fid_destroy(ret);
350 goto clunk_fid;
Latchesar Ionkov0b8dd172005-09-27 21:45:24 -0700351 }
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800352
353 return ret;
354
355clunk_fid:
356 v9fs_t_clunk(v9ses, nfid);
357
358error:
359 kfree(fcall);
360 return ERR_PTR(err);
361}
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500362*/
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800363
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -0500364
365/**
366 * v9fs_clear_inode - release an inode
367 * @inode: inode to release
368 *
369 */
370void v9fs_clear_inode(struct inode *inode)
371{
372 filemap_fdatawrite(inode->i_mapping);
373
374#ifdef CONFIG_9P_FSCACHE
375 v9fs_cache_inode_put_cookie(inode);
376#endif
377}
378
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600379/**
380 * v9fs_inode_from_fid - populate an inode by issuing a attribute request
381 * @v9ses: session information
382 * @fid: fid to issue attribute request for
383 * @sb: superblock on which to create inode
384 *
385 */
386
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800387static struct inode *
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500388v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800389 struct super_block *sb)
390{
391 int err, umode;
392 struct inode *ret;
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500393 struct p9_wstat *st;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800394
395 ret = NULL;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500396 st = p9_client_stat(fid);
Abhishek Kulkarni02bc3562009-07-19 13:41:54 -0600397 if (IS_ERR(st))
398 return ERR_CAST(st);
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800399
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500400 umode = p9mode2unixmode(v9ses, st->mode);
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800401 ret = v9fs_get_inode(sb, umode);
402 if (IS_ERR(ret)) {
403 err = PTR_ERR(ret);
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800404 goto error;
405 }
406
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500407 v9fs_stat2inode(st, ret, sb);
408 ret->i_ino = v9fs_qid2ino(&st->qid);
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -0500409
410#ifdef CONFIG_9P_FSCACHE
411 v9fs_vcookie_set_qid(ret, &st->qid);
412 v9fs_cache_inode_get_cookie(ret);
413#endif
Abhishek Kulkarni02bc3562009-07-19 13:41:54 -0600414 p9stat_free(st);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500415 kfree(st);
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -0500416
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800417 return ret;
418
419error:
Abhishek Kulkarni02bc3562009-07-19 13:41:54 -0600420 p9stat_free(st);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500421 kfree(st);
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800422 return ERR_PTR(err);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700423}
424
425/**
426 * v9fs_remove - helper function to remove files and directories
Eric Van Hensbergen73c592b2005-09-09 13:04:26 -0700427 * @dir: directory inode that is being deleted
428 * @file: dentry that is being deleted
429 * @rmdir: removing a directory
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700430 *
431 */
432
433static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
434{
Aneesh Kumar K.Vd994f402010-03-29 18:14:50 -0500435 int retval;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500436 struct inode *file_inode;
437 struct v9fs_session_info *v9ses;
438 struct p9_fid *v9fid;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700439
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500440 P9_DPRINTK(P9_DEBUG_VFS, "inode: %p dentry: %p rmdir: %d\n", dir, file,
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700441 rmdir);
442
443 file_inode = file->d_inode;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700444 v9ses = v9fs_inode2v9ses(file_inode);
Latchesar Ionkovc959df92007-04-23 14:41:11 -0700445 v9fid = v9fs_fid_clone(file);
Latchesar Ionkovba176742007-10-17 14:31:07 -0500446 if (IS_ERR(v9fid))
Eric Van Hensbergenda977b22007-01-26 00:57:06 -0800447 return PTR_ERR(v9fid);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700448
Aneesh Kumar K.Vd994f402010-03-29 18:14:50 -0500449 retval = p9_client_remove(v9fid);
450 if (!retval)
451 drop_nlink(file_inode);
452 return retval;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700453}
454
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800455static int
456v9fs_open_created(struct inode *inode, struct file *file)
457{
458 return 0;
459}
460
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500461
462/**
463 * v9fs_create - Create a file
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600464 * @v9ses: session information
465 * @dir: directory that dentry is being created in
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500466 * @dentry: dentry that is being created
Abhishek Kulkarni0e155972009-07-19 13:41:55 -0600467 * @extension: 9p2000.u extension string to support devices, etc.
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500468 * @perm: create permissions
469 * @mode: open mode
470 *
471 */
472static struct p9_fid *
473v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
474 struct dentry *dentry, char *extension, u32 perm, u8 mode)
475{
476 int err;
477 char *name;
478 struct p9_fid *dfid, *ofid, *fid;
479 struct inode *inode;
480
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500481 P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
482
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500483 err = 0;
484 ofid = NULL;
485 fid = NULL;
486 name = (char *) dentry->d_name.name;
487 dfid = v9fs_fid_clone(dentry->d_parent);
Latchesar Ionkovba176742007-10-17 14:31:07 -0500488 if (IS_ERR(dfid)) {
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500489 err = PTR_ERR(dfid);
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500490 P9_DPRINTK(P9_DEBUG_VFS, "fid clone failed %d\n", err);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500491 dfid = NULL;
492 goto error;
493 }
494
495 /* clone a fid to use for creation */
496 ofid = p9_client_walk(dfid, 0, NULL, 1);
497 if (IS_ERR(ofid)) {
498 err = PTR_ERR(ofid);
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500499 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500500 ofid = NULL;
501 goto error;
502 }
503
504 err = p9_client_fcreate(ofid, name, perm, mode, extension);
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500505 if (err < 0) {
506 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_fcreate failed %d\n", err);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500507 goto error;
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500508 }
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500509
510 /* now walk from the parent so we can get unopened fid */
511 fid = p9_client_walk(dfid, 1, &name, 0);
512 if (IS_ERR(fid)) {
513 err = PTR_ERR(fid);
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500514 P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500515 fid = NULL;
516 goto error;
517 } else
518 dfid = NULL;
519
520 /* instantiate inode and assign the unopened fid to the dentry */
521 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
522 if (IS_ERR(inode)) {
523 err = PTR_ERR(inode);
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500524 P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500525 goto error;
526 }
527
Latchesar Ionkovba176742007-10-17 14:31:07 -0500528 if (v9ses->cache)
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500529 dentry->d_op = &v9fs_cached_dentry_operations;
530 else
531 dentry->d_op = &v9fs_dentry_operations;
532
533 d_instantiate(dentry, inode);
Abhishek Kulkarni50fb6d22009-07-19 13:41:57 -0600534 err = v9fs_fid_add(dentry, fid);
535 if (err < 0)
536 goto error;
537
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500538 return ofid;
539
540error:
541 if (dfid)
542 p9_client_clunk(dfid);
543
544 if (ofid)
545 p9_client_clunk(ofid);
546
547 if (fid)
548 p9_client_clunk(fid);
549
550 return ERR_PTR(err);
551}
552
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700553/**
554 * v9fs_vfs_create - VFS hook to create files
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600555 * @dir: directory inode that is being created
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700556 * @dentry: dentry that is being deleted
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800557 * @mode: create permissions
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700558 * @nd: path information
559 *
560 */
561
562static int
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800563v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700564 struct nameidata *nd)
565{
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800566 int err;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500567 u32 perm;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800568 int flags;
569 struct v9fs_session_info *v9ses;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500570 struct p9_fid *fid;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800571 struct file *filp;
572
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500573 err = 0;
574 fid = NULL;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800575 v9ses = v9fs_inode2v9ses(dir);
Eric Van Hensbergenda977b22007-01-26 00:57:06 -0800576 perm = unixmode2p9mode(v9ses, mode);
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800577 if (nd && nd->flags & LOOKUP_OPEN)
578 flags = nd->intent.open.flags - 1;
579 else
580 flags = O_RDWR;
581
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500582 fid = v9fs_create(v9ses, dir, dentry, NULL, perm,
Sripathi Kodidd6102f2010-03-05 18:48:00 +0000583 v9fs_uflags2omode(flags,
584 v9fs_proto_dotu(v9ses)));
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500585 if (IS_ERR(fid)) {
586 err = PTR_ERR(fid);
587 fid = NULL;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800588 goto error;
589 }
590
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500591 /* if we are opening a file, assign the open fid to the file */
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800592 if (nd && nd->flags & LOOKUP_OPEN) {
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800593 filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created);
594 if (IS_ERR(filp)) {
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500595 err = PTR_ERR(filp);
596 goto error;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800597 }
598
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500599 filp->private_data = fid;
600 } else
601 p9_client_clunk(fid);
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800602
603 return 0;
604
605error:
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500606 if (fid)
607 p9_client_clunk(fid);
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800608
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800609 return err;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700610}
611
612/**
613 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600614 * @dir: inode that is being unlinked
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700615 * @dentry: dentry that is being unlinked
616 * @mode: mode for new directory
617 *
618 */
619
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800620static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700621{
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800622 int err;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500623 u32 perm;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800624 struct v9fs_session_info *v9ses;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500625 struct p9_fid *fid;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800626
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500627 P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
628 err = 0;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800629 v9ses = v9fs_inode2v9ses(dir);
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800630 perm = unixmode2p9mode(v9ses, mode | S_IFDIR);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500631 fid = v9fs_create(v9ses, dir, dentry, NULL, perm, P9_OREAD);
632 if (IS_ERR(fid)) {
633 err = PTR_ERR(fid);
634 fid = NULL;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800635 }
636
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500637 if (fid)
638 p9_client_clunk(fid);
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800639
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800640 return err;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700641}
642
643/**
644 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
645 * @dir: inode that is being walked from
646 * @dentry: dentry that is being walked to?
647 * @nameidata: path data
648 *
649 */
650
651static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
652 struct nameidata *nameidata)
653{
654 struct super_block *sb;
655 struct v9fs_session_info *v9ses;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500656 struct p9_fid *dfid, *fid;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700657 struct inode *inode;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500658 char *name;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700659 int result = 0;
660
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500661 P9_DPRINTK(P9_DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n",
Latchesar Ionkov731805b2006-03-07 21:55:42 -0800662 dir, dentry->d_name.name, dentry, nameidata);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700663
Sripathi Kodi11e9b492010-03-29 18:13:59 -0500664 if (dentry->d_name.len > NAME_MAX)
665 return ERR_PTR(-ENAMETOOLONG);
666
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700667 sb = dir->i_sb;
668 v9ses = v9fs_inode2v9ses(dir);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500669 dfid = v9fs_fid_lookup(dentry->d_parent);
670 if (IS_ERR(dfid))
David Howellse231c2e2008-02-07 00:15:26 -0800671 return ERR_CAST(dfid);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700672
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500673 name = (char *) dentry->d_name.name;
674 fid = p9_client_walk(dfid, 1, &name, 1);
675 if (IS_ERR(fid)) {
676 result = PTR_ERR(fid);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700677 if (result == -ENOENT) {
678 d_add(dentry, NULL);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700679 return NULL;
680 }
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700681
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500682 return ERR_PTR(result);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700683 }
684
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500685 inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
686 if (IS_ERR(inode)) {
687 result = PTR_ERR(inode);
688 inode = NULL;
689 goto error;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700690 }
691
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500692 result = v9fs_fid_add(dentry, fid);
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800693 if (result < 0)
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500694 goto error;
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -0800695
Latchesar Ionkovba176742007-10-17 14:31:07 -0500696 if ((fid->qid.version) && (v9ses->cache))
Eric Van Hensbergene03abc02007-02-11 13:21:39 -0600697 dentry->d_op = &v9fs_cached_dentry_operations;
698 else
699 dentry->d_op = &v9fs_dentry_operations;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700700
701 d_add(dentry, inode);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700702 return NULL;
703
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500704error:
Julien Brunel62aa5282008-09-24 16:22:22 -0500705 p9_client_clunk(fid);
Eric Van Hensbergenda977b22007-01-26 00:57:06 -0800706
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700707 return ERR_PTR(result);
708}
709
710/**
711 * v9fs_vfs_unlink - VFS unlink hook to delete an inode
712 * @i: inode that is being unlinked
Eric Van Hensbergen73c592b2005-09-09 13:04:26 -0700713 * @d: dentry that is being unlinked
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700714 *
715 */
716
717static int v9fs_vfs_unlink(struct inode *i, struct dentry *d)
718{
719 return v9fs_remove(i, d, 0);
720}
721
722/**
723 * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
724 * @i: inode that is being unlinked
Eric Van Hensbergen73c592b2005-09-09 13:04:26 -0700725 * @d: dentry that is being unlinked
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700726 *
727 */
728
729static int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)
730{
731 return v9fs_remove(i, d, 1);
732}
733
734/**
735 * v9fs_vfs_rename - VFS hook to rename an inode
736 * @old_dir: old dir inode
737 * @old_dentry: old dentry
738 * @new_dir: new dir inode
739 * @new_dentry: new dentry
740 *
741 */
742
743static int
744v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
745 struct inode *new_dir, struct dentry *new_dentry)
746{
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500747 struct inode *old_inode;
748 struct v9fs_session_info *v9ses;
749 struct p9_fid *oldfid;
750 struct p9_fid *olddirfid;
751 struct p9_fid *newdirfid;
752 struct p9_wstat wstat;
753 int retval;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700754
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500755 P9_DPRINTK(P9_DEBUG_VFS, "\n");
756 retval = 0;
757 old_inode = old_dentry->d_inode;
758 v9ses = v9fs_inode2v9ses(old_inode);
759 oldfid = v9fs_fid_lookup(old_dentry);
Latchesar Ionkovba176742007-10-17 14:31:07 -0500760 if (IS_ERR(oldfid))
Eric Van Hensbergenda977b22007-01-26 00:57:06 -0800761 return PTR_ERR(oldfid);
762
763 olddirfid = v9fs_fid_clone(old_dentry->d_parent);
Latchesar Ionkovba176742007-10-17 14:31:07 -0500764 if (IS_ERR(olddirfid)) {
Eric Van Hensbergenda977b22007-01-26 00:57:06 -0800765 retval = PTR_ERR(olddirfid);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500766 goto done;
Eric Van Hensbergenda977b22007-01-26 00:57:06 -0800767 }
768
769 newdirfid = v9fs_fid_clone(new_dentry->d_parent);
Latchesar Ionkovba176742007-10-17 14:31:07 -0500770 if (IS_ERR(newdirfid)) {
Eric Van Hensbergenda977b22007-01-26 00:57:06 -0800771 retval = PTR_ERR(newdirfid);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500772 goto clunk_olddir;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700773 }
774
775 /* 9P can only handle file rename in the same directory */
776 if (memcmp(&olddirfid->qid, &newdirfid->qid, sizeof(newdirfid->qid))) {
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500777 P9_DPRINTK(P9_DEBUG_ERROR,
778 "old dir and new dir are different\n");
Eric Van Hensbergen621997c2007-01-26 00:57:04 -0800779 retval = -EXDEV;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500780 goto clunk_newdir;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700781 }
782
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800783 v9fs_blank_wstat(&wstat);
Latchesar Ionkovba176742007-10-17 14:31:07 -0500784 wstat.muid = v9ses->uname;
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800785 wstat.name = (char *) new_dentry->d_name.name;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500786 retval = p9_client_wstat(oldfid, &wstat);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700787
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500788clunk_newdir:
Latchesar Ionkov22150c42007-10-23 13:48:33 -0500789 p9_client_clunk(newdirfid);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700790
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500791clunk_olddir:
Latchesar Ionkov22150c42007-10-23 13:48:33 -0500792 p9_client_clunk(olddirfid);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700793
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500794done:
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700795 return retval;
796}
797
798/**
Adrian Bunk943ffb52006-01-10 00:10:13 +0100799 * v9fs_vfs_getattr - retrieve file metadata
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600800 * @mnt: mount information
801 * @dentry: file to get attributes on
802 * @stat: metadata structure to populate
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700803 *
804 */
805
806static int
807v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
808 struct kstat *stat)
809{
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500810 int err;
811 struct v9fs_session_info *v9ses;
812 struct p9_fid *fid;
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500813 struct p9_wstat *st;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700814
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500815 P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
816 err = -EPERM;
817 v9ses = v9fs_inode2v9ses(dentry->d_inode);
Abhishek Kulkarni60e78d22009-09-23 13:00:27 -0500818 if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
Eric Van Hensbergen9523a842007-07-13 13:01:27 -0500819 return simple_getattr(mnt, dentry, stat);
820
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500821 fid = v9fs_fid_lookup(dentry);
822 if (IS_ERR(fid))
Eric Van Hensbergenda977b22007-01-26 00:57:06 -0800823 return PTR_ERR(fid);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700824
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500825 st = p9_client_stat(fid);
826 if (IS_ERR(st))
827 return PTR_ERR(st);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700828
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500829 v9fs_stat2inode(st, dentry->d_inode, dentry->d_inode->i_sb);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700830 generic_fillattr(dentry->d_inode, stat);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700831
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500832 kfree(st);
833 return 0;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700834}
835
836/**
837 * v9fs_vfs_setattr - set file metadata
838 * @dentry: file whose metadata to set
839 * @iattr: metadata assignment structure
840 *
841 */
842
843static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
844{
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500845 int retval;
846 struct v9fs_session_info *v9ses;
847 struct p9_fid *fid;
848 struct p9_wstat wstat;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700849
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500850 P9_DPRINTK(P9_DEBUG_VFS, "\n");
851 retval = -EPERM;
852 v9ses = v9fs_inode2v9ses(dentry->d_inode);
853 fid = v9fs_fid_lookup(dentry);
Eric Van Hensbergenda977b22007-01-26 00:57:06 -0800854 if(IS_ERR(fid))
855 return PTR_ERR(fid);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700856
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800857 v9fs_blank_wstat(&wstat);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700858 if (iattr->ia_valid & ATTR_MODE)
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800859 wstat.mode = unixmode2p9mode(v9ses, iattr->ia_mode);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700860
861 if (iattr->ia_valid & ATTR_MTIME)
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800862 wstat.mtime = iattr->ia_mtime.tv_sec;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700863
864 if (iattr->ia_valid & ATTR_ATIME)
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800865 wstat.atime = iattr->ia_atime.tv_sec;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700866
867 if (iattr->ia_valid & ATTR_SIZE)
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800868 wstat.length = iattr->ia_size;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700869
Sripathi Kodidd6102f2010-03-05 18:48:00 +0000870 if (v9fs_proto_dotu(v9ses)) {
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800871 if (iattr->ia_valid & ATTR_UID)
872 wstat.n_uid = iattr->ia_uid;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700873
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800874 if (iattr->ia_valid & ATTR_GID)
875 wstat.n_gid = iattr->ia_gid;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700876 }
877
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500878 retval = p9_client_wstat(fid, &wstat);
879 if (retval >= 0)
880 retval = inode_setattr(dentry->d_inode, iattr);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700881
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500882 return retval;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700883}
884
885/**
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800886 * v9fs_stat2inode - populate an inode structure with mistat info
887 * @stat: Plan 9 metadata (mistat) structure
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700888 * @inode: inode to populate
889 * @sb: superblock of filesystem
890 *
891 */
892
893void
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500894v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800895 struct super_block *sb)
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700896{
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800897 char ext[32];
Aneesh Kumar K.V57171442010-03-05 14:43:43 -0600898 char tag_name[14];
899 unsigned int i_nlink;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700900 struct v9fs_session_info *v9ses = sb->s_fs_info;
901
902 inode->i_nlink = 1;
903
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800904 inode->i_atime.tv_sec = stat->atime;
905 inode->i_mtime.tv_sec = stat->mtime;
906 inode->i_ctime.tv_sec = stat->mtime;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700907
Latchesar Ionkovbd32b822007-10-17 14:31:07 -0500908 inode->i_uid = v9ses->dfltuid;
909 inode->i_gid = v9ses->dfltgid;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700910
Sripathi Kodidd6102f2010-03-05 18:48:00 +0000911 if (v9fs_proto_dotu(v9ses)) {
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800912 inode->i_uid = stat->n_uid;
913 inode->i_gid = stat->n_gid;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700914 }
Aneesh Kumar K.V57171442010-03-05 14:43:43 -0600915 if ((S_ISREG(inode->i_mode)) || (S_ISDIR(inode->i_mode))) {
916 if (v9fs_proto_dotu(v9ses) && (stat->extension[0] != '\0')) {
917 /*
918 * Hadlink support got added later to
919 * to the .u extension. So there can be
920 * server out there that doesn't support
921 * this even with .u extension. So check
922 * for non NULL stat->extension
923 */
924 strncpy(ext, stat->extension, sizeof(ext));
925 /* HARDLINKCOUNT %u */
926 sscanf(ext, "%13s %u", tag_name, &i_nlink);
927 if (!strncmp(tag_name, "HARDLINKCOUNT", 13))
928 inode->i_nlink = i_nlink;
929 }
930 }
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800931 inode->i_mode = p9mode2unixmode(v9ses, stat->mode);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700932 if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode))) {
933 char type = 0;
934 int major = -1;
935 int minor = -1;
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800936
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500937 strncpy(ext, stat->extension, sizeof(ext));
Latchesar Ionkov531b1092006-01-08 01:05:00 -0800938 sscanf(ext, "%c %u %u", &type, &major, &minor);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700939 switch (type) {
940 case 'c':
941 inode->i_mode &= ~S_IFBLK;
942 inode->i_mode |= S_IFCHR;
943 break;
944 case 'b':
945 break;
946 default:
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500947 P9_DPRINTK(P9_DEBUG_ERROR,
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500948 "Unknown special type %c %s\n", type,
949 stat->extension);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700950 };
951 inode->i_rdev = MKDEV(major, minor);
Magnus Deininger57c7b4e2008-10-17 12:44:46 -0500952 init_special_inode(inode, inode->i_mode, inode->i_rdev);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700953 } else
954 inode->i_rdev = 0;
955
Abhishek Kulkarni7549ae3e2009-09-22 11:34:05 -0500956 i_size_write(inode, stat->length);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700957
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500958 /* not real number of blocks, but 512 byte ones ... */
Abhishek Kulkarni7549ae3e2009-09-22 11:34:05 -0500959 inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700960}
961
962/**
963 * v9fs_qid2ino - convert qid into inode number
964 * @qid: qid to hash
965 *
966 * BUG: potential for inode number collisions?
967 */
968
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500969ino_t v9fs_qid2ino(struct p9_qid *qid)
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700970{
971 u64 path = qid->path + 2;
972 ino_t i = 0;
973
974 if (sizeof(ino_t) == sizeof(path))
975 memcpy(&i, &path, sizeof(ino_t));
976 else
977 i = (ino_t) (path ^ (path >> 32));
978
979 return i;
980}
981
982/**
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700983 * v9fs_readlink - read a symlink's location (internal version)
984 * @dentry: dentry for symlink
Eric Van Hensbergen73c592b2005-09-09 13:04:26 -0700985 * @buffer: buffer to load symlink location into
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700986 * @buflen: length of buffer
987 *
988 */
989
990static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
991{
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500992 int retval;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700993
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500994 struct v9fs_session_info *v9ses;
995 struct p9_fid *fid;
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -0500996 struct p9_wstat *st;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -0700997
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500998 P9_DPRINTK(P9_DEBUG_VFS, " %s\n", dentry->d_name.name);
999 retval = -EPERM;
1000 v9ses = v9fs_inode2v9ses(dentry->d_inode);
1001 fid = v9fs_fid_lookup(dentry);
Latchesar Ionkovba176742007-10-17 14:31:07 -05001002 if (IS_ERR(fid))
Eric Van Hensbergenda977b22007-01-26 00:57:06 -08001003 return PTR_ERR(fid);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001004
Sripathi Kodidd6102f2010-03-05 18:48:00 +00001005 if (!v9fs_proto_dotu(v9ses))
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001006 return -EBADF;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001007
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001008 st = p9_client_stat(fid);
1009 if (IS_ERR(st))
1010 return PTR_ERR(st);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001011
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001012 if (!(st->mode & P9_DMSYMLINK)) {
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001013 retval = -EINVAL;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001014 goto done;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001015 }
1016
1017 /* copy extension buffer into buffer */
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -05001018 strncpy(buffer, st->extension, buflen);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001019
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001020 P9_DPRINTK(P9_DEBUG_VFS,
Eric Van Hensbergen51a87c52008-10-16 08:30:07 -05001021 "%s -> %s (%s)\n", dentry->d_name.name, st->extension, buffer);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001022
Martin Stava2511cd02009-11-02 08:39:34 -06001023 retval = strnlen(buffer, buflen);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001024done:
1025 kfree(st);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001026 return retval;
1027}
1028
1029/**
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001030 * v9fs_vfs_follow_link - follow a symlink path
1031 * @dentry: dentry for symlink
1032 * @nd: nameidata
1033 *
1034 */
1035
1036static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
1037{
1038 int len = 0;
1039 char *link = __getname();
1040
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001041 P9_DPRINTK(P9_DEBUG_VFS, "%s n", dentry->d_name.name);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001042
1043 if (!link)
1044 link = ERR_PTR(-ENOMEM);
1045 else {
Latchesar Ionkov16cce6d2006-03-25 03:07:26 -08001046 len = v9fs_readlink(dentry, link, PATH_MAX);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001047
1048 if (len < 0) {
Davi Arnautce44eeb2005-11-07 00:59:36 -08001049 __putname(link);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001050 link = ERR_PTR(len);
1051 } else
Martin Stava2511cd02009-11-02 08:39:34 -06001052 link[min(len, PATH_MAX-1)] = 0;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001053 }
1054 nd_set_link(nd, link);
1055
1056 return NULL;
1057}
1058
1059/**
1060 * v9fs_vfs_put_link - release a symlink path
1061 * @dentry: dentry for symlink
1062 * @nd: nameidata
Eric Van Hensbergenee443992008-03-05 07:08:09 -06001063 * @p: unused
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001064 *
1065 */
1066
Eric Van Hensbergenee443992008-03-05 07:08:09 -06001067static void
1068v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001069{
1070 char *s = nd_get_link(nd);
1071
Duane Griffin6ff23202008-12-19 16:45:21 -06001072 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
1073 IS_ERR(s) ? "<error>" : s);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001074 if (!IS_ERR(s))
Davi Arnautce44eeb2005-11-07 00:59:36 -08001075 __putname(s);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001076}
1077
Eric Van Hensbergenee443992008-03-05 07:08:09 -06001078/**
1079 * v9fs_vfs_mkspecial - create a special file
1080 * @dir: inode to create special file in
1081 * @dentry: dentry to create
1082 * @mode: mode to create special file
1083 * @extension: 9p2000.u format extension string representing special file
1084 *
1085 */
1086
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001087static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
1088 int mode, const char *extension)
1089{
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001090 u32 perm;
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001091 struct v9fs_session_info *v9ses;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001092 struct p9_fid *fid;
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001093
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -08001094 v9ses = v9fs_inode2v9ses(dir);
Sripathi Kodidd6102f2010-03-05 18:48:00 +00001095 if (!v9fs_proto_dotu(v9ses)) {
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001096 P9_DPRINTK(P9_DEBUG_ERROR, "not extended\n");
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -08001097 return -EPERM;
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001098 }
1099
Eric Van Hensbergenda977b22007-01-26 00:57:06 -08001100 perm = unixmode2p9mode(v9ses, mode);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001101 fid = v9fs_create(v9ses, dir, dentry, (char *) extension, perm,
1102 P9_OREAD);
1103 if (IS_ERR(fid))
1104 return PTR_ERR(fid);
Eric Van Hensbergenda977b22007-01-26 00:57:06 -08001105
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001106 p9_client_clunk(fid);
Latchesar Ionkov6a3124a2006-03-02 02:54:30 -08001107 return 0;
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001108}
1109
1110/**
1111 * v9fs_vfs_symlink - helper function to create symlinks
1112 * @dir: directory inode containing symlink
1113 * @dentry: dentry for symlink
1114 * @symname: symlink data
1115 *
Eric Van Hensbergenee443992008-03-05 07:08:09 -06001116 * See Also: 9P2000.u RFC for more information
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001117 *
1118 */
1119
1120static int
1121v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
1122{
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001123 P9_DPRINTK(P9_DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino,
1124 dentry->d_name.name, symname);
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001125
1126 return v9fs_vfs_mkspecial(dir, dentry, S_IFLNK, symname);
1127}
1128
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001129/**
1130 * v9fs_vfs_link - create a hardlink
1131 * @old_dentry: dentry for file to link to
1132 * @dir: inode destination for new link
Eric Van Hensbergen73c592b2005-09-09 13:04:26 -07001133 * @dentry: dentry for link
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001134 *
1135 */
1136
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001137static int
1138v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
1139 struct dentry *dentry)
1140{
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001141 int retval;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001142 struct p9_fid *oldfid;
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001143 char *name;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001144
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001145 P9_DPRINTK(P9_DEBUG_VFS,
1146 " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name,
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001147 old_dentry->d_name.name);
1148
Eric Van Hensbergenda977b22007-01-26 00:57:06 -08001149 oldfid = v9fs_fid_clone(old_dentry);
Latchesar Ionkovba176742007-10-17 14:31:07 -05001150 if (IS_ERR(oldfid))
Eric Van Hensbergenda977b22007-01-26 00:57:06 -08001151 return PTR_ERR(oldfid);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001152
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001153 name = __getname();
Eric Van Hensbergenda977b22007-01-26 00:57:06 -08001154 if (unlikely(!name)) {
1155 retval = -ENOMEM;
1156 goto clunk_fid;
1157 }
Florin Malita0710d362006-06-25 05:48:31 -07001158
Latchesar Ionkov16cce6d2006-03-25 03:07:26 -08001159 sprintf(name, "%d\n", oldfid->fid);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001160 retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name);
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001161 __putname(name);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001162
Eric Van Hensbergenda977b22007-01-26 00:57:06 -08001163clunk_fid:
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001164 p9_client_clunk(oldfid);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001165 return retval;
1166}
1167
1168/**
1169 * v9fs_vfs_mknod - create a special file
1170 * @dir: inode destination for new link
1171 * @dentry: dentry for file
1172 * @mode: mode for creation
Eric Van Hensbergenee443992008-03-05 07:08:09 -06001173 * @rdev: device associated with special file
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001174 *
1175 */
1176
1177static int
1178v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
1179{
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001180 int retval;
1181 char *name;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001182
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05001183 P9_DPRINTK(P9_DEBUG_VFS,
1184 " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001185 dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev));
1186
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001187 if (!new_valid_dev(rdev))
1188 return -EINVAL;
Eric Van Hensbergen73c592b2005-09-09 13:04:26 -07001189
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001190 name = __getname();
Eugene Teoc0291a02006-03-25 03:07:27 -08001191 if (!name)
1192 return -ENOMEM;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001193 /* build extension */
1194 if (S_ISBLK(mode))
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001195 sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev));
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001196 else if (S_ISCHR(mode))
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001197 sprintf(name, "c %u %u", MAJOR(rdev), MINOR(rdev));
Eric Van Hensbergen73c592b2005-09-09 13:04:26 -07001198 else if (S_ISFIFO(mode))
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001199 *name = 0;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001200 else {
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001201 __putname(name);
1202 return -EINVAL;
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001203 }
1204
Latchesar Ionkov531b1092006-01-08 01:05:00 -08001205 retval = v9fs_vfs_mkspecial(dir, dentry, mode, name);
1206 __putname(name);
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001207
1208 return retval;
1209}
1210
Arjan van de Ven754661f2007-02-12 00:55:38 -08001211static const struct inode_operations v9fs_dir_inode_operations_ext = {
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001212 .create = v9fs_vfs_create,
1213 .lookup = v9fs_vfs_lookup,
1214 .symlink = v9fs_vfs_symlink,
1215 .link = v9fs_vfs_link,
1216 .unlink = v9fs_vfs_unlink,
1217 .mkdir = v9fs_vfs_mkdir,
1218 .rmdir = v9fs_vfs_rmdir,
1219 .mknod = v9fs_vfs_mknod,
1220 .rename = v9fs_vfs_rename,
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001221 .getattr = v9fs_vfs_getattr,
1222 .setattr = v9fs_vfs_setattr,
1223};
1224
Arjan van de Ven754661f2007-02-12 00:55:38 -08001225static const struct inode_operations v9fs_dir_inode_operations = {
Eric Van Hensbergenb5016112005-09-09 13:04:27 -07001226 .create = v9fs_vfs_create,
1227 .lookup = v9fs_vfs_lookup,
1228 .unlink = v9fs_vfs_unlink,
1229 .mkdir = v9fs_vfs_mkdir,
1230 .rmdir = v9fs_vfs_rmdir,
1231 .mknod = v9fs_vfs_mknod,
1232 .rename = v9fs_vfs_rename,
1233 .getattr = v9fs_vfs_getattr,
1234 .setattr = v9fs_vfs_setattr,
1235};
1236
Arjan van de Ven754661f2007-02-12 00:55:38 -08001237static const struct inode_operations v9fs_file_inode_operations = {
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001238 .getattr = v9fs_vfs_getattr,
1239 .setattr = v9fs_vfs_setattr,
1240};
1241
Arjan van de Ven754661f2007-02-12 00:55:38 -08001242static const struct inode_operations v9fs_symlink_inode_operations = {
Al Viro204f2f02009-12-23 00:35:54 -05001243 .readlink = generic_readlink,
Eric Van Hensbergen2bad8472005-09-09 13:04:19 -07001244 .follow_link = v9fs_vfs_follow_link,
1245 .put_link = v9fs_vfs_put_link,
1246 .getattr = v9fs_vfs_getattr,
1247 .setattr = v9fs_vfs_setattr,
1248};