]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/fuse/dir.c
[PATCH] fuse: fix handling of moved directory
[net-next-2.6.git] / fs / fuse / dir.c
CommitLineData
e5e5558e
MS
1/*
2 FUSE: Filesystem in Userspace
51eb01e7 3 Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu>
e5e5558e
MS
4
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
7*/
8
9#include "fuse_i.h"
10
11#include <linux/pagemap.h>
12#include <linux/file.h>
13#include <linux/gfp.h>
14#include <linux/sched.h>
15#include <linux/namei.h>
16
0a0898cf
MS
17#if BITS_PER_LONG >= 64
18static inline void fuse_dentry_settime(struct dentry *entry, u64 time)
19{
20 entry->d_time = time;
21}
22
23static inline u64 fuse_dentry_time(struct dentry *entry)
24{
25 return entry->d_time;
26}
27#else
28/*
29 * On 32 bit archs store the high 32 bits of time in d_fsdata
30 */
31static void fuse_dentry_settime(struct dentry *entry, u64 time)
32{
33 entry->d_time = time;
34 entry->d_fsdata = (void *) (unsigned long) (time >> 32);
35}
36
37static u64 fuse_dentry_time(struct dentry *entry)
38{
39 return (u64) entry->d_time +
40 ((u64) (unsigned long) entry->d_fsdata << 32);
41}
42#endif
43
6f9f1180
MS
44/*
45 * FUSE caches dentries and attributes with separate timeout. The
46 * time in jiffies until the dentry/attributes are valid is stored in
47 * dentry->d_time and fuse_inode->i_time respectively.
48 */
49
50/*
51 * Calculate the time in jiffies until a dentry/attributes are valid
52 */
0a0898cf 53static u64 time_to_jiffies(unsigned long sec, unsigned long nsec)
e5e5558e 54{
685d16dd
MS
55 if (sec || nsec) {
56 struct timespec ts = {sec, nsec};
0a0898cf 57 return get_jiffies_64() + timespec_to_jiffies(&ts);
685d16dd 58 } else
0a0898cf 59 return 0;
e5e5558e
MS
60}
61
6f9f1180
MS
62/*
63 * Set dentry and possibly attribute timeouts from the lookup/mk*
64 * replies
65 */
0aa7c699
MS
66static void fuse_change_timeout(struct dentry *entry, struct fuse_entry_out *o)
67{
0a0898cf
MS
68 fuse_dentry_settime(entry,
69 time_to_jiffies(o->entry_valid, o->entry_valid_nsec));
8cbdf1e6
MS
70 if (entry->d_inode)
71 get_fuse_inode(entry->d_inode)->i_time =
72 time_to_jiffies(o->attr_valid, o->attr_valid_nsec);
73}
74
6f9f1180
MS
75/*
76 * Mark the attributes as stale, so that at the next call to
77 * ->getattr() they will be fetched from userspace
78 */
8cbdf1e6
MS
79void fuse_invalidate_attr(struct inode *inode)
80{
0a0898cf 81 get_fuse_inode(inode)->i_time = 0;
8cbdf1e6
MS
82}
83
6f9f1180
MS
84/*
85 * Just mark the entry as stale, so that a next attempt to look it up
86 * will result in a new lookup call to userspace
87 *
88 * This is called when a dentry is about to become negative and the
89 * timeout is unknown (unlink, rmdir, rename and in some cases
90 * lookup)
91 */
8cbdf1e6
MS
92static void fuse_invalidate_entry_cache(struct dentry *entry)
93{
0a0898cf 94 fuse_dentry_settime(entry, 0);
8cbdf1e6
MS
95}
96
6f9f1180
MS
97/*
98 * Same as fuse_invalidate_entry_cache(), but also try to remove the
99 * dentry from the hash
100 */
8cbdf1e6
MS
101static void fuse_invalidate_entry(struct dentry *entry)
102{
103 d_invalidate(entry);
104 fuse_invalidate_entry_cache(entry);
0aa7c699
MS
105}
106
e5e5558e
MS
107static void fuse_lookup_init(struct fuse_req *req, struct inode *dir,
108 struct dentry *entry,
109 struct fuse_entry_out *outarg)
110{
111 req->in.h.opcode = FUSE_LOOKUP;
112 req->in.h.nodeid = get_node_id(dir);
e5e5558e
MS
113 req->in.numargs = 1;
114 req->in.args[0].size = entry->d_name.len + 1;
115 req->in.args[0].value = entry->d_name.name;
116 req->out.numargs = 1;
117 req->out.args[0].size = sizeof(struct fuse_entry_out);
118 req->out.args[0].value = outarg;
119}
120
6f9f1180
MS
121/*
122 * Check whether the dentry is still valid
123 *
124 * If the entry validity timeout has expired and the dentry is
125 * positive, try to redo the lookup. If the lookup results in a
126 * different inode, then let the VFS invalidate the dentry and redo
127 * the lookup once more. If the lookup results in the same inode,
128 * then refresh the attributes, timeouts and mark the dentry valid.
129 */
e5e5558e
MS
130static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd)
131{
8cbdf1e6
MS
132 struct inode *inode = entry->d_inode;
133
134 if (inode && is_bad_inode(inode))
e5e5558e 135 return 0;
0a0898cf 136 else if (fuse_dentry_time(entry) < get_jiffies_64()) {
e5e5558e 137 int err;
e5e5558e 138 struct fuse_entry_out outarg;
8cbdf1e6
MS
139 struct fuse_conn *fc;
140 struct fuse_req *req;
141
6f9f1180 142 /* Doesn't hurt to "reset" the validity timeout */
8cbdf1e6 143 fuse_invalidate_entry_cache(entry);
50322fe7
MS
144
145 /* For negative dentries, always do a fresh lookup */
8cbdf1e6
MS
146 if (!inode)
147 return 0;
148
149 fc = get_fuse_conn(inode);
ce1d5a49
MS
150 req = fuse_get_req(fc);
151 if (IS_ERR(req))
e5e5558e
MS
152 return 0;
153
154 fuse_lookup_init(req, entry->d_parent->d_inode, entry, &outarg);
7c352bdf 155 request_send(fc, req);
e5e5558e 156 err = req->out.h.error;
50322fe7
MS
157 /* Zero nodeid is same as -ENOENT */
158 if (!err && !outarg.nodeid)
159 err = -ENOENT;
9e6268db 160 if (!err) {
8cbdf1e6 161 struct fuse_inode *fi = get_fuse_inode(inode);
9e6268db
MS
162 if (outarg.nodeid != get_node_id(inode)) {
163 fuse_send_forget(fc, req, outarg.nodeid, 1);
164 return 0;
165 }
8da5ff23 166 spin_lock(&fc->lock);
9e6268db 167 fi->nlookup ++;
8da5ff23 168 spin_unlock(&fc->lock);
9e6268db 169 }
e5e5558e 170 fuse_put_request(fc, req);
9e6268db 171 if (err || (outarg.attr.mode ^ inode->i_mode) & S_IFMT)
e5e5558e
MS
172 return 0;
173
174 fuse_change_attributes(inode, &outarg.attr);
0aa7c699 175 fuse_change_timeout(entry, &outarg);
e5e5558e
MS
176 }
177 return 1;
178}
179
8bfc016d 180static int invalid_nodeid(u64 nodeid)
2827d0b2
MS
181{
182 return !nodeid || nodeid == FUSE_ROOT_ID;
183}
184
e5e5558e
MS
185static struct dentry_operations fuse_dentry_operations = {
186 .d_revalidate = fuse_dentry_revalidate,
187};
188
8bfc016d 189static int valid_mode(int m)
39ee059a
MS
190{
191 return S_ISREG(m) || S_ISDIR(m) || S_ISLNK(m) || S_ISCHR(m) ||
192 S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m);
193}
194
d2a85164
MS
195/*
196 * Add a directory inode to a dentry, ensuring that no other dentry
197 * refers to this inode. Called with fc->inst_mutex.
198 */
199static int fuse_d_add_directory(struct dentry *entry, struct inode *inode)
200{
201 struct dentry *alias = d_find_alias(inode);
202 if (alias) {
203 /* This tries to shrink the subtree below alias */
204 fuse_invalidate_entry(alias);
205 dput(alias);
206 if (!list_empty(&inode->i_dentry))
207 return -EBUSY;
208 }
209 d_add(entry, inode);
210 return 0;
211}
212
0aa7c699
MS
213static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
214 struct nameidata *nd)
e5e5558e
MS
215{
216 int err;
e5e5558e
MS
217 struct fuse_entry_out outarg;
218 struct inode *inode = NULL;
219 struct fuse_conn *fc = get_fuse_conn(dir);
220 struct fuse_req *req;
221
222 if (entry->d_name.len > FUSE_NAME_MAX)
0aa7c699 223 return ERR_PTR(-ENAMETOOLONG);
e5e5558e 224
ce1d5a49
MS
225 req = fuse_get_req(fc);
226 if (IS_ERR(req))
227 return ERR_PTR(PTR_ERR(req));
e5e5558e
MS
228
229 fuse_lookup_init(req, dir, entry, &outarg);
230 request_send(fc, req);
e5e5558e 231 err = req->out.h.error;
50322fe7
MS
232 /* Zero nodeid is same as -ENOENT, but with valid timeout */
233 if (!err && outarg.nodeid &&
234 (invalid_nodeid(outarg.nodeid) || !valid_mode(outarg.attr.mode)))
ee4e5271 235 err = -EIO;
8cbdf1e6 236 if (!err && outarg.nodeid) {
e5e5558e 237 inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
9e6268db 238 &outarg.attr);
e5e5558e 239 if (!inode) {
9e6268db 240 fuse_send_forget(fc, req, outarg.nodeid, 1);
0aa7c699 241 return ERR_PTR(-ENOMEM);
e5e5558e
MS
242 }
243 }
244 fuse_put_request(fc, req);
245 if (err && err != -ENOENT)
0aa7c699 246 return ERR_PTR(err);
e5e5558e 247
d2a85164
MS
248 if (inode && S_ISDIR(inode->i_mode)) {
249 mutex_lock(&fc->inst_mutex);
250 err = fuse_d_add_directory(entry, inode);
251 mutex_unlock(&fc->inst_mutex);
252 if (err) {
253 iput(inode);
254 return ERR_PTR(err);
255 }
256 } else
257 d_add(entry, inode);
258
e5e5558e 259 entry->d_op = &fuse_dentry_operations;
8cbdf1e6 260 if (!err)
0aa7c699 261 fuse_change_timeout(entry, &outarg);
8cbdf1e6
MS
262 else
263 fuse_invalidate_entry_cache(entry);
0aa7c699 264 return NULL;
e5e5558e
MS
265}
266
51eb01e7
MS
267/*
268 * Synchronous release for the case when something goes wrong in CREATE_OPEN
269 */
270static void fuse_sync_release(struct fuse_conn *fc, struct fuse_file *ff,
271 u64 nodeid, int flags)
272{
273 struct fuse_req *req;
274
275 req = fuse_release_fill(ff, nodeid, flags, FUSE_RELEASE);
276 req->force = 1;
277 request_send(fc, req);
278 fuse_put_request(fc, req);
279}
280
6f9f1180
MS
281/*
282 * Atomic create+open operation
283 *
284 * If the filesystem doesn't support this, then fall back to separate
285 * 'mknod' + 'open' requests.
286 */
fd72faac
MS
287static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
288 struct nameidata *nd)
289{
290 int err;
291 struct inode *inode;
292 struct fuse_conn *fc = get_fuse_conn(dir);
293 struct fuse_req *req;
51eb01e7 294 struct fuse_req *forget_req;
fd72faac
MS
295 struct fuse_open_in inarg;
296 struct fuse_open_out outopen;
297 struct fuse_entry_out outentry;
fd72faac
MS
298 struct fuse_file *ff;
299 struct file *file;
300 int flags = nd->intent.open.flags - 1;
301
fd72faac 302 if (fc->no_create)
ce1d5a49 303 return -ENOSYS;
fd72faac 304
51eb01e7
MS
305 forget_req = fuse_get_req(fc);
306 if (IS_ERR(forget_req))
307 return PTR_ERR(forget_req);
308
ce1d5a49 309 req = fuse_get_req(fc);
51eb01e7 310 err = PTR_ERR(req);
ce1d5a49 311 if (IS_ERR(req))
51eb01e7 312 goto out_put_forget_req;
fd72faac 313
ce1d5a49 314 err = -ENOMEM;
fd72faac
MS
315 ff = fuse_file_alloc();
316 if (!ff)
317 goto out_put_request;
318
319 flags &= ~O_NOCTTY;
320 memset(&inarg, 0, sizeof(inarg));
321 inarg.flags = flags;
322 inarg.mode = mode;
323 req->in.h.opcode = FUSE_CREATE;
324 req->in.h.nodeid = get_node_id(dir);
fd72faac
MS
325 req->in.numargs = 2;
326 req->in.args[0].size = sizeof(inarg);
327 req->in.args[0].value = &inarg;
328 req->in.args[1].size = entry->d_name.len + 1;
329 req->in.args[1].value = entry->d_name.name;
330 req->out.numargs = 2;
331 req->out.args[0].size = sizeof(outentry);
332 req->out.args[0].value = &outentry;
333 req->out.args[1].size = sizeof(outopen);
334 req->out.args[1].value = &outopen;
335 request_send(fc, req);
336 err = req->out.h.error;
337 if (err) {
338 if (err == -ENOSYS)
339 fc->no_create = 1;
340 goto out_free_ff;
341 }
342
343 err = -EIO;
2827d0b2 344 if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid))
fd72faac
MS
345 goto out_free_ff;
346
51eb01e7 347 fuse_put_request(fc, req);
fd72faac
MS
348 inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
349 &outentry.attr);
fd72faac
MS
350 if (!inode) {
351 flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
352 ff->fh = outopen.fh;
51eb01e7
MS
353 fuse_sync_release(fc, ff, outentry.nodeid, flags);
354 fuse_send_forget(fc, forget_req, outentry.nodeid, 1);
355 return -ENOMEM;
fd72faac 356 }
51eb01e7 357 fuse_put_request(fc, forget_req);
fd72faac 358 d_instantiate(entry, inode);
0aa7c699 359 fuse_change_timeout(entry, &outentry);
fd72faac
MS
360 file = lookup_instantiate_filp(nd, entry, generic_file_open);
361 if (IS_ERR(file)) {
362 ff->fh = outopen.fh;
51eb01e7 363 fuse_sync_release(fc, ff, outentry.nodeid, flags);
fd72faac
MS
364 return PTR_ERR(file);
365 }
366 fuse_finish_open(inode, file, ff, &outopen);
367 return 0;
368
369 out_free_ff:
370 fuse_file_free(ff);
371 out_put_request:
372 fuse_put_request(fc, req);
51eb01e7
MS
373 out_put_forget_req:
374 fuse_put_request(fc, forget_req);
fd72faac
MS
375 return err;
376}
377
6f9f1180
MS
378/*
379 * Code shared between mknod, mkdir, symlink and link
380 */
9e6268db
MS
381static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
382 struct inode *dir, struct dentry *entry,
383 int mode)
384{
385 struct fuse_entry_out outarg;
386 struct inode *inode;
9e6268db
MS
387 int err;
388
389 req->in.h.nodeid = get_node_id(dir);
9e6268db
MS
390 req->out.numargs = 1;
391 req->out.args[0].size = sizeof(outarg);
392 req->out.args[0].value = &outarg;
393 request_send(fc, req);
394 err = req->out.h.error;
395 if (err) {
396 fuse_put_request(fc, req);
397 return err;
398 }
39ee059a
MS
399 err = -EIO;
400 if (invalid_nodeid(outarg.nodeid))
401 goto out_put_request;
402
403 if ((outarg.attr.mode ^ mode) & S_IFMT)
404 goto out_put_request;
405
9e6268db
MS
406 inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
407 &outarg.attr);
408 if (!inode) {
409 fuse_send_forget(fc, req, outarg.nodeid, 1);
410 return -ENOMEM;
411 }
412 fuse_put_request(fc, req);
413
d2a85164
MS
414 if (S_ISDIR(inode->i_mode)) {
415 struct dentry *alias;
416 mutex_lock(&fc->inst_mutex);
417 alias = d_find_alias(inode);
418 if (alias) {
419 /* New directory must have moved since mkdir */
420 mutex_unlock(&fc->inst_mutex);
421 dput(alias);
422 iput(inode);
423 return -EBUSY;
424 }
425 d_instantiate(entry, inode);
426 mutex_unlock(&fc->inst_mutex);
427 } else
428 d_instantiate(entry, inode);
9e6268db 429
0aa7c699 430 fuse_change_timeout(entry, &outarg);
9e6268db
MS
431 fuse_invalidate_attr(dir);
432 return 0;
39ee059a
MS
433
434 out_put_request:
435 fuse_put_request(fc, req);
436 return err;
9e6268db
MS
437}
438
439static int fuse_mknod(struct inode *dir, struct dentry *entry, int mode,
440 dev_t rdev)
441{
442 struct fuse_mknod_in inarg;
443 struct fuse_conn *fc = get_fuse_conn(dir);
ce1d5a49
MS
444 struct fuse_req *req = fuse_get_req(fc);
445 if (IS_ERR(req))
446 return PTR_ERR(req);
9e6268db
MS
447
448 memset(&inarg, 0, sizeof(inarg));
449 inarg.mode = mode;
450 inarg.rdev = new_encode_dev(rdev);
451 req->in.h.opcode = FUSE_MKNOD;
452 req->in.numargs = 2;
453 req->in.args[0].size = sizeof(inarg);
454 req->in.args[0].value = &inarg;
455 req->in.args[1].size = entry->d_name.len + 1;
456 req->in.args[1].value = entry->d_name.name;
457 return create_new_entry(fc, req, dir, entry, mode);
458}
459
460static int fuse_create(struct inode *dir, struct dentry *entry, int mode,
461 struct nameidata *nd)
462{
fd72faac
MS
463 if (nd && (nd->flags & LOOKUP_CREATE)) {
464 int err = fuse_create_open(dir, entry, mode, nd);
465 if (err != -ENOSYS)
466 return err;
467 /* Fall back on mknod */
468 }
9e6268db
MS
469 return fuse_mknod(dir, entry, mode, 0);
470}
471
472static int fuse_mkdir(struct inode *dir, struct dentry *entry, int mode)
473{
474 struct fuse_mkdir_in inarg;
475 struct fuse_conn *fc = get_fuse_conn(dir);
ce1d5a49
MS
476 struct fuse_req *req = fuse_get_req(fc);
477 if (IS_ERR(req))
478 return PTR_ERR(req);
9e6268db
MS
479
480 memset(&inarg, 0, sizeof(inarg));
481 inarg.mode = mode;
482 req->in.h.opcode = FUSE_MKDIR;
483 req->in.numargs = 2;
484 req->in.args[0].size = sizeof(inarg);
485 req->in.args[0].value = &inarg;
486 req->in.args[1].size = entry->d_name.len + 1;
487 req->in.args[1].value = entry->d_name.name;
488 return create_new_entry(fc, req, dir, entry, S_IFDIR);
489}
490
491static int fuse_symlink(struct inode *dir, struct dentry *entry,
492 const char *link)
493{
494 struct fuse_conn *fc = get_fuse_conn(dir);
495 unsigned len = strlen(link) + 1;
ce1d5a49
MS
496 struct fuse_req *req = fuse_get_req(fc);
497 if (IS_ERR(req))
498 return PTR_ERR(req);
9e6268db
MS
499
500 req->in.h.opcode = FUSE_SYMLINK;
501 req->in.numargs = 2;
502 req->in.args[0].size = entry->d_name.len + 1;
503 req->in.args[0].value = entry->d_name.name;
504 req->in.args[1].size = len;
505 req->in.args[1].value = link;
506 return create_new_entry(fc, req, dir, entry, S_IFLNK);
507}
508
509static int fuse_unlink(struct inode *dir, struct dentry *entry)
510{
511 int err;
512 struct fuse_conn *fc = get_fuse_conn(dir);
ce1d5a49
MS
513 struct fuse_req *req = fuse_get_req(fc);
514 if (IS_ERR(req))
515 return PTR_ERR(req);
9e6268db
MS
516
517 req->in.h.opcode = FUSE_UNLINK;
518 req->in.h.nodeid = get_node_id(dir);
9e6268db
MS
519 req->in.numargs = 1;
520 req->in.args[0].size = entry->d_name.len + 1;
521 req->in.args[0].value = entry->d_name.name;
522 request_send(fc, req);
523 err = req->out.h.error;
524 fuse_put_request(fc, req);
525 if (!err) {
526 struct inode *inode = entry->d_inode;
527
528 /* Set nlink to zero so the inode can be cleared, if
529 the inode does have more links this will be
530 discovered at the next lookup/getattr */
ce71ec36 531 clear_nlink(inode);
9e6268db
MS
532 fuse_invalidate_attr(inode);
533 fuse_invalidate_attr(dir);
8cbdf1e6 534 fuse_invalidate_entry_cache(entry);
9e6268db
MS
535 } else if (err == -EINTR)
536 fuse_invalidate_entry(entry);
537 return err;
538}
539
540static int fuse_rmdir(struct inode *dir, struct dentry *entry)
541{
542 int err;
543 struct fuse_conn *fc = get_fuse_conn(dir);
ce1d5a49
MS
544 struct fuse_req *req = fuse_get_req(fc);
545 if (IS_ERR(req))
546 return PTR_ERR(req);
9e6268db
MS
547
548 req->in.h.opcode = FUSE_RMDIR;
549 req->in.h.nodeid = get_node_id(dir);
9e6268db
MS
550 req->in.numargs = 1;
551 req->in.args[0].size = entry->d_name.len + 1;
552 req->in.args[0].value = entry->d_name.name;
553 request_send(fc, req);
554 err = req->out.h.error;
555 fuse_put_request(fc, req);
556 if (!err) {
ce71ec36 557 clear_nlink(entry->d_inode);
9e6268db 558 fuse_invalidate_attr(dir);
8cbdf1e6 559 fuse_invalidate_entry_cache(entry);
9e6268db
MS
560 } else if (err == -EINTR)
561 fuse_invalidate_entry(entry);
562 return err;
563}
564
565static int fuse_rename(struct inode *olddir, struct dentry *oldent,
566 struct inode *newdir, struct dentry *newent)
567{
568 int err;
569 struct fuse_rename_in inarg;
570 struct fuse_conn *fc = get_fuse_conn(olddir);
ce1d5a49
MS
571 struct fuse_req *req = fuse_get_req(fc);
572 if (IS_ERR(req))
573 return PTR_ERR(req);
9e6268db
MS
574
575 memset(&inarg, 0, sizeof(inarg));
576 inarg.newdir = get_node_id(newdir);
577 req->in.h.opcode = FUSE_RENAME;
578 req->in.h.nodeid = get_node_id(olddir);
9e6268db
MS
579 req->in.numargs = 3;
580 req->in.args[0].size = sizeof(inarg);
581 req->in.args[0].value = &inarg;
582 req->in.args[1].size = oldent->d_name.len + 1;
583 req->in.args[1].value = oldent->d_name.name;
584 req->in.args[2].size = newent->d_name.len + 1;
585 req->in.args[2].value = newent->d_name.name;
586 request_send(fc, req);
587 err = req->out.h.error;
588 fuse_put_request(fc, req);
589 if (!err) {
590 fuse_invalidate_attr(olddir);
591 if (olddir != newdir)
592 fuse_invalidate_attr(newdir);
8cbdf1e6
MS
593
594 /* newent will end up negative */
595 if (newent->d_inode)
596 fuse_invalidate_entry_cache(newent);
9e6268db
MS
597 } else if (err == -EINTR) {
598 /* If request was interrupted, DEITY only knows if the
599 rename actually took place. If the invalidation
600 fails (e.g. some process has CWD under the renamed
601 directory), then there can be inconsistency between
602 the dcache and the real filesystem. Tough luck. */
603 fuse_invalidate_entry(oldent);
604 if (newent->d_inode)
605 fuse_invalidate_entry(newent);
606 }
607
608 return err;
609}
610
611static int fuse_link(struct dentry *entry, struct inode *newdir,
612 struct dentry *newent)
613{
614 int err;
615 struct fuse_link_in inarg;
616 struct inode *inode = entry->d_inode;
617 struct fuse_conn *fc = get_fuse_conn(inode);
ce1d5a49
MS
618 struct fuse_req *req = fuse_get_req(fc);
619 if (IS_ERR(req))
620 return PTR_ERR(req);
9e6268db
MS
621
622 memset(&inarg, 0, sizeof(inarg));
623 inarg.oldnodeid = get_node_id(inode);
624 req->in.h.opcode = FUSE_LINK;
9e6268db
MS
625 req->in.numargs = 2;
626 req->in.args[0].size = sizeof(inarg);
627 req->in.args[0].value = &inarg;
628 req->in.args[1].size = newent->d_name.len + 1;
629 req->in.args[1].value = newent->d_name.name;
630 err = create_new_entry(fc, req, newdir, newent, inode->i_mode);
631 /* Contrary to "normal" filesystems it can happen that link
632 makes two "logical" inodes point to the same "physical"
633 inode. We invalidate the attributes of the old one, so it
634 will reflect changes in the backing inode (link count,
635 etc.)
636 */
637 if (!err || err == -EINTR)
638 fuse_invalidate_attr(inode);
639 return err;
640}
641
e5e5558e
MS
642int fuse_do_getattr(struct inode *inode)
643{
644 int err;
645 struct fuse_attr_out arg;
646 struct fuse_conn *fc = get_fuse_conn(inode);
ce1d5a49
MS
647 struct fuse_req *req = fuse_get_req(fc);
648 if (IS_ERR(req))
649 return PTR_ERR(req);
e5e5558e
MS
650
651 req->in.h.opcode = FUSE_GETATTR;
652 req->in.h.nodeid = get_node_id(inode);
e5e5558e
MS
653 req->out.numargs = 1;
654 req->out.args[0].size = sizeof(arg);
655 req->out.args[0].value = &arg;
656 request_send(fc, req);
657 err = req->out.h.error;
658 fuse_put_request(fc, req);
659 if (!err) {
660 if ((inode->i_mode ^ arg.attr.mode) & S_IFMT) {
661 make_bad_inode(inode);
662 err = -EIO;
663 } else {
664 struct fuse_inode *fi = get_fuse_inode(inode);
665 fuse_change_attributes(inode, &arg.attr);
666 fi->i_time = time_to_jiffies(arg.attr_valid,
667 arg.attr_valid_nsec);
668 }
669 }
670 return err;
671}
672
87729a55
MS
673/*
674 * Calling into a user-controlled filesystem gives the filesystem
675 * daemon ptrace-like capabilities over the requester process. This
676 * means, that the filesystem daemon is able to record the exact
677 * filesystem operations performed, and can also control the behavior
678 * of the requester process in otherwise impossible ways. For example
679 * it can delay the operation for arbitrary length of time allowing
680 * DoS against the requester.
681 *
682 * For this reason only those processes can call into the filesystem,
683 * for which the owner of the mount has ptrace privilege. This
684 * excludes processes started by other users, suid or sgid processes.
685 */
686static int fuse_allow_task(struct fuse_conn *fc, struct task_struct *task)
687{
688 if (fc->flags & FUSE_ALLOW_OTHER)
689 return 1;
690
691 if (task->euid == fc->user_id &&
692 task->suid == fc->user_id &&
693 task->uid == fc->user_id &&
694 task->egid == fc->group_id &&
695 task->sgid == fc->group_id &&
696 task->gid == fc->group_id)
697 return 1;
698
699 return 0;
700}
701
6f9f1180
MS
702/*
703 * Check whether the inode attributes are still valid
704 *
705 * If the attribute validity timeout has expired, then fetch the fresh
706 * attributes with a 'getattr' request
707 *
708 * I'm not sure why cached attributes are never returned for the root
709 * inode, this is probably being too cautious.
710 */
e5e5558e
MS
711static int fuse_revalidate(struct dentry *entry)
712{
713 struct inode *inode = entry->d_inode;
714 struct fuse_inode *fi = get_fuse_inode(inode);
715 struct fuse_conn *fc = get_fuse_conn(inode);
716
87729a55
MS
717 if (!fuse_allow_task(fc, current))
718 return -EACCES;
719 if (get_node_id(inode) != FUSE_ROOT_ID &&
0a0898cf 720 fi->i_time >= get_jiffies_64())
e5e5558e
MS
721 return 0;
722
723 return fuse_do_getattr(inode);
724}
725
31d40d74
MS
726static int fuse_access(struct inode *inode, int mask)
727{
728 struct fuse_conn *fc = get_fuse_conn(inode);
729 struct fuse_req *req;
730 struct fuse_access_in inarg;
731 int err;
732
733 if (fc->no_access)
734 return 0;
735
ce1d5a49
MS
736 req = fuse_get_req(fc);
737 if (IS_ERR(req))
738 return PTR_ERR(req);
31d40d74
MS
739
740 memset(&inarg, 0, sizeof(inarg));
741 inarg.mask = mask;
742 req->in.h.opcode = FUSE_ACCESS;
743 req->in.h.nodeid = get_node_id(inode);
31d40d74
MS
744 req->in.numargs = 1;
745 req->in.args[0].size = sizeof(inarg);
746 req->in.args[0].value = &inarg;
747 request_send(fc, req);
748 err = req->out.h.error;
749 fuse_put_request(fc, req);
750 if (err == -ENOSYS) {
751 fc->no_access = 1;
752 err = 0;
753 }
754 return err;
755}
756
6f9f1180
MS
757/*
758 * Check permission. The two basic access models of FUSE are:
759 *
760 * 1) Local access checking ('default_permissions' mount option) based
761 * on file mode. This is the plain old disk filesystem permission
762 * modell.
763 *
764 * 2) "Remote" access checking, where server is responsible for
765 * checking permission in each inode operation. An exception to this
766 * is if ->permission() was invoked from sys_access() in which case an
767 * access request is sent. Execute permission is still checked
768 * locally based on file mode.
769 */
e5e5558e
MS
770static int fuse_permission(struct inode *inode, int mask, struct nameidata *nd)
771{
772 struct fuse_conn *fc = get_fuse_conn(inode);
773
87729a55 774 if (!fuse_allow_task(fc, current))
e5e5558e 775 return -EACCES;
1e9a4ed9
MS
776 else if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
777 int err = generic_permission(inode, mask, NULL);
778
779 /* If permission is denied, try to refresh file
780 attributes. This is also needed, because the root
781 node will at first have no permissions */
782 if (err == -EACCES) {
783 err = fuse_do_getattr(inode);
784 if (!err)
785 err = generic_permission(inode, mask, NULL);
786 }
787
6f9f1180
MS
788 /* Note: the opposite of the above test does not
789 exist. So if permissions are revoked this won't be
790 noticed immediately, only after the attribute
791 timeout has expired */
1e9a4ed9
MS
792
793 return err;
794 } else {
e5e5558e 795 int mode = inode->i_mode;
e5e5558e
MS
796 if ((mask & MAY_EXEC) && !S_ISDIR(mode) && !(mode & S_IXUGO))
797 return -EACCES;
31d40d74 798
650a8983 799 if (nd && (nd->flags & (LOOKUP_ACCESS | LOOKUP_CHDIR)))
31d40d74 800 return fuse_access(inode, mask);
e5e5558e
MS
801 return 0;
802 }
803}
804
805static int parse_dirfile(char *buf, size_t nbytes, struct file *file,
806 void *dstbuf, filldir_t filldir)
807{
808 while (nbytes >= FUSE_NAME_OFFSET) {
809 struct fuse_dirent *dirent = (struct fuse_dirent *) buf;
810 size_t reclen = FUSE_DIRENT_SIZE(dirent);
811 int over;
812 if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX)
813 return -EIO;
814 if (reclen > nbytes)
815 break;
816
817 over = filldir(dstbuf, dirent->name, dirent->namelen,
818 file->f_pos, dirent->ino, dirent->type);
819 if (over)
820 break;
821
822 buf += reclen;
823 nbytes -= reclen;
824 file->f_pos = dirent->off;
825 }
826
827 return 0;
828}
829
04730fef 830static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir)
e5e5558e 831{
04730fef
MS
832 int err;
833 size_t nbytes;
834 struct page *page;
e5e5558e
MS
835 struct inode *inode = file->f_dentry->d_inode;
836 struct fuse_conn *fc = get_fuse_conn(inode);
248d86e8
MS
837 struct fuse_req *req;
838
839 if (is_bad_inode(inode))
840 return -EIO;
841
ce1d5a49
MS
842 req = fuse_get_req(fc);
843 if (IS_ERR(req))
844 return PTR_ERR(req);
e5e5558e 845
04730fef
MS
846 page = alloc_page(GFP_KERNEL);
847 if (!page) {
848 fuse_put_request(fc, req);
849 return -ENOMEM;
850 }
851 req->num_pages = 1;
852 req->pages[0] = page;
361b1eb5
MS
853 fuse_read_fill(req, file, inode, file->f_pos, PAGE_SIZE, FUSE_READDIR);
854 request_send(fc, req);
855 nbytes = req->out.args[0].size;
e5e5558e
MS
856 err = req->out.h.error;
857 fuse_put_request(fc, req);
858 if (!err)
04730fef
MS
859 err = parse_dirfile(page_address(page), nbytes, file, dstbuf,
860 filldir);
e5e5558e 861
04730fef 862 __free_page(page);
b36c31ba 863 fuse_invalidate_attr(inode); /* atime changed */
04730fef 864 return err;
e5e5558e
MS
865}
866
867static char *read_link(struct dentry *dentry)
868{
869 struct inode *inode = dentry->d_inode;
870 struct fuse_conn *fc = get_fuse_conn(inode);
ce1d5a49 871 struct fuse_req *req = fuse_get_req(fc);
e5e5558e
MS
872 char *link;
873
ce1d5a49
MS
874 if (IS_ERR(req))
875 return ERR_PTR(PTR_ERR(req));
e5e5558e
MS
876
877 link = (char *) __get_free_page(GFP_KERNEL);
878 if (!link) {
879 link = ERR_PTR(-ENOMEM);
880 goto out;
881 }
882 req->in.h.opcode = FUSE_READLINK;
883 req->in.h.nodeid = get_node_id(inode);
e5e5558e
MS
884 req->out.argvar = 1;
885 req->out.numargs = 1;
886 req->out.args[0].size = PAGE_SIZE - 1;
887 req->out.args[0].value = link;
888 request_send(fc, req);
889 if (req->out.h.error) {
890 free_page((unsigned long) link);
891 link = ERR_PTR(req->out.h.error);
892 } else
893 link[req->out.args[0].size] = '\0';
894 out:
895 fuse_put_request(fc, req);
b36c31ba 896 fuse_invalidate_attr(inode); /* atime changed */
e5e5558e
MS
897 return link;
898}
899
900static void free_link(char *link)
901{
902 if (!IS_ERR(link))
903 free_page((unsigned long) link);
904}
905
906static void *fuse_follow_link(struct dentry *dentry, struct nameidata *nd)
907{
908 nd_set_link(nd, read_link(dentry));
909 return NULL;
910}
911
912static void fuse_put_link(struct dentry *dentry, struct nameidata *nd, void *c)
913{
914 free_link(nd_get_link(nd));
915}
916
917static int fuse_dir_open(struct inode *inode, struct file *file)
918{
04730fef 919 return fuse_open_common(inode, file, 1);
e5e5558e
MS
920}
921
922static int fuse_dir_release(struct inode *inode, struct file *file)
923{
04730fef 924 return fuse_release_common(inode, file, 1);
e5e5558e
MS
925}
926
82547981
MS
927static int fuse_dir_fsync(struct file *file, struct dentry *de, int datasync)
928{
929 /* nfsd can call this with no file */
930 return file ? fuse_fsync_common(file, de, datasync, 1) : 0;
931}
932
befc649c 933static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg)
9e6268db
MS
934{
935 unsigned ivalid = iattr->ia_valid;
9e6268db
MS
936
937 if (ivalid & ATTR_MODE)
befc649c 938 arg->valid |= FATTR_MODE, arg->mode = iattr->ia_mode;
9e6268db 939 if (ivalid & ATTR_UID)
befc649c 940 arg->valid |= FATTR_UID, arg->uid = iattr->ia_uid;
9e6268db 941 if (ivalid & ATTR_GID)
befc649c 942 arg->valid |= FATTR_GID, arg->gid = iattr->ia_gid;
9e6268db 943 if (ivalid & ATTR_SIZE)
befc649c 944 arg->valid |= FATTR_SIZE, arg->size = iattr->ia_size;
9e6268db
MS
945 /* You can only _set_ these together (they may change by themselves) */
946 if ((ivalid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) {
befc649c
MS
947 arg->valid |= FATTR_ATIME | FATTR_MTIME;
948 arg->atime = iattr->ia_atime.tv_sec;
949 arg->mtime = iattr->ia_mtime.tv_sec;
950 }
951 if (ivalid & ATTR_FILE) {
952 struct fuse_file *ff = iattr->ia_file->private_data;
953 arg->valid |= FATTR_FH;
954 arg->fh = ff->fh;
9e6268db 955 }
9e6268db
MS
956}
957
9ffbb916
MS
958static void fuse_vmtruncate(struct inode *inode, loff_t offset)
959{
960 struct fuse_conn *fc = get_fuse_conn(inode);
961 int need_trunc;
962
963 spin_lock(&fc->lock);
964 need_trunc = inode->i_size > offset;
965 i_size_write(inode, offset);
966 spin_unlock(&fc->lock);
967
968 if (need_trunc) {
969 struct address_space *mapping = inode->i_mapping;
970 unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
971 truncate_inode_pages(mapping, offset);
972 }
973}
974
6f9f1180
MS
975/*
976 * Set attributes, and at the same time refresh them.
977 *
978 * Truncation is slightly complicated, because the 'truncate' request
979 * may fail, in which case we don't want to touch the mapping.
9ffbb916
MS
980 * vmtruncate() doesn't allow for this case, so do the rlimit checking
981 * and the actual truncation by hand.
6f9f1180 982 */
9e6268db
MS
983static int fuse_setattr(struct dentry *entry, struct iattr *attr)
984{
985 struct inode *inode = entry->d_inode;
986 struct fuse_conn *fc = get_fuse_conn(inode);
987 struct fuse_inode *fi = get_fuse_inode(inode);
988 struct fuse_req *req;
989 struct fuse_setattr_in inarg;
990 struct fuse_attr_out outarg;
991 int err;
992 int is_truncate = 0;
993
1e9a4ed9
MS
994 if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
995 err = inode_change_ok(inode, attr);
996 if (err)
997 return err;
998 }
999
9e6268db
MS
1000 if (attr->ia_valid & ATTR_SIZE) {
1001 unsigned long limit;
1002 is_truncate = 1;
1003 limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
1004 if (limit != RLIM_INFINITY && attr->ia_size > (loff_t) limit) {
1005 send_sig(SIGXFSZ, current, 0);
1006 return -EFBIG;
1007 }
1008 }
1009
ce1d5a49
MS
1010 req = fuse_get_req(fc);
1011 if (IS_ERR(req))
1012 return PTR_ERR(req);
9e6268db
MS
1013
1014 memset(&inarg, 0, sizeof(inarg));
befc649c 1015 iattr_to_fattr(attr, &inarg);
9e6268db
MS
1016 req->in.h.opcode = FUSE_SETATTR;
1017 req->in.h.nodeid = get_node_id(inode);
9e6268db
MS
1018 req->in.numargs = 1;
1019 req->in.args[0].size = sizeof(inarg);
1020 req->in.args[0].value = &inarg;
1021 req->out.numargs = 1;
1022 req->out.args[0].size = sizeof(outarg);
1023 req->out.args[0].value = &outarg;
1024 request_send(fc, req);
1025 err = req->out.h.error;
1026 fuse_put_request(fc, req);
1027 if (!err) {
1028 if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
1029 make_bad_inode(inode);
1030 err = -EIO;
1031 } else {
9ffbb916
MS
1032 if (is_truncate)
1033 fuse_vmtruncate(inode, outarg.attr.size);
9e6268db
MS
1034 fuse_change_attributes(inode, &outarg.attr);
1035 fi->i_time = time_to_jiffies(outarg.attr_valid,
1036 outarg.attr_valid_nsec);
1037 }
1038 } else if (err == -EINTR)
1039 fuse_invalidate_attr(inode);
1040
1041 return err;
1042}
1043
e5e5558e
MS
1044static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,
1045 struct kstat *stat)
1046{
1047 struct inode *inode = entry->d_inode;
1048 int err = fuse_revalidate(entry);
1049 if (!err)
1050 generic_fillattr(inode, stat);
1051
1052 return err;
1053}
1054
92a8780e
MS
1055static int fuse_setxattr(struct dentry *entry, const char *name,
1056 const void *value, size_t size, int flags)
1057{
1058 struct inode *inode = entry->d_inode;
1059 struct fuse_conn *fc = get_fuse_conn(inode);
1060 struct fuse_req *req;
1061 struct fuse_setxattr_in inarg;
1062 int err;
1063
92a8780e
MS
1064 if (fc->no_setxattr)
1065 return -EOPNOTSUPP;
1066
ce1d5a49
MS
1067 req = fuse_get_req(fc);
1068 if (IS_ERR(req))
1069 return PTR_ERR(req);
92a8780e
MS
1070
1071 memset(&inarg, 0, sizeof(inarg));
1072 inarg.size = size;
1073 inarg.flags = flags;
1074 req->in.h.opcode = FUSE_SETXATTR;
1075 req->in.h.nodeid = get_node_id(inode);
92a8780e
MS
1076 req->in.numargs = 3;
1077 req->in.args[0].size = sizeof(inarg);
1078 req->in.args[0].value = &inarg;
1079 req->in.args[1].size = strlen(name) + 1;
1080 req->in.args[1].value = name;
1081 req->in.args[2].size = size;
1082 req->in.args[2].value = value;
1083 request_send(fc, req);
1084 err = req->out.h.error;
1085 fuse_put_request(fc, req);
1086 if (err == -ENOSYS) {
1087 fc->no_setxattr = 1;
1088 err = -EOPNOTSUPP;
1089 }
1090 return err;
1091}
1092
1093static ssize_t fuse_getxattr(struct dentry *entry, const char *name,
1094 void *value, size_t size)
1095{
1096 struct inode *inode = entry->d_inode;
1097 struct fuse_conn *fc = get_fuse_conn(inode);
1098 struct fuse_req *req;
1099 struct fuse_getxattr_in inarg;
1100 struct fuse_getxattr_out outarg;
1101 ssize_t ret;
1102
1103 if (fc->no_getxattr)
1104 return -EOPNOTSUPP;
1105
ce1d5a49
MS
1106 req = fuse_get_req(fc);
1107 if (IS_ERR(req))
1108 return PTR_ERR(req);
92a8780e
MS
1109
1110 memset(&inarg, 0, sizeof(inarg));
1111 inarg.size = size;
1112 req->in.h.opcode = FUSE_GETXATTR;
1113 req->in.h.nodeid = get_node_id(inode);
92a8780e
MS
1114 req->in.numargs = 2;
1115 req->in.args[0].size = sizeof(inarg);
1116 req->in.args[0].value = &inarg;
1117 req->in.args[1].size = strlen(name) + 1;
1118 req->in.args[1].value = name;
1119 /* This is really two different operations rolled into one */
1120 req->out.numargs = 1;
1121 if (size) {
1122 req->out.argvar = 1;
1123 req->out.args[0].size = size;
1124 req->out.args[0].value = value;
1125 } else {
1126 req->out.args[0].size = sizeof(outarg);
1127 req->out.args[0].value = &outarg;
1128 }
1129 request_send(fc, req);
1130 ret = req->out.h.error;
1131 if (!ret)
1132 ret = size ? req->out.args[0].size : outarg.size;
1133 else {
1134 if (ret == -ENOSYS) {
1135 fc->no_getxattr = 1;
1136 ret = -EOPNOTSUPP;
1137 }
1138 }
1139 fuse_put_request(fc, req);
1140 return ret;
1141}
1142
1143static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)
1144{
1145 struct inode *inode = entry->d_inode;
1146 struct fuse_conn *fc = get_fuse_conn(inode);
1147 struct fuse_req *req;
1148 struct fuse_getxattr_in inarg;
1149 struct fuse_getxattr_out outarg;
1150 ssize_t ret;
1151
1152 if (fc->no_listxattr)
1153 return -EOPNOTSUPP;
1154
ce1d5a49
MS
1155 req = fuse_get_req(fc);
1156 if (IS_ERR(req))
1157 return PTR_ERR(req);
92a8780e
MS
1158
1159 memset(&inarg, 0, sizeof(inarg));
1160 inarg.size = size;
1161 req->in.h.opcode = FUSE_LISTXATTR;
1162 req->in.h.nodeid = get_node_id(inode);
92a8780e
MS
1163 req->in.numargs = 1;
1164 req->in.args[0].size = sizeof(inarg);
1165 req->in.args[0].value = &inarg;
1166 /* This is really two different operations rolled into one */
1167 req->out.numargs = 1;
1168 if (size) {
1169 req->out.argvar = 1;
1170 req->out.args[0].size = size;
1171 req->out.args[0].value = list;
1172 } else {
1173 req->out.args[0].size = sizeof(outarg);
1174 req->out.args[0].value = &outarg;
1175 }
1176 request_send(fc, req);
1177 ret = req->out.h.error;
1178 if (!ret)
1179 ret = size ? req->out.args[0].size : outarg.size;
1180 else {
1181 if (ret == -ENOSYS) {
1182 fc->no_listxattr = 1;
1183 ret = -EOPNOTSUPP;
1184 }
1185 }
1186 fuse_put_request(fc, req);
1187 return ret;
1188}
1189
1190static int fuse_removexattr(struct dentry *entry, const char *name)
1191{
1192 struct inode *inode = entry->d_inode;
1193 struct fuse_conn *fc = get_fuse_conn(inode);
1194 struct fuse_req *req;
1195 int err;
1196
1197 if (fc->no_removexattr)
1198 return -EOPNOTSUPP;
1199
ce1d5a49
MS
1200 req = fuse_get_req(fc);
1201 if (IS_ERR(req))
1202 return PTR_ERR(req);
92a8780e
MS
1203
1204 req->in.h.opcode = FUSE_REMOVEXATTR;
1205 req->in.h.nodeid = get_node_id(inode);
92a8780e
MS
1206 req->in.numargs = 1;
1207 req->in.args[0].size = strlen(name) + 1;
1208 req->in.args[0].value = name;
1209 request_send(fc, req);
1210 err = req->out.h.error;
1211 fuse_put_request(fc, req);
1212 if (err == -ENOSYS) {
1213 fc->no_removexattr = 1;
1214 err = -EOPNOTSUPP;
1215 }
1216 return err;
1217}
1218
e5e5558e
MS
1219static struct inode_operations fuse_dir_inode_operations = {
1220 .lookup = fuse_lookup,
9e6268db
MS
1221 .mkdir = fuse_mkdir,
1222 .symlink = fuse_symlink,
1223 .unlink = fuse_unlink,
1224 .rmdir = fuse_rmdir,
1225 .rename = fuse_rename,
1226 .link = fuse_link,
1227 .setattr = fuse_setattr,
1228 .create = fuse_create,
1229 .mknod = fuse_mknod,
e5e5558e
MS
1230 .permission = fuse_permission,
1231 .getattr = fuse_getattr,
92a8780e
MS
1232 .setxattr = fuse_setxattr,
1233 .getxattr = fuse_getxattr,
1234 .listxattr = fuse_listxattr,
1235 .removexattr = fuse_removexattr,
e5e5558e
MS
1236};
1237
4b6f5d20 1238static const struct file_operations fuse_dir_operations = {
b6aeaded 1239 .llseek = generic_file_llseek,
e5e5558e
MS
1240 .read = generic_read_dir,
1241 .readdir = fuse_readdir,
1242 .open = fuse_dir_open,
1243 .release = fuse_dir_release,
82547981 1244 .fsync = fuse_dir_fsync,
e5e5558e
MS
1245};
1246
1247static struct inode_operations fuse_common_inode_operations = {
9e6268db 1248 .setattr = fuse_setattr,
e5e5558e
MS
1249 .permission = fuse_permission,
1250 .getattr = fuse_getattr,
92a8780e
MS
1251 .setxattr = fuse_setxattr,
1252 .getxattr = fuse_getxattr,
1253 .listxattr = fuse_listxattr,
1254 .removexattr = fuse_removexattr,
e5e5558e
MS
1255};
1256
1257static struct inode_operations fuse_symlink_inode_operations = {
9e6268db 1258 .setattr = fuse_setattr,
e5e5558e
MS
1259 .follow_link = fuse_follow_link,
1260 .put_link = fuse_put_link,
1261 .readlink = generic_readlink,
1262 .getattr = fuse_getattr,
92a8780e
MS
1263 .setxattr = fuse_setxattr,
1264 .getxattr = fuse_getxattr,
1265 .listxattr = fuse_listxattr,
1266 .removexattr = fuse_removexattr,
e5e5558e
MS
1267};
1268
1269void fuse_init_common(struct inode *inode)
1270{
1271 inode->i_op = &fuse_common_inode_operations;
1272}
1273
1274void fuse_init_dir(struct inode *inode)
1275{
1276 inode->i_op = &fuse_dir_inode_operations;
1277 inode->i_fop = &fuse_dir_operations;
1278}
1279
1280void fuse_init_symlink(struct inode *inode)
1281{
1282 inode->i_op = &fuse_symlink_inode_operations;
1283}