dir.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902
  1. /*
  2. FUSE: Filesystem in Userspace
  3. Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
  4. This program can be distributed under the terms of the GNU GPL.
  5. See the file COPYING.
  6. */
  7. #include "fuse_i.h"
  8. #include <linux/pagemap.h>
  9. #include <linux/file.h>
  10. #include <linux/sched.h>
  11. #include <linux/namei.h>
  12. #include <linux/slab.h>
  13. #include <linux/xattr.h>
  14. #include <linux/posix_acl.h>
  15. static bool fuse_use_readdirplus(struct inode *dir, struct dir_context *ctx)
  16. {
  17. struct fuse_conn *fc = get_fuse_conn(dir);
  18. struct fuse_inode *fi = get_fuse_inode(dir);
  19. if (!fc->do_readdirplus)
  20. return false;
  21. if (!fc->readdirplus_auto)
  22. return true;
  23. if (test_and_clear_bit(FUSE_I_ADVISE_RDPLUS, &fi->state))
  24. return true;
  25. if (ctx->pos == 0)
  26. return true;
  27. return false;
  28. }
  29. static void fuse_advise_use_readdirplus(struct inode *dir)
  30. {
  31. struct fuse_inode *fi = get_fuse_inode(dir);
  32. set_bit(FUSE_I_ADVISE_RDPLUS, &fi->state);
  33. }
  34. union fuse_dentry {
  35. u64 time;
  36. struct rcu_head rcu;
  37. };
  38. static inline void fuse_dentry_settime(struct dentry *entry, u64 time)
  39. {
  40. ((union fuse_dentry *) entry->d_fsdata)->time = time;
  41. }
  42. static inline u64 fuse_dentry_time(struct dentry *entry)
  43. {
  44. return ((union fuse_dentry *) entry->d_fsdata)->time;
  45. }
  46. /*
  47. * FUSE caches dentries and attributes with separate timeout. The
  48. * time in jiffies until the dentry/attributes are valid is stored in
  49. * dentry->d_fsdata and fuse_inode->i_time respectively.
  50. */
  51. /*
  52. * Calculate the time in jiffies until a dentry/attributes are valid
  53. */
  54. static u64 time_to_jiffies(u64 sec, u32 nsec)
  55. {
  56. if (sec || nsec) {
  57. struct timespec64 ts = {
  58. sec,
  59. min_t(u32, nsec, NSEC_PER_SEC - 1)
  60. };
  61. return get_jiffies_64() + timespec64_to_jiffies(&ts);
  62. } else
  63. return 0;
  64. }
  65. /*
  66. * Set dentry and possibly attribute timeouts from the lookup/mk*
  67. * replies
  68. */
  69. static void fuse_change_entry_timeout(struct dentry *entry,
  70. struct fuse_entry_out *o)
  71. {
  72. fuse_dentry_settime(entry,
  73. time_to_jiffies(o->entry_valid, o->entry_valid_nsec));
  74. }
  75. static u64 attr_timeout(struct fuse_attr_out *o)
  76. {
  77. return time_to_jiffies(o->attr_valid, o->attr_valid_nsec);
  78. }
  79. static u64 entry_attr_timeout(struct fuse_entry_out *o)
  80. {
  81. return time_to_jiffies(o->attr_valid, o->attr_valid_nsec);
  82. }
  83. /*
  84. * Mark the attributes as stale, so that at the next call to
  85. * ->getattr() they will be fetched from userspace
  86. */
  87. void fuse_invalidate_attr(struct inode *inode)
  88. {
  89. get_fuse_inode(inode)->i_time = 0;
  90. }
  91. /**
  92. * Mark the attributes as stale due to an atime change. Avoid the invalidate if
  93. * atime is not used.
  94. */
  95. void fuse_invalidate_atime(struct inode *inode)
  96. {
  97. if (!IS_RDONLY(inode))
  98. fuse_invalidate_attr(inode);
  99. }
  100. /*
  101. * Just mark the entry as stale, so that a next attempt to look it up
  102. * will result in a new lookup call to userspace
  103. *
  104. * This is called when a dentry is about to become negative and the
  105. * timeout is unknown (unlink, rmdir, rename and in some cases
  106. * lookup)
  107. */
  108. void fuse_invalidate_entry_cache(struct dentry *entry)
  109. {
  110. fuse_dentry_settime(entry, 0);
  111. }
  112. /*
  113. * Same as fuse_invalidate_entry_cache(), but also try to remove the
  114. * dentry from the hash
  115. */
  116. static void fuse_invalidate_entry(struct dentry *entry)
  117. {
  118. d_invalidate(entry);
  119. fuse_invalidate_entry_cache(entry);
  120. }
  121. static void fuse_lookup_init(struct fuse_conn *fc, struct fuse_args *args,
  122. u64 nodeid, const struct qstr *name,
  123. struct fuse_entry_out *outarg)
  124. {
  125. memset(outarg, 0, sizeof(struct fuse_entry_out));
  126. args->in.h.opcode = FUSE_LOOKUP;
  127. args->in.h.nodeid = nodeid;
  128. args->in.numargs = 1;
  129. args->in.args[0].size = name->len + 1;
  130. args->in.args[0].value = name->name;
  131. args->out.numargs = 1;
  132. args->out.args[0].size = sizeof(struct fuse_entry_out);
  133. args->out.args[0].value = outarg;
  134. }
  135. u64 fuse_get_attr_version(struct fuse_conn *fc)
  136. {
  137. u64 curr_version;
  138. /*
  139. * The spin lock isn't actually needed on 64bit archs, but we
  140. * don't yet care too much about such optimizations.
  141. */
  142. spin_lock(&fc->lock);
  143. curr_version = fc->attr_version;
  144. spin_unlock(&fc->lock);
  145. return curr_version;
  146. }
  147. /*
  148. * Check whether the dentry is still valid
  149. *
  150. * If the entry validity timeout has expired and the dentry is
  151. * positive, try to redo the lookup. If the lookup results in a
  152. * different inode, then let the VFS invalidate the dentry and redo
  153. * the lookup once more. If the lookup results in the same inode,
  154. * then refresh the attributes, timeouts and mark the dentry valid.
  155. */
  156. static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
  157. {
  158. struct inode *inode;
  159. struct dentry *parent;
  160. struct fuse_conn *fc;
  161. struct fuse_inode *fi;
  162. int ret;
  163. inode = d_inode_rcu(entry);
  164. if (inode && is_bad_inode(inode))
  165. goto invalid;
  166. else if (time_before64(fuse_dentry_time(entry), get_jiffies_64()) ||
  167. (flags & LOOKUP_REVAL)) {
  168. struct fuse_entry_out outarg;
  169. FUSE_ARGS(args);
  170. struct fuse_forget_link *forget;
  171. u64 attr_version;
  172. /* For negative dentries, always do a fresh lookup */
  173. if (!inode)
  174. goto invalid;
  175. ret = -ECHILD;
  176. if (flags & LOOKUP_RCU)
  177. goto out;
  178. fc = get_fuse_conn(inode);
  179. forget = fuse_alloc_forget();
  180. ret = -ENOMEM;
  181. if (!forget)
  182. goto out;
  183. attr_version = fuse_get_attr_version(fc);
  184. parent = dget_parent(entry);
  185. fuse_lookup_init(fc, &args, get_node_id(d_inode(parent)),
  186. &entry->d_name, &outarg);
  187. ret = fuse_simple_request(fc, &args);
  188. dput(parent);
  189. /* Zero nodeid is same as -ENOENT */
  190. if (!ret && !outarg.nodeid)
  191. ret = -ENOENT;
  192. if (!ret) {
  193. fi = get_fuse_inode(inode);
  194. if (outarg.nodeid != get_node_id(inode)) {
  195. fuse_queue_forget(fc, forget, outarg.nodeid, 1);
  196. goto invalid;
  197. }
  198. spin_lock(&fc->lock);
  199. fi->nlookup++;
  200. spin_unlock(&fc->lock);
  201. }
  202. kfree(forget);
  203. if (ret == -ENOMEM)
  204. goto out;
  205. if (ret || fuse_invalid_attr(&outarg.attr) ||
  206. (outarg.attr.mode ^ inode->i_mode) & S_IFMT)
  207. goto invalid;
  208. forget_all_cached_acls(inode);
  209. fuse_change_attributes(inode, &outarg.attr,
  210. entry_attr_timeout(&outarg),
  211. attr_version);
  212. fuse_change_entry_timeout(entry, &outarg);
  213. } else if (inode) {
  214. fi = get_fuse_inode(inode);
  215. if (flags & LOOKUP_RCU) {
  216. if (test_bit(FUSE_I_INIT_RDPLUS, &fi->state))
  217. return -ECHILD;
  218. } else if (test_and_clear_bit(FUSE_I_INIT_RDPLUS, &fi->state)) {
  219. parent = dget_parent(entry);
  220. fuse_advise_use_readdirplus(d_inode(parent));
  221. dput(parent);
  222. }
  223. }
  224. ret = 1;
  225. out:
  226. return ret;
  227. invalid:
  228. ret = 0;
  229. goto out;
  230. }
  231. static int invalid_nodeid(u64 nodeid)
  232. {
  233. return !nodeid || nodeid == FUSE_ROOT_ID;
  234. }
  235. static int fuse_dentry_init(struct dentry *dentry)
  236. {
  237. dentry->d_fsdata = kzalloc(sizeof(union fuse_dentry), GFP_KERNEL);
  238. return dentry->d_fsdata ? 0 : -ENOMEM;
  239. }
  240. static void fuse_dentry_release(struct dentry *dentry)
  241. {
  242. union fuse_dentry *fd = dentry->d_fsdata;
  243. kfree_rcu(fd, rcu);
  244. }
  245. const struct dentry_operations fuse_dentry_operations = {
  246. .d_revalidate = fuse_dentry_revalidate,
  247. .d_init = fuse_dentry_init,
  248. .d_release = fuse_dentry_release,
  249. };
  250. const struct dentry_operations fuse_root_dentry_operations = {
  251. .d_init = fuse_dentry_init,
  252. .d_release = fuse_dentry_release,
  253. };
  254. int fuse_valid_type(int m)
  255. {
  256. return S_ISREG(m) || S_ISDIR(m) || S_ISLNK(m) || S_ISCHR(m) ||
  257. S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m);
  258. }
  259. bool fuse_invalid_attr(struct fuse_attr *attr)
  260. {
  261. return !fuse_valid_type(attr->mode) ||
  262. attr->size > LLONG_MAX;
  263. }
  264. int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
  265. struct fuse_entry_out *outarg, struct inode **inode)
  266. {
  267. struct fuse_conn *fc = get_fuse_conn_super(sb);
  268. FUSE_ARGS(args);
  269. struct fuse_forget_link *forget;
  270. u64 attr_version;
  271. int err;
  272. *inode = NULL;
  273. err = -ENAMETOOLONG;
  274. if (name->len > FUSE_NAME_MAX)
  275. goto out;
  276. forget = fuse_alloc_forget();
  277. err = -ENOMEM;
  278. if (!forget)
  279. goto out;
  280. attr_version = fuse_get_attr_version(fc);
  281. fuse_lookup_init(fc, &args, nodeid, name, outarg);
  282. err = fuse_simple_request(fc, &args);
  283. /* Zero nodeid is same as -ENOENT, but with valid timeout */
  284. if (err || !outarg->nodeid)
  285. goto out_put_forget;
  286. err = -EIO;
  287. if (!outarg->nodeid)
  288. goto out_put_forget;
  289. if (fuse_invalid_attr(&outarg->attr))
  290. goto out_put_forget;
  291. *inode = fuse_iget(sb, outarg->nodeid, outarg->generation,
  292. &outarg->attr, entry_attr_timeout(outarg),
  293. attr_version);
  294. err = -ENOMEM;
  295. if (!*inode) {
  296. fuse_queue_forget(fc, forget, outarg->nodeid, 1);
  297. goto out;
  298. }
  299. err = 0;
  300. out_put_forget:
  301. kfree(forget);
  302. out:
  303. return err;
  304. }
  305. static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
  306. unsigned int flags)
  307. {
  308. int err;
  309. struct fuse_entry_out outarg;
  310. struct inode *inode;
  311. struct dentry *newent;
  312. bool outarg_valid = true;
  313. bool locked;
  314. locked = fuse_lock_inode(dir);
  315. err = fuse_lookup_name(dir->i_sb, get_node_id(dir), &entry->d_name,
  316. &outarg, &inode);
  317. fuse_unlock_inode(dir, locked);
  318. if (err == -ENOENT) {
  319. outarg_valid = false;
  320. err = 0;
  321. }
  322. if (err)
  323. goto out_err;
  324. err = -EIO;
  325. if (inode && get_node_id(inode) == FUSE_ROOT_ID)
  326. goto out_iput;
  327. newent = d_splice_alias(inode, entry);
  328. err = PTR_ERR(newent);
  329. if (IS_ERR(newent))
  330. goto out_err;
  331. entry = newent ? newent : entry;
  332. if (outarg_valid)
  333. fuse_change_entry_timeout(entry, &outarg);
  334. else
  335. fuse_invalidate_entry_cache(entry);
  336. fuse_advise_use_readdirplus(dir);
  337. return newent;
  338. out_iput:
  339. iput(inode);
  340. out_err:
  341. return ERR_PTR(err);
  342. }
  343. /*
  344. * Atomic create+open operation
  345. *
  346. * If the filesystem doesn't support this, then fall back to separate
  347. * 'mknod' + 'open' requests.
  348. */
  349. static int fuse_create_open(struct inode *dir, struct dentry *entry,
  350. struct file *file, unsigned flags,
  351. umode_t mode)
  352. {
  353. int err;
  354. struct inode *inode;
  355. struct fuse_conn *fc = get_fuse_conn(dir);
  356. FUSE_ARGS(args);
  357. struct fuse_forget_link *forget;
  358. struct fuse_create_in inarg;
  359. struct fuse_open_out outopen;
  360. struct fuse_entry_out outentry;
  361. struct fuse_file *ff;
  362. /* Userspace expects S_IFREG in create mode */
  363. BUG_ON((mode & S_IFMT) != S_IFREG);
  364. forget = fuse_alloc_forget();
  365. err = -ENOMEM;
  366. if (!forget)
  367. goto out_err;
  368. err = -ENOMEM;
  369. ff = fuse_file_alloc(fc);
  370. if (!ff)
  371. goto out_put_forget_req;
  372. if (!fc->dont_mask)
  373. mode &= ~current_umask();
  374. flags &= ~O_NOCTTY;
  375. memset(&inarg, 0, sizeof(inarg));
  376. memset(&outentry, 0, sizeof(outentry));
  377. inarg.flags = flags;
  378. inarg.mode = mode;
  379. inarg.umask = current_umask();
  380. args.in.h.opcode = FUSE_CREATE;
  381. args.in.h.nodeid = get_node_id(dir);
  382. args.in.numargs = 2;
  383. args.in.args[0].size = sizeof(inarg);
  384. args.in.args[0].value = &inarg;
  385. args.in.args[1].size = entry->d_name.len + 1;
  386. args.in.args[1].value = entry->d_name.name;
  387. args.out.numargs = 2;
  388. args.out.args[0].size = sizeof(outentry);
  389. args.out.args[0].value = &outentry;
  390. args.out.args[1].size = sizeof(outopen);
  391. args.out.args[1].value = &outopen;
  392. err = fuse_simple_request(fc, &args);
  393. if (err)
  394. goto out_free_ff;
  395. err = -EIO;
  396. if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid) ||
  397. fuse_invalid_attr(&outentry.attr))
  398. goto out_free_ff;
  399. ff->fh = outopen.fh;
  400. ff->nodeid = outentry.nodeid;
  401. ff->open_flags = outopen.open_flags;
  402. inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
  403. &outentry.attr, entry_attr_timeout(&outentry), 0);
  404. if (!inode) {
  405. flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
  406. fuse_sync_release(ff, flags);
  407. fuse_queue_forget(fc, forget, outentry.nodeid, 1);
  408. err = -ENOMEM;
  409. goto out_err;
  410. }
  411. kfree(forget);
  412. d_instantiate(entry, inode);
  413. fuse_change_entry_timeout(entry, &outentry);
  414. fuse_invalidate_attr(dir);
  415. err = finish_open(file, entry, generic_file_open);
  416. if (err) {
  417. fuse_sync_release(ff, flags);
  418. } else {
  419. file->private_data = ff;
  420. fuse_finish_open(inode, file);
  421. }
  422. return err;
  423. out_free_ff:
  424. fuse_file_free(ff);
  425. out_put_forget_req:
  426. kfree(forget);
  427. out_err:
  428. return err;
  429. }
  430. static int fuse_mknod(struct inode *, struct dentry *, umode_t, dev_t);
  431. static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
  432. struct file *file, unsigned flags,
  433. umode_t mode)
  434. {
  435. int err;
  436. struct fuse_conn *fc = get_fuse_conn(dir);
  437. struct dentry *res = NULL;
  438. if (d_in_lookup(entry)) {
  439. res = fuse_lookup(dir, entry, 0);
  440. if (IS_ERR(res))
  441. return PTR_ERR(res);
  442. if (res)
  443. entry = res;
  444. }
  445. if (!(flags & O_CREAT) || d_really_is_positive(entry))
  446. goto no_open;
  447. /* Only creates */
  448. file->f_mode |= FMODE_CREATED;
  449. if (fc->no_create)
  450. goto mknod;
  451. err = fuse_create_open(dir, entry, file, flags, mode);
  452. if (err == -ENOSYS) {
  453. fc->no_create = 1;
  454. goto mknod;
  455. }
  456. out_dput:
  457. dput(res);
  458. return err;
  459. mknod:
  460. err = fuse_mknod(dir, entry, mode, 0);
  461. if (err)
  462. goto out_dput;
  463. no_open:
  464. return finish_no_open(file, res);
  465. }
  466. /*
  467. * Code shared between mknod, mkdir, symlink and link
  468. */
  469. static int create_new_entry(struct fuse_conn *fc, struct fuse_args *args,
  470. struct inode *dir, struct dentry *entry,
  471. umode_t mode)
  472. {
  473. struct fuse_entry_out outarg;
  474. struct inode *inode;
  475. struct dentry *d;
  476. int err;
  477. struct fuse_forget_link *forget;
  478. forget = fuse_alloc_forget();
  479. if (!forget)
  480. return -ENOMEM;
  481. memset(&outarg, 0, sizeof(outarg));
  482. args->in.h.nodeid = get_node_id(dir);
  483. args->out.numargs = 1;
  484. args->out.args[0].size = sizeof(outarg);
  485. args->out.args[0].value = &outarg;
  486. err = fuse_simple_request(fc, args);
  487. if (err)
  488. goto out_put_forget_req;
  489. err = -EIO;
  490. if (invalid_nodeid(outarg.nodeid) || fuse_invalid_attr(&outarg.attr))
  491. goto out_put_forget_req;
  492. if ((outarg.attr.mode ^ mode) & S_IFMT)
  493. goto out_put_forget_req;
  494. inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
  495. &outarg.attr, entry_attr_timeout(&outarg), 0);
  496. if (!inode) {
  497. fuse_queue_forget(fc, forget, outarg.nodeid, 1);
  498. return -ENOMEM;
  499. }
  500. kfree(forget);
  501. d_drop(entry);
  502. d = d_splice_alias(inode, entry);
  503. if (IS_ERR(d))
  504. return PTR_ERR(d);
  505. if (d) {
  506. fuse_change_entry_timeout(d, &outarg);
  507. dput(d);
  508. } else {
  509. fuse_change_entry_timeout(entry, &outarg);
  510. }
  511. fuse_invalidate_attr(dir);
  512. return 0;
  513. out_put_forget_req:
  514. kfree(forget);
  515. return err;
  516. }
  517. static int fuse_mknod(struct inode *dir, struct dentry *entry, umode_t mode,
  518. dev_t rdev)
  519. {
  520. struct fuse_mknod_in inarg;
  521. struct fuse_conn *fc = get_fuse_conn(dir);
  522. FUSE_ARGS(args);
  523. if (!fc->dont_mask)
  524. mode &= ~current_umask();
  525. memset(&inarg, 0, sizeof(inarg));
  526. inarg.mode = mode;
  527. inarg.rdev = new_encode_dev(rdev);
  528. inarg.umask = current_umask();
  529. args.in.h.opcode = FUSE_MKNOD;
  530. args.in.numargs = 2;
  531. args.in.args[0].size = sizeof(inarg);
  532. args.in.args[0].value = &inarg;
  533. args.in.args[1].size = entry->d_name.len + 1;
  534. args.in.args[1].value = entry->d_name.name;
  535. return create_new_entry(fc, &args, dir, entry, mode);
  536. }
  537. static int fuse_create(struct inode *dir, struct dentry *entry, umode_t mode,
  538. bool excl)
  539. {
  540. return fuse_mknod(dir, entry, mode, 0);
  541. }
  542. static int fuse_mkdir(struct inode *dir, struct dentry *entry, umode_t mode)
  543. {
  544. struct fuse_mkdir_in inarg;
  545. struct fuse_conn *fc = get_fuse_conn(dir);
  546. FUSE_ARGS(args);
  547. if (!fc->dont_mask)
  548. mode &= ~current_umask();
  549. memset(&inarg, 0, sizeof(inarg));
  550. inarg.mode = mode;
  551. inarg.umask = current_umask();
  552. args.in.h.opcode = FUSE_MKDIR;
  553. args.in.numargs = 2;
  554. args.in.args[0].size = sizeof(inarg);
  555. args.in.args[0].value = &inarg;
  556. args.in.args[1].size = entry->d_name.len + 1;
  557. args.in.args[1].value = entry->d_name.name;
  558. return create_new_entry(fc, &args, dir, entry, S_IFDIR);
  559. }
  560. static int fuse_symlink(struct inode *dir, struct dentry *entry,
  561. const char *link)
  562. {
  563. struct fuse_conn *fc = get_fuse_conn(dir);
  564. unsigned len = strlen(link) + 1;
  565. FUSE_ARGS(args);
  566. args.in.h.opcode = FUSE_SYMLINK;
  567. args.in.numargs = 2;
  568. args.in.args[0].size = entry->d_name.len + 1;
  569. args.in.args[0].value = entry->d_name.name;
  570. args.in.args[1].size = len;
  571. args.in.args[1].value = link;
  572. return create_new_entry(fc, &args, dir, entry, S_IFLNK);
  573. }
  574. void fuse_update_ctime(struct inode *inode)
  575. {
  576. if (!IS_NOCMTIME(inode)) {
  577. inode->i_ctime = current_time(inode);
  578. mark_inode_dirty_sync(inode);
  579. }
  580. }
  581. static int fuse_unlink(struct inode *dir, struct dentry *entry)
  582. {
  583. int err;
  584. struct fuse_conn *fc = get_fuse_conn(dir);
  585. FUSE_ARGS(args);
  586. args.in.h.opcode = FUSE_UNLINK;
  587. args.in.h.nodeid = get_node_id(dir);
  588. args.in.numargs = 1;
  589. args.in.args[0].size = entry->d_name.len + 1;
  590. args.in.args[0].value = entry->d_name.name;
  591. err = fuse_simple_request(fc, &args);
  592. if (!err) {
  593. struct inode *inode = d_inode(entry);
  594. struct fuse_inode *fi = get_fuse_inode(inode);
  595. spin_lock(&fc->lock);
  596. fi->attr_version = ++fc->attr_version;
  597. /*
  598. * If i_nlink == 0 then unlink doesn't make sense, yet this can
  599. * happen if userspace filesystem is careless. It would be
  600. * difficult to enforce correct nlink usage so just ignore this
  601. * condition here
  602. */
  603. if (inode->i_nlink > 0)
  604. drop_nlink(inode);
  605. spin_unlock(&fc->lock);
  606. fuse_invalidate_attr(inode);
  607. fuse_invalidate_attr(dir);
  608. fuse_invalidate_entry_cache(entry);
  609. fuse_update_ctime(inode);
  610. } else if (err == -EINTR)
  611. fuse_invalidate_entry(entry);
  612. return err;
  613. }
  614. static int fuse_rmdir(struct inode *dir, struct dentry *entry)
  615. {
  616. int err;
  617. struct fuse_conn *fc = get_fuse_conn(dir);
  618. FUSE_ARGS(args);
  619. args.in.h.opcode = FUSE_RMDIR;
  620. args.in.h.nodeid = get_node_id(dir);
  621. args.in.numargs = 1;
  622. args.in.args[0].size = entry->d_name.len + 1;
  623. args.in.args[0].value = entry->d_name.name;
  624. err = fuse_simple_request(fc, &args);
  625. if (!err) {
  626. clear_nlink(d_inode(entry));
  627. fuse_invalidate_attr(dir);
  628. fuse_invalidate_entry_cache(entry);
  629. } else if (err == -EINTR)
  630. fuse_invalidate_entry(entry);
  631. return err;
  632. }
  633. static int fuse_rename_common(struct inode *olddir, struct dentry *oldent,
  634. struct inode *newdir, struct dentry *newent,
  635. unsigned int flags, int opcode, size_t argsize)
  636. {
  637. int err;
  638. struct fuse_rename2_in inarg;
  639. struct fuse_conn *fc = get_fuse_conn(olddir);
  640. FUSE_ARGS(args);
  641. memset(&inarg, 0, argsize);
  642. inarg.newdir = get_node_id(newdir);
  643. inarg.flags = flags;
  644. args.in.h.opcode = opcode;
  645. args.in.h.nodeid = get_node_id(olddir);
  646. args.in.numargs = 3;
  647. args.in.args[0].size = argsize;
  648. args.in.args[0].value = &inarg;
  649. args.in.args[1].size = oldent->d_name.len + 1;
  650. args.in.args[1].value = oldent->d_name.name;
  651. args.in.args[2].size = newent->d_name.len + 1;
  652. args.in.args[2].value = newent->d_name.name;
  653. err = fuse_simple_request(fc, &args);
  654. if (!err) {
  655. /* ctime changes */
  656. fuse_invalidate_attr(d_inode(oldent));
  657. fuse_update_ctime(d_inode(oldent));
  658. if (flags & RENAME_EXCHANGE) {
  659. fuse_invalidate_attr(d_inode(newent));
  660. fuse_update_ctime(d_inode(newent));
  661. }
  662. fuse_invalidate_attr(olddir);
  663. if (olddir != newdir)
  664. fuse_invalidate_attr(newdir);
  665. /* newent will end up negative */
  666. if (!(flags & RENAME_EXCHANGE) && d_really_is_positive(newent)) {
  667. fuse_invalidate_attr(d_inode(newent));
  668. fuse_invalidate_entry_cache(newent);
  669. fuse_update_ctime(d_inode(newent));
  670. }
  671. } else if (err == -EINTR) {
  672. /* If request was interrupted, DEITY only knows if the
  673. rename actually took place. If the invalidation
  674. fails (e.g. some process has CWD under the renamed
  675. directory), then there can be inconsistency between
  676. the dcache and the real filesystem. Tough luck. */
  677. fuse_invalidate_entry(oldent);
  678. if (d_really_is_positive(newent))
  679. fuse_invalidate_entry(newent);
  680. }
  681. return err;
  682. }
  683. static int fuse_rename2(struct inode *olddir, struct dentry *oldent,
  684. struct inode *newdir, struct dentry *newent,
  685. unsigned int flags)
  686. {
  687. struct fuse_conn *fc = get_fuse_conn(olddir);
  688. int err;
  689. if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE))
  690. return -EINVAL;
  691. if (flags) {
  692. if (fc->no_rename2 || fc->minor < 23)
  693. return -EINVAL;
  694. err = fuse_rename_common(olddir, oldent, newdir, newent, flags,
  695. FUSE_RENAME2,
  696. sizeof(struct fuse_rename2_in));
  697. if (err == -ENOSYS) {
  698. fc->no_rename2 = 1;
  699. err = -EINVAL;
  700. }
  701. } else {
  702. err = fuse_rename_common(olddir, oldent, newdir, newent, 0,
  703. FUSE_RENAME,
  704. sizeof(struct fuse_rename_in));
  705. }
  706. return err;
  707. }
  708. static int fuse_link(struct dentry *entry, struct inode *newdir,
  709. struct dentry *newent)
  710. {
  711. int err;
  712. struct fuse_link_in inarg;
  713. struct inode *inode = d_inode(entry);
  714. struct fuse_conn *fc = get_fuse_conn(inode);
  715. FUSE_ARGS(args);
  716. memset(&inarg, 0, sizeof(inarg));
  717. inarg.oldnodeid = get_node_id(inode);
  718. args.in.h.opcode = FUSE_LINK;
  719. args.in.numargs = 2;
  720. args.in.args[0].size = sizeof(inarg);
  721. args.in.args[0].value = &inarg;
  722. args.in.args[1].size = newent->d_name.len + 1;
  723. args.in.args[1].value = newent->d_name.name;
  724. err = create_new_entry(fc, &args, newdir, newent, inode->i_mode);
  725. /* Contrary to "normal" filesystems it can happen that link
  726. makes two "logical" inodes point to the same "physical"
  727. inode. We invalidate the attributes of the old one, so it
  728. will reflect changes in the backing inode (link count,
  729. etc.)
  730. */
  731. if (!err) {
  732. struct fuse_inode *fi = get_fuse_inode(inode);
  733. spin_lock(&fc->lock);
  734. fi->attr_version = ++fc->attr_version;
  735. if (likely(inode->i_nlink < UINT_MAX))
  736. inc_nlink(inode);
  737. spin_unlock(&fc->lock);
  738. fuse_invalidate_attr(inode);
  739. fuse_update_ctime(inode);
  740. } else if (err == -EINTR) {
  741. fuse_invalidate_attr(inode);
  742. }
  743. return err;
  744. }
  745. static void fuse_fillattr(struct inode *inode, struct fuse_attr *attr,
  746. struct kstat *stat)
  747. {
  748. unsigned int blkbits;
  749. struct fuse_conn *fc = get_fuse_conn(inode);
  750. /* see the comment in fuse_change_attributes() */
  751. if (fc->writeback_cache && S_ISREG(inode->i_mode)) {
  752. attr->size = i_size_read(inode);
  753. attr->mtime = inode->i_mtime.tv_sec;
  754. attr->mtimensec = inode->i_mtime.tv_nsec;
  755. attr->ctime = inode->i_ctime.tv_sec;
  756. attr->ctimensec = inode->i_ctime.tv_nsec;
  757. }
  758. stat->dev = inode->i_sb->s_dev;
  759. stat->ino = attr->ino;
  760. stat->mode = (inode->i_mode & S_IFMT) | (attr->mode & 07777);
  761. stat->nlink = attr->nlink;
  762. stat->uid = make_kuid(fc->user_ns, attr->uid);
  763. stat->gid = make_kgid(fc->user_ns, attr->gid);
  764. stat->rdev = inode->i_rdev;
  765. stat->atime.tv_sec = attr->atime;
  766. stat->atime.tv_nsec = attr->atimensec;
  767. stat->mtime.tv_sec = attr->mtime;
  768. stat->mtime.tv_nsec = attr->mtimensec;
  769. stat->ctime.tv_sec = attr->ctime;
  770. stat->ctime.tv_nsec = attr->ctimensec;
  771. stat->size = attr->size;
  772. stat->blocks = attr->blocks;
  773. if (attr->blksize != 0)
  774. blkbits = ilog2(attr->blksize);
  775. else
  776. blkbits = inode->i_sb->s_blocksize_bits;
  777. stat->blksize = 1 << blkbits;
  778. }
  779. static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
  780. struct file *file)
  781. {
  782. int err;
  783. struct fuse_getattr_in inarg;
  784. struct fuse_attr_out outarg;
  785. struct fuse_conn *fc = get_fuse_conn(inode);
  786. FUSE_ARGS(args);
  787. u64 attr_version;
  788. attr_version = fuse_get_attr_version(fc);
  789. memset(&inarg, 0, sizeof(inarg));
  790. memset(&outarg, 0, sizeof(outarg));
  791. /* Directories have separate file-handle space */
  792. if (file && S_ISREG(inode->i_mode)) {
  793. struct fuse_file *ff = file->private_data;
  794. inarg.getattr_flags |= FUSE_GETATTR_FH;
  795. inarg.fh = ff->fh;
  796. }
  797. args.in.h.opcode = FUSE_GETATTR;
  798. args.in.h.nodeid = get_node_id(inode);
  799. args.in.numargs = 1;
  800. args.in.args[0].size = sizeof(inarg);
  801. args.in.args[0].value = &inarg;
  802. args.out.numargs = 1;
  803. args.out.args[0].size = sizeof(outarg);
  804. args.out.args[0].value = &outarg;
  805. err = fuse_simple_request(fc, &args);
  806. if (!err) {
  807. if (fuse_invalid_attr(&outarg.attr) ||
  808. (inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
  809. make_bad_inode(inode);
  810. err = -EIO;
  811. } else {
  812. fuse_change_attributes(inode, &outarg.attr,
  813. attr_timeout(&outarg),
  814. attr_version);
  815. if (stat)
  816. fuse_fillattr(inode, &outarg.attr, stat);
  817. }
  818. }
  819. return err;
  820. }
  821. static int fuse_update_get_attr(struct inode *inode, struct file *file,
  822. struct kstat *stat, unsigned int flags)
  823. {
  824. struct fuse_inode *fi = get_fuse_inode(inode);
  825. int err = 0;
  826. bool sync;
  827. if (flags & AT_STATX_FORCE_SYNC)
  828. sync = true;
  829. else if (flags & AT_STATX_DONT_SYNC)
  830. sync = false;
  831. else
  832. sync = time_before64(fi->i_time, get_jiffies_64());
  833. if (sync) {
  834. forget_all_cached_acls(inode);
  835. err = fuse_do_getattr(inode, stat, file);
  836. } else if (stat) {
  837. generic_fillattr(inode, stat);
  838. stat->mode = fi->orig_i_mode;
  839. stat->ino = fi->orig_ino;
  840. }
  841. return err;
  842. }
  843. int fuse_update_attributes(struct inode *inode, struct file *file)
  844. {
  845. return fuse_update_get_attr(inode, file, NULL, 0);
  846. }
  847. int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
  848. u64 child_nodeid, struct qstr *name)
  849. {
  850. int err = -ENOTDIR;
  851. struct inode *parent;
  852. struct dentry *dir;
  853. struct dentry *entry;
  854. parent = ilookup5(sb, parent_nodeid, fuse_inode_eq, &parent_nodeid);
  855. if (!parent)
  856. return -ENOENT;
  857. inode_lock(parent);
  858. if (!S_ISDIR(parent->i_mode))
  859. goto unlock;
  860. err = -ENOENT;
  861. dir = d_find_alias(parent);
  862. if (!dir)
  863. goto unlock;
  864. name->hash = full_name_hash(dir, name->name, name->len);
  865. entry = d_lookup(dir, name);
  866. dput(dir);
  867. if (!entry)
  868. goto unlock;
  869. fuse_invalidate_attr(parent);
  870. fuse_invalidate_entry(entry);
  871. if (child_nodeid != 0 && d_really_is_positive(entry)) {
  872. inode_lock(d_inode(entry));
  873. if (get_node_id(d_inode(entry)) != child_nodeid) {
  874. err = -ENOENT;
  875. goto badentry;
  876. }
  877. if (d_mountpoint(entry)) {
  878. err = -EBUSY;
  879. goto badentry;
  880. }
  881. if (d_is_dir(entry)) {
  882. shrink_dcache_parent(entry);
  883. if (!simple_empty(entry)) {
  884. err = -ENOTEMPTY;
  885. goto badentry;
  886. }
  887. d_inode(entry)->i_flags |= S_DEAD;
  888. }
  889. dont_mount(entry);
  890. clear_nlink(d_inode(entry));
  891. err = 0;
  892. badentry:
  893. inode_unlock(d_inode(entry));
  894. if (!err)
  895. d_delete(entry);
  896. } else {
  897. err = 0;
  898. }
  899. dput(entry);
  900. unlock:
  901. inode_unlock(parent);
  902. iput(parent);
  903. return err;
  904. }
  905. /*
  906. * Calling into a user-controlled filesystem gives the filesystem
  907. * daemon ptrace-like capabilities over the current process. This
  908. * means, that the filesystem daemon is able to record the exact
  909. * filesystem operations performed, and can also control the behavior
  910. * of the requester process in otherwise impossible ways. For example
  911. * it can delay the operation for arbitrary length of time allowing
  912. * DoS against the requester.
  913. *
  914. * For this reason only those processes can call into the filesystem,
  915. * for which the owner of the mount has ptrace privilege. This
  916. * excludes processes started by other users, suid or sgid processes.
  917. */
  918. int fuse_allow_current_process(struct fuse_conn *fc)
  919. {
  920. const struct cred *cred;
  921. if (fc->allow_other)
  922. return current_in_userns(fc->user_ns);
  923. cred = current_cred();
  924. if (uid_eq(cred->euid, fc->user_id) &&
  925. uid_eq(cred->suid, fc->user_id) &&
  926. uid_eq(cred->uid, fc->user_id) &&
  927. gid_eq(cred->egid, fc->group_id) &&
  928. gid_eq(cred->sgid, fc->group_id) &&
  929. gid_eq(cred->gid, fc->group_id))
  930. return 1;
  931. return 0;
  932. }
  933. static int fuse_access(struct inode *inode, int mask)
  934. {
  935. struct fuse_conn *fc = get_fuse_conn(inode);
  936. FUSE_ARGS(args);
  937. struct fuse_access_in inarg;
  938. int err;
  939. BUG_ON(mask & MAY_NOT_BLOCK);
  940. if (fc->no_access)
  941. return 0;
  942. memset(&inarg, 0, sizeof(inarg));
  943. inarg.mask = mask & (MAY_READ | MAY_WRITE | MAY_EXEC);
  944. args.in.h.opcode = FUSE_ACCESS;
  945. args.in.h.nodeid = get_node_id(inode);
  946. args.in.numargs = 1;
  947. args.in.args[0].size = sizeof(inarg);
  948. args.in.args[0].value = &inarg;
  949. err = fuse_simple_request(fc, &args);
  950. if (err == -ENOSYS) {
  951. fc->no_access = 1;
  952. err = 0;
  953. }
  954. return err;
  955. }
  956. static int fuse_perm_getattr(struct inode *inode, int mask)
  957. {
  958. if (mask & MAY_NOT_BLOCK)
  959. return -ECHILD;
  960. forget_all_cached_acls(inode);
  961. return fuse_do_getattr(inode, NULL, NULL);
  962. }
  963. /*
  964. * Check permission. The two basic access models of FUSE are:
  965. *
  966. * 1) Local access checking ('default_permissions' mount option) based
  967. * on file mode. This is the plain old disk filesystem permission
  968. * modell.
  969. *
  970. * 2) "Remote" access checking, where server is responsible for
  971. * checking permission in each inode operation. An exception to this
  972. * is if ->permission() was invoked from sys_access() in which case an
  973. * access request is sent. Execute permission is still checked
  974. * locally based on file mode.
  975. */
  976. static int fuse_permission(struct inode *inode, int mask)
  977. {
  978. struct fuse_conn *fc = get_fuse_conn(inode);
  979. bool refreshed = false;
  980. int err = 0;
  981. if (!fuse_allow_current_process(fc))
  982. return -EACCES;
  983. /*
  984. * If attributes are needed, refresh them before proceeding
  985. */
  986. if (fc->default_permissions ||
  987. ((mask & MAY_EXEC) && S_ISREG(inode->i_mode))) {
  988. struct fuse_inode *fi = get_fuse_inode(inode);
  989. if (time_before64(fi->i_time, get_jiffies_64())) {
  990. refreshed = true;
  991. err = fuse_perm_getattr(inode, mask);
  992. if (err)
  993. return err;
  994. }
  995. }
  996. if (fc->default_permissions) {
  997. err = generic_permission(inode, mask);
  998. /* If permission is denied, try to refresh file
  999. attributes. This is also needed, because the root
  1000. node will at first have no permissions */
  1001. if (err == -EACCES && !refreshed) {
  1002. err = fuse_perm_getattr(inode, mask);
  1003. if (!err)
  1004. err = generic_permission(inode, mask);
  1005. }
  1006. /* Note: the opposite of the above test does not
  1007. exist. So if permissions are revoked this won't be
  1008. noticed immediately, only after the attribute
  1009. timeout has expired */
  1010. } else if (mask & (MAY_ACCESS | MAY_CHDIR)) {
  1011. err = fuse_access(inode, mask);
  1012. } else if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode)) {
  1013. if (!(inode->i_mode & S_IXUGO)) {
  1014. if (refreshed)
  1015. return -EACCES;
  1016. err = fuse_perm_getattr(inode, mask);
  1017. if (!err && !(inode->i_mode & S_IXUGO))
  1018. return -EACCES;
  1019. }
  1020. }
  1021. return err;
  1022. }
  1023. static int parse_dirfile(char *buf, size_t nbytes, struct file *file,
  1024. struct dir_context *ctx)
  1025. {
  1026. while (nbytes >= FUSE_NAME_OFFSET) {
  1027. struct fuse_dirent *dirent = (struct fuse_dirent *) buf;
  1028. size_t reclen = FUSE_DIRENT_SIZE(dirent);
  1029. if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX)
  1030. return -EIO;
  1031. if (reclen > nbytes)
  1032. break;
  1033. if (memchr(dirent->name, '/', dirent->namelen) != NULL)
  1034. return -EIO;
  1035. if (!dir_emit(ctx, dirent->name, dirent->namelen,
  1036. dirent->ino, dirent->type))
  1037. break;
  1038. buf += reclen;
  1039. nbytes -= reclen;
  1040. ctx->pos = dirent->off;
  1041. }
  1042. return 0;
  1043. }
  1044. static int fuse_direntplus_link(struct file *file,
  1045. struct fuse_direntplus *direntplus,
  1046. u64 attr_version)
  1047. {
  1048. struct fuse_entry_out *o = &direntplus->entry_out;
  1049. struct fuse_dirent *dirent = &direntplus->dirent;
  1050. struct dentry *parent = file->f_path.dentry;
  1051. struct qstr name = QSTR_INIT(dirent->name, dirent->namelen);
  1052. struct dentry *dentry;
  1053. struct dentry *alias;
  1054. struct inode *dir = d_inode(parent);
  1055. struct fuse_conn *fc;
  1056. struct inode *inode;
  1057. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
  1058. if (!o->nodeid) {
  1059. /*
  1060. * Unlike in the case of fuse_lookup, zero nodeid does not mean
  1061. * ENOENT. Instead, it only means the userspace filesystem did
  1062. * not want to return attributes/handle for this entry.
  1063. *
  1064. * So do nothing.
  1065. */
  1066. return 0;
  1067. }
  1068. if (name.name[0] == '.') {
  1069. /*
  1070. * We could potentially refresh the attributes of the directory
  1071. * and its parent?
  1072. */
  1073. if (name.len == 1)
  1074. return 0;
  1075. if (name.name[1] == '.' && name.len == 2)
  1076. return 0;
  1077. }
  1078. if (invalid_nodeid(o->nodeid))
  1079. return -EIO;
  1080. if (fuse_invalid_attr(&o->attr))
  1081. return -EIO;
  1082. fc = get_fuse_conn(dir);
  1083. name.hash = full_name_hash(parent, name.name, name.len);
  1084. dentry = d_lookup(parent, &name);
  1085. if (!dentry) {
  1086. retry:
  1087. dentry = d_alloc_parallel(parent, &name, &wq);
  1088. if (IS_ERR(dentry))
  1089. return PTR_ERR(dentry);
  1090. }
  1091. if (!d_in_lookup(dentry)) {
  1092. struct fuse_inode *fi;
  1093. inode = d_inode(dentry);
  1094. if (!inode ||
  1095. get_node_id(inode) != o->nodeid ||
  1096. ((o->attr.mode ^ inode->i_mode) & S_IFMT)) {
  1097. d_invalidate(dentry);
  1098. dput(dentry);
  1099. goto retry;
  1100. }
  1101. if (is_bad_inode(inode)) {
  1102. dput(dentry);
  1103. return -EIO;
  1104. }
  1105. fi = get_fuse_inode(inode);
  1106. spin_lock(&fc->lock);
  1107. fi->nlookup++;
  1108. spin_unlock(&fc->lock);
  1109. forget_all_cached_acls(inode);
  1110. fuse_change_attributes(inode, &o->attr,
  1111. entry_attr_timeout(o),
  1112. attr_version);
  1113. /*
  1114. * The other branch comes via fuse_iget()
  1115. * which bumps nlookup inside
  1116. */
  1117. } else {
  1118. inode = fuse_iget(dir->i_sb, o->nodeid, o->generation,
  1119. &o->attr, entry_attr_timeout(o),
  1120. attr_version);
  1121. if (!inode)
  1122. inode = ERR_PTR(-ENOMEM);
  1123. alias = d_splice_alias(inode, dentry);
  1124. d_lookup_done(dentry);
  1125. if (alias) {
  1126. dput(dentry);
  1127. dentry = alias;
  1128. }
  1129. if (IS_ERR(dentry))
  1130. return PTR_ERR(dentry);
  1131. }
  1132. if (fc->readdirplus_auto)
  1133. set_bit(FUSE_I_INIT_RDPLUS, &get_fuse_inode(inode)->state);
  1134. fuse_change_entry_timeout(dentry, o);
  1135. dput(dentry);
  1136. return 0;
  1137. }
  1138. static int parse_dirplusfile(char *buf, size_t nbytes, struct file *file,
  1139. struct dir_context *ctx, u64 attr_version)
  1140. {
  1141. struct fuse_direntplus *direntplus;
  1142. struct fuse_dirent *dirent;
  1143. size_t reclen;
  1144. int over = 0;
  1145. int ret;
  1146. while (nbytes >= FUSE_NAME_OFFSET_DIRENTPLUS) {
  1147. direntplus = (struct fuse_direntplus *) buf;
  1148. dirent = &direntplus->dirent;
  1149. reclen = FUSE_DIRENTPLUS_SIZE(direntplus);
  1150. if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX)
  1151. return -EIO;
  1152. if (reclen > nbytes)
  1153. break;
  1154. if (memchr(dirent->name, '/', dirent->namelen) != NULL)
  1155. return -EIO;
  1156. if (!over) {
  1157. /* We fill entries into dstbuf only as much as
  1158. it can hold. But we still continue iterating
  1159. over remaining entries to link them. If not,
  1160. we need to send a FORGET for each of those
  1161. which we did not link.
  1162. */
  1163. over = !dir_emit(ctx, dirent->name, dirent->namelen,
  1164. dirent->ino, dirent->type);
  1165. if (!over)
  1166. ctx->pos = dirent->off;
  1167. }
  1168. buf += reclen;
  1169. nbytes -= reclen;
  1170. ret = fuse_direntplus_link(file, direntplus, attr_version);
  1171. if (ret)
  1172. fuse_force_forget(file, direntplus->entry_out.nodeid);
  1173. }
  1174. return 0;
  1175. }
  1176. static int fuse_readdir(struct file *file, struct dir_context *ctx)
  1177. {
  1178. int plus, err;
  1179. size_t nbytes;
  1180. struct page *page;
  1181. struct inode *inode = file_inode(file);
  1182. struct fuse_conn *fc = get_fuse_conn(inode);
  1183. struct fuse_req *req;
  1184. u64 attr_version = 0;
  1185. bool locked;
  1186. if (is_bad_inode(inode))
  1187. return -EIO;
  1188. req = fuse_get_req(fc, 1);
  1189. if (IS_ERR(req))
  1190. return PTR_ERR(req);
  1191. page = alloc_page(GFP_KERNEL);
  1192. if (!page) {
  1193. fuse_put_request(fc, req);
  1194. return -ENOMEM;
  1195. }
  1196. plus = fuse_use_readdirplus(inode, ctx);
  1197. req->out.argpages = 1;
  1198. req->num_pages = 1;
  1199. req->pages[0] = page;
  1200. req->page_descs[0].length = PAGE_SIZE;
  1201. if (plus) {
  1202. attr_version = fuse_get_attr_version(fc);
  1203. fuse_read_fill(req, file, ctx->pos, PAGE_SIZE,
  1204. FUSE_READDIRPLUS);
  1205. } else {
  1206. fuse_read_fill(req, file, ctx->pos, PAGE_SIZE,
  1207. FUSE_READDIR);
  1208. }
  1209. locked = fuse_lock_inode(inode);
  1210. fuse_request_send(fc, req);
  1211. fuse_unlock_inode(inode, locked);
  1212. nbytes = req->out.args[0].size;
  1213. err = req->out.h.error;
  1214. fuse_put_request(fc, req);
  1215. if (!err) {
  1216. if (plus) {
  1217. err = parse_dirplusfile(page_address(page), nbytes,
  1218. file, ctx,
  1219. attr_version);
  1220. } else {
  1221. err = parse_dirfile(page_address(page), nbytes, file,
  1222. ctx);
  1223. }
  1224. }
  1225. __free_page(page);
  1226. fuse_invalidate_atime(inode);
  1227. return err;
  1228. }
  1229. static const char *fuse_get_link(struct dentry *dentry,
  1230. struct inode *inode,
  1231. struct delayed_call *done)
  1232. {
  1233. struct fuse_conn *fc = get_fuse_conn(inode);
  1234. FUSE_ARGS(args);
  1235. char *link;
  1236. ssize_t ret;
  1237. if (!dentry)
  1238. return ERR_PTR(-ECHILD);
  1239. link = kmalloc(PAGE_SIZE, GFP_KERNEL);
  1240. if (!link)
  1241. return ERR_PTR(-ENOMEM);
  1242. args.in.h.opcode = FUSE_READLINK;
  1243. args.in.h.nodeid = get_node_id(inode);
  1244. args.out.argvar = 1;
  1245. args.out.numargs = 1;
  1246. args.out.args[0].size = PAGE_SIZE - 1;
  1247. args.out.args[0].value = link;
  1248. ret = fuse_simple_request(fc, &args);
  1249. if (ret < 0) {
  1250. kfree(link);
  1251. link = ERR_PTR(ret);
  1252. } else {
  1253. link[ret] = '\0';
  1254. set_delayed_call(done, kfree_link, link);
  1255. }
  1256. fuse_invalidate_atime(inode);
  1257. return link;
  1258. }
  1259. static int fuse_dir_open(struct inode *inode, struct file *file)
  1260. {
  1261. return fuse_open_common(inode, file, true);
  1262. }
  1263. static int fuse_dir_release(struct inode *inode, struct file *file)
  1264. {
  1265. fuse_release_common(file, true);
  1266. return 0;
  1267. }
  1268. static int fuse_dir_fsync(struct file *file, loff_t start, loff_t end,
  1269. int datasync)
  1270. {
  1271. return fuse_fsync_common(file, start, end, datasync, 1);
  1272. }
  1273. static long fuse_dir_ioctl(struct file *file, unsigned int cmd,
  1274. unsigned long arg)
  1275. {
  1276. struct fuse_conn *fc = get_fuse_conn(file->f_mapping->host);
  1277. /* FUSE_IOCTL_DIR only supported for API version >= 7.18 */
  1278. if (fc->minor < 18)
  1279. return -ENOTTY;
  1280. return fuse_ioctl_common(file, cmd, arg, FUSE_IOCTL_DIR);
  1281. }
  1282. static long fuse_dir_compat_ioctl(struct file *file, unsigned int cmd,
  1283. unsigned long arg)
  1284. {
  1285. struct fuse_conn *fc = get_fuse_conn(file->f_mapping->host);
  1286. if (fc->minor < 18)
  1287. return -ENOTTY;
  1288. return fuse_ioctl_common(file, cmd, arg,
  1289. FUSE_IOCTL_COMPAT | FUSE_IOCTL_DIR);
  1290. }
  1291. static bool update_mtime(unsigned ivalid, bool trust_local_mtime)
  1292. {
  1293. /* Always update if mtime is explicitly set */
  1294. if (ivalid & ATTR_MTIME_SET)
  1295. return true;
  1296. /* Or if kernel i_mtime is the official one */
  1297. if (trust_local_mtime)
  1298. return true;
  1299. /* If it's an open(O_TRUNC) or an ftruncate(), don't update */
  1300. if ((ivalid & ATTR_SIZE) && (ivalid & (ATTR_OPEN | ATTR_FILE)))
  1301. return false;
  1302. /* In all other cases update */
  1303. return true;
  1304. }
  1305. static void iattr_to_fattr(struct fuse_conn *fc, struct iattr *iattr,
  1306. struct fuse_setattr_in *arg, bool trust_local_cmtime)
  1307. {
  1308. unsigned ivalid = iattr->ia_valid;
  1309. if (ivalid & ATTR_MODE)
  1310. arg->valid |= FATTR_MODE, arg->mode = iattr->ia_mode;
  1311. if (ivalid & ATTR_UID)
  1312. arg->valid |= FATTR_UID, arg->uid = from_kuid(fc->user_ns, iattr->ia_uid);
  1313. if (ivalid & ATTR_GID)
  1314. arg->valid |= FATTR_GID, arg->gid = from_kgid(fc->user_ns, iattr->ia_gid);
  1315. if (ivalid & ATTR_SIZE)
  1316. arg->valid |= FATTR_SIZE, arg->size = iattr->ia_size;
  1317. if (ivalid & ATTR_ATIME) {
  1318. arg->valid |= FATTR_ATIME;
  1319. arg->atime = iattr->ia_atime.tv_sec;
  1320. arg->atimensec = iattr->ia_atime.tv_nsec;
  1321. if (!(ivalid & ATTR_ATIME_SET))
  1322. arg->valid |= FATTR_ATIME_NOW;
  1323. }
  1324. if ((ivalid & ATTR_MTIME) && update_mtime(ivalid, trust_local_cmtime)) {
  1325. arg->valid |= FATTR_MTIME;
  1326. arg->mtime = iattr->ia_mtime.tv_sec;
  1327. arg->mtimensec = iattr->ia_mtime.tv_nsec;
  1328. if (!(ivalid & ATTR_MTIME_SET) && !trust_local_cmtime)
  1329. arg->valid |= FATTR_MTIME_NOW;
  1330. }
  1331. if ((ivalid & ATTR_CTIME) && trust_local_cmtime) {
  1332. arg->valid |= FATTR_CTIME;
  1333. arg->ctime = iattr->ia_ctime.tv_sec;
  1334. arg->ctimensec = iattr->ia_ctime.tv_nsec;
  1335. }
  1336. }
  1337. /*
  1338. * Prevent concurrent writepages on inode
  1339. *
  1340. * This is done by adding a negative bias to the inode write counter
  1341. * and waiting for all pending writes to finish.
  1342. */
  1343. void fuse_set_nowrite(struct inode *inode)
  1344. {
  1345. struct fuse_conn *fc = get_fuse_conn(inode);
  1346. struct fuse_inode *fi = get_fuse_inode(inode);
  1347. BUG_ON(!inode_is_locked(inode));
  1348. spin_lock(&fc->lock);
  1349. BUG_ON(fi->writectr < 0);
  1350. fi->writectr += FUSE_NOWRITE;
  1351. spin_unlock(&fc->lock);
  1352. wait_event(fi->page_waitq, fi->writectr == FUSE_NOWRITE);
  1353. }
  1354. /*
  1355. * Allow writepages on inode
  1356. *
  1357. * Remove the bias from the writecounter and send any queued
  1358. * writepages.
  1359. */
  1360. static void __fuse_release_nowrite(struct inode *inode)
  1361. {
  1362. struct fuse_inode *fi = get_fuse_inode(inode);
  1363. BUG_ON(fi->writectr != FUSE_NOWRITE);
  1364. fi->writectr = 0;
  1365. fuse_flush_writepages(inode);
  1366. }
  1367. void fuse_release_nowrite(struct inode *inode)
  1368. {
  1369. struct fuse_conn *fc = get_fuse_conn(inode);
  1370. spin_lock(&fc->lock);
  1371. __fuse_release_nowrite(inode);
  1372. spin_unlock(&fc->lock);
  1373. }
  1374. static void fuse_setattr_fill(struct fuse_conn *fc, struct fuse_args *args,
  1375. struct inode *inode,
  1376. struct fuse_setattr_in *inarg_p,
  1377. struct fuse_attr_out *outarg_p)
  1378. {
  1379. args->in.h.opcode = FUSE_SETATTR;
  1380. args->in.h.nodeid = get_node_id(inode);
  1381. args->in.numargs = 1;
  1382. args->in.args[0].size = sizeof(*inarg_p);
  1383. args->in.args[0].value = inarg_p;
  1384. args->out.numargs = 1;
  1385. args->out.args[0].size = sizeof(*outarg_p);
  1386. args->out.args[0].value = outarg_p;
  1387. }
  1388. /*
  1389. * Flush inode->i_mtime to the server
  1390. */
  1391. int fuse_flush_times(struct inode *inode, struct fuse_file *ff)
  1392. {
  1393. struct fuse_conn *fc = get_fuse_conn(inode);
  1394. FUSE_ARGS(args);
  1395. struct fuse_setattr_in inarg;
  1396. struct fuse_attr_out outarg;
  1397. memset(&inarg, 0, sizeof(inarg));
  1398. memset(&outarg, 0, sizeof(outarg));
  1399. inarg.valid = FATTR_MTIME;
  1400. inarg.mtime = inode->i_mtime.tv_sec;
  1401. inarg.mtimensec = inode->i_mtime.tv_nsec;
  1402. if (fc->minor >= 23) {
  1403. inarg.valid |= FATTR_CTIME;
  1404. inarg.ctime = inode->i_ctime.tv_sec;
  1405. inarg.ctimensec = inode->i_ctime.tv_nsec;
  1406. }
  1407. if (ff) {
  1408. inarg.valid |= FATTR_FH;
  1409. inarg.fh = ff->fh;
  1410. }
  1411. fuse_setattr_fill(fc, &args, inode, &inarg, &outarg);
  1412. return fuse_simple_request(fc, &args);
  1413. }
  1414. /*
  1415. * Set attributes, and at the same time refresh them.
  1416. *
  1417. * Truncation is slightly complicated, because the 'truncate' request
  1418. * may fail, in which case we don't want to touch the mapping.
  1419. * vmtruncate() doesn't allow for this case, so do the rlimit checking
  1420. * and the actual truncation by hand.
  1421. */
  1422. int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
  1423. struct file *file)
  1424. {
  1425. struct inode *inode = d_inode(dentry);
  1426. struct fuse_conn *fc = get_fuse_conn(inode);
  1427. struct fuse_inode *fi = get_fuse_inode(inode);
  1428. FUSE_ARGS(args);
  1429. struct fuse_setattr_in inarg;
  1430. struct fuse_attr_out outarg;
  1431. bool is_truncate = false;
  1432. bool is_wb = fc->writeback_cache;
  1433. loff_t oldsize;
  1434. int err;
  1435. bool trust_local_cmtime = is_wb && S_ISREG(inode->i_mode);
  1436. if (!fc->default_permissions)
  1437. attr->ia_valid |= ATTR_FORCE;
  1438. err = setattr_prepare(dentry, attr);
  1439. if (err)
  1440. return err;
  1441. if (attr->ia_valid & ATTR_OPEN) {
  1442. /* This is coming from open(..., ... | O_TRUNC); */
  1443. WARN_ON(!(attr->ia_valid & ATTR_SIZE));
  1444. WARN_ON(attr->ia_size != 0);
  1445. if (fc->atomic_o_trunc) {
  1446. /*
  1447. * No need to send request to userspace, since actual
  1448. * truncation has already been done by OPEN. But still
  1449. * need to truncate page cache.
  1450. */
  1451. i_size_write(inode, 0);
  1452. truncate_pagecache(inode, 0);
  1453. return 0;
  1454. }
  1455. file = NULL;
  1456. }
  1457. if (attr->ia_valid & ATTR_SIZE)
  1458. is_truncate = true;
  1459. /* Flush dirty data/metadata before non-truncate SETATTR */
  1460. if (is_wb && S_ISREG(inode->i_mode) &&
  1461. attr->ia_valid &
  1462. (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_MTIME_SET |
  1463. ATTR_TIMES_SET)) {
  1464. err = write_inode_now(inode, true);
  1465. if (err)
  1466. return err;
  1467. fuse_set_nowrite(inode);
  1468. fuse_release_nowrite(inode);
  1469. }
  1470. if (is_truncate) {
  1471. fuse_set_nowrite(inode);
  1472. set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
  1473. if (trust_local_cmtime && attr->ia_size != inode->i_size)
  1474. attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
  1475. }
  1476. memset(&inarg, 0, sizeof(inarg));
  1477. memset(&outarg, 0, sizeof(outarg));
  1478. iattr_to_fattr(fc, attr, &inarg, trust_local_cmtime);
  1479. if (file) {
  1480. struct fuse_file *ff = file->private_data;
  1481. inarg.valid |= FATTR_FH;
  1482. inarg.fh = ff->fh;
  1483. }
  1484. if (attr->ia_valid & ATTR_SIZE) {
  1485. /* For mandatory locking in truncate */
  1486. inarg.valid |= FATTR_LOCKOWNER;
  1487. inarg.lock_owner = fuse_lock_owner_id(fc, current->files);
  1488. }
  1489. fuse_setattr_fill(fc, &args, inode, &inarg, &outarg);
  1490. err = fuse_simple_request(fc, &args);
  1491. if (err) {
  1492. if (err == -EINTR)
  1493. fuse_invalidate_attr(inode);
  1494. goto error;
  1495. }
  1496. if (fuse_invalid_attr(&outarg.attr) ||
  1497. (inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
  1498. make_bad_inode(inode);
  1499. err = -EIO;
  1500. goto error;
  1501. }
  1502. spin_lock(&fc->lock);
  1503. /* the kernel maintains i_mtime locally */
  1504. if (trust_local_cmtime) {
  1505. if (attr->ia_valid & ATTR_MTIME)
  1506. inode->i_mtime = attr->ia_mtime;
  1507. if (attr->ia_valid & ATTR_CTIME)
  1508. inode->i_ctime = attr->ia_ctime;
  1509. /* FIXME: clear I_DIRTY_SYNC? */
  1510. }
  1511. fuse_change_attributes_common(inode, &outarg.attr,
  1512. attr_timeout(&outarg));
  1513. oldsize = inode->i_size;
  1514. /* see the comment in fuse_change_attributes() */
  1515. if (!is_wb || is_truncate || !S_ISREG(inode->i_mode))
  1516. i_size_write(inode, outarg.attr.size);
  1517. if (is_truncate) {
  1518. /* NOTE: this may release/reacquire fc->lock */
  1519. __fuse_release_nowrite(inode);
  1520. }
  1521. spin_unlock(&fc->lock);
  1522. /*
  1523. * Only call invalidate_inode_pages2() after removing
  1524. * FUSE_NOWRITE, otherwise fuse_launder_page() would deadlock.
  1525. */
  1526. if ((is_truncate || !is_wb) &&
  1527. S_ISREG(inode->i_mode) && oldsize != outarg.attr.size) {
  1528. truncate_pagecache(inode, outarg.attr.size);
  1529. invalidate_inode_pages2(inode->i_mapping);
  1530. }
  1531. clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
  1532. return 0;
  1533. error:
  1534. if (is_truncate)
  1535. fuse_release_nowrite(inode);
  1536. clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
  1537. return err;
  1538. }
  1539. static int fuse_setattr(struct dentry *entry, struct iattr *attr)
  1540. {
  1541. struct inode *inode = d_inode(entry);
  1542. struct fuse_conn *fc = get_fuse_conn(inode);
  1543. struct file *file = (attr->ia_valid & ATTR_FILE) ? attr->ia_file : NULL;
  1544. int ret;
  1545. if (!fuse_allow_current_process(get_fuse_conn(inode)))
  1546. return -EACCES;
  1547. if (attr->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) {
  1548. attr->ia_valid &= ~(ATTR_KILL_SUID | ATTR_KILL_SGID |
  1549. ATTR_MODE);
  1550. /*
  1551. * The only sane way to reliably kill suid/sgid is to do it in
  1552. * the userspace filesystem
  1553. *
  1554. * This should be done on write(), truncate() and chown().
  1555. */
  1556. if (!fc->handle_killpriv) {
  1557. /*
  1558. * ia_mode calculation may have used stale i_mode.
  1559. * Refresh and recalculate.
  1560. */
  1561. ret = fuse_do_getattr(inode, NULL, file);
  1562. if (ret)
  1563. return ret;
  1564. attr->ia_mode = inode->i_mode;
  1565. if (inode->i_mode & S_ISUID) {
  1566. attr->ia_valid |= ATTR_MODE;
  1567. attr->ia_mode &= ~S_ISUID;
  1568. }
  1569. if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
  1570. attr->ia_valid |= ATTR_MODE;
  1571. attr->ia_mode &= ~S_ISGID;
  1572. }
  1573. }
  1574. }
  1575. if (!attr->ia_valid)
  1576. return 0;
  1577. ret = fuse_do_setattr(entry, attr, file);
  1578. if (!ret) {
  1579. /*
  1580. * If filesystem supports acls it may have updated acl xattrs in
  1581. * the filesystem, so forget cached acls for the inode.
  1582. */
  1583. if (fc->posix_acl)
  1584. forget_all_cached_acls(inode);
  1585. /* Directory mode changed, may need to revalidate access */
  1586. if (d_is_dir(entry) && (attr->ia_valid & ATTR_MODE))
  1587. fuse_invalidate_entry_cache(entry);
  1588. }
  1589. return ret;
  1590. }
  1591. static int fuse_getattr(const struct path *path, struct kstat *stat,
  1592. u32 request_mask, unsigned int flags)
  1593. {
  1594. struct inode *inode = d_inode(path->dentry);
  1595. struct fuse_conn *fc = get_fuse_conn(inode);
  1596. if (!fuse_allow_current_process(fc))
  1597. return -EACCES;
  1598. return fuse_update_get_attr(inode, NULL, stat, flags);
  1599. }
  1600. static const struct inode_operations fuse_dir_inode_operations = {
  1601. .lookup = fuse_lookup,
  1602. .mkdir = fuse_mkdir,
  1603. .symlink = fuse_symlink,
  1604. .unlink = fuse_unlink,
  1605. .rmdir = fuse_rmdir,
  1606. .rename = fuse_rename2,
  1607. .link = fuse_link,
  1608. .setattr = fuse_setattr,
  1609. .create = fuse_create,
  1610. .atomic_open = fuse_atomic_open,
  1611. .mknod = fuse_mknod,
  1612. .permission = fuse_permission,
  1613. .getattr = fuse_getattr,
  1614. .listxattr = fuse_listxattr,
  1615. .get_acl = fuse_get_acl,
  1616. .set_acl = fuse_set_acl,
  1617. };
  1618. static const struct file_operations fuse_dir_operations = {
  1619. .llseek = generic_file_llseek,
  1620. .read = generic_read_dir,
  1621. .iterate_shared = fuse_readdir,
  1622. .open = fuse_dir_open,
  1623. .release = fuse_dir_release,
  1624. .fsync = fuse_dir_fsync,
  1625. .unlocked_ioctl = fuse_dir_ioctl,
  1626. .compat_ioctl = fuse_dir_compat_ioctl,
  1627. };
  1628. static const struct inode_operations fuse_common_inode_operations = {
  1629. .setattr = fuse_setattr,
  1630. .permission = fuse_permission,
  1631. .getattr = fuse_getattr,
  1632. .listxattr = fuse_listxattr,
  1633. .get_acl = fuse_get_acl,
  1634. .set_acl = fuse_set_acl,
  1635. };
  1636. static const struct inode_operations fuse_symlink_inode_operations = {
  1637. .setattr = fuse_setattr,
  1638. .get_link = fuse_get_link,
  1639. .getattr = fuse_getattr,
  1640. .listxattr = fuse_listxattr,
  1641. };
  1642. void fuse_init_common(struct inode *inode)
  1643. {
  1644. inode->i_op = &fuse_common_inode_operations;
  1645. }
  1646. void fuse_init_dir(struct inode *inode)
  1647. {
  1648. inode->i_op = &fuse_dir_inode_operations;
  1649. inode->i_fop = &fuse_dir_operations;
  1650. }
  1651. void fuse_init_symlink(struct inode *inode)
  1652. {
  1653. inode->i_op = &fuse_symlink_inode_operations;
  1654. }