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