dir.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. /* * This file is part of UBIFS.
  2. *
  3. * Copyright (C) 2006-2008 Nokia Corporation.
  4. * Copyright (C) 2006, 2007 University of Szeged, Hungary
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, write to the Free Software Foundation, Inc., 51
  17. * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. *
  19. * Authors: Artem Bityutskiy (Битюцкий Артём)
  20. * Adrian Hunter
  21. * Zoltan Sogor
  22. */
  23. /*
  24. * This file implements directory operations.
  25. *
  26. * All FS operations in this file allocate budget before writing anything to the
  27. * media. If they fail to allocate it, the error is returned. The only
  28. * exceptions are 'ubifs_unlink()' and 'ubifs_rmdir()' which keep working even
  29. * if they unable to allocate the budget, because deletion %-ENOSPC failure is
  30. * not what users are usually ready to get. UBIFS budgeting subsystem has some
  31. * space reserved for these purposes.
  32. *
  33. * All operations in this file write all inodes which they change straight
  34. * away, instead of marking them dirty. For example, 'ubifs_link()' changes
  35. * @i_size of the parent inode and writes the parent inode together with the
  36. * target inode. This was done to simplify file-system recovery which would
  37. * otherwise be very difficult to do. The only exception is rename which marks
  38. * the re-named inode dirty (because its @i_ctime is updated) but does not
  39. * write it, but just marks it as dirty.
  40. */
  41. #include "ubifs.h"
  42. /**
  43. * inherit_flags - inherit flags of the parent inode.
  44. * @dir: parent inode
  45. * @mode: new inode mode flags
  46. *
  47. * This is a helper function for 'ubifs_new_inode()' which inherits flag of the
  48. * parent directory inode @dir. UBIFS inodes inherit the following flags:
  49. * o %UBIFS_COMPR_FL, which is useful to switch compression on/of on
  50. * sub-directory basis;
  51. * o %UBIFS_SYNC_FL - useful for the same reasons;
  52. * o %UBIFS_DIRSYNC_FL - similar, but relevant only to directories.
  53. *
  54. * This function returns the inherited flags.
  55. */
  56. static int inherit_flags(const struct inode *dir, umode_t mode)
  57. {
  58. int flags;
  59. const struct ubifs_inode *ui = ubifs_inode(dir);
  60. if (!S_ISDIR(dir->i_mode))
  61. /*
  62. * The parent is not a directory, which means that an extended
  63. * attribute inode is being created. No flags.
  64. */
  65. return 0;
  66. flags = ui->flags & (UBIFS_COMPR_FL | UBIFS_SYNC_FL | UBIFS_DIRSYNC_FL);
  67. if (!S_ISDIR(mode))
  68. /* The "DIRSYNC" flag only applies to directories */
  69. flags &= ~UBIFS_DIRSYNC_FL;
  70. return flags;
  71. }
  72. /**
  73. * ubifs_new_inode - allocate new UBIFS inode object.
  74. * @c: UBIFS file-system description object
  75. * @dir: parent directory inode
  76. * @mode: inode mode flags
  77. *
  78. * This function finds an unused inode number, allocates new inode and
  79. * initializes it. Returns new inode in case of success and an error code in
  80. * case of failure.
  81. */
  82. struct inode *ubifs_new_inode(struct ubifs_info *c, const struct inode *dir,
  83. umode_t mode)
  84. {
  85. struct inode *inode;
  86. struct ubifs_inode *ui;
  87. inode = new_inode(c->vfs_sb);
  88. ui = ubifs_inode(inode);
  89. if (!inode)
  90. return ERR_PTR(-ENOMEM);
  91. /*
  92. * Set 'S_NOCMTIME' to prevent VFS form updating [mc]time of inodes and
  93. * marking them dirty in file write path (see 'file_update_time()').
  94. * UBIFS has to fully control "clean <-> dirty" transitions of inodes
  95. * to make budgeting work.
  96. */
  97. inode->i_flags |= S_NOCMTIME;
  98. inode_init_owner(inode, dir, mode);
  99. inode->i_mtime = inode->i_atime = inode->i_ctime =
  100. ubifs_current_time(inode);
  101. inode->i_mapping->nrpages = 0;
  102. /* Disable readahead */
  103. inode->i_mapping->backing_dev_info = &c->bdi;
  104. switch (mode & S_IFMT) {
  105. case S_IFREG:
  106. inode->i_mapping->a_ops = &ubifs_file_address_operations;
  107. inode->i_op = &ubifs_file_inode_operations;
  108. inode->i_fop = &ubifs_file_operations;
  109. break;
  110. case S_IFDIR:
  111. inode->i_op = &ubifs_dir_inode_operations;
  112. inode->i_fop = &ubifs_dir_operations;
  113. inode->i_size = ui->ui_size = UBIFS_INO_NODE_SZ;
  114. break;
  115. case S_IFLNK:
  116. inode->i_op = &ubifs_symlink_inode_operations;
  117. break;
  118. case S_IFSOCK:
  119. case S_IFIFO:
  120. case S_IFBLK:
  121. case S_IFCHR:
  122. inode->i_op = &ubifs_file_inode_operations;
  123. break;
  124. default:
  125. BUG();
  126. }
  127. ui->flags = inherit_flags(dir, mode);
  128. ubifs_set_inode_flags(inode);
  129. if (S_ISREG(mode))
  130. ui->compr_type = c->default_compr;
  131. else
  132. ui->compr_type = UBIFS_COMPR_NONE;
  133. ui->synced_i_size = 0;
  134. spin_lock(&c->cnt_lock);
  135. /* Inode number overflow is currently not supported */
  136. if (c->highest_inum >= INUM_WARN_WATERMARK) {
  137. if (c->highest_inum >= INUM_WATERMARK) {
  138. spin_unlock(&c->cnt_lock);
  139. ubifs_err("out of inode numbers");
  140. make_bad_inode(inode);
  141. iput(inode);
  142. return ERR_PTR(-EINVAL);
  143. }
  144. ubifs_warn("running out of inode numbers (current %lu, max %d)",
  145. (unsigned long)c->highest_inum, INUM_WATERMARK);
  146. }
  147. inode->i_ino = ++c->highest_inum;
  148. /*
  149. * The creation sequence number remains with this inode for its
  150. * lifetime. All nodes for this inode have a greater sequence number,
  151. * and so it is possible to distinguish obsolete nodes belonging to a
  152. * previous incarnation of the same inode number - for example, for the
  153. * purpose of rebuilding the index.
  154. */
  155. ui->creat_sqnum = ++c->max_sqnum;
  156. spin_unlock(&c->cnt_lock);
  157. return inode;
  158. }
  159. static int dbg_check_name(const struct ubifs_info *c,
  160. const struct ubifs_dent_node *dent,
  161. const struct qstr *nm)
  162. {
  163. if (!dbg_is_chk_gen(c))
  164. return 0;
  165. if (le16_to_cpu(dent->nlen) != nm->len)
  166. return -EINVAL;
  167. if (memcmp(dent->name, nm->name, nm->len))
  168. return -EINVAL;
  169. return 0;
  170. }
  171. static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry,
  172. unsigned int flags)
  173. {
  174. int err;
  175. union ubifs_key key;
  176. struct inode *inode = NULL;
  177. struct ubifs_dent_node *dent;
  178. struct ubifs_info *c = dir->i_sb->s_fs_info;
  179. dbg_gen("'%pd' in dir ino %lu", dentry, dir->i_ino);
  180. if (dentry->d_name.len > UBIFS_MAX_NLEN)
  181. return ERR_PTR(-ENAMETOOLONG);
  182. dent = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS);
  183. if (!dent)
  184. return ERR_PTR(-ENOMEM);
  185. dent_key_init(c, &key, dir->i_ino, &dentry->d_name);
  186. err = ubifs_tnc_lookup_nm(c, &key, dent, &dentry->d_name);
  187. if (err) {
  188. if (err == -ENOENT) {
  189. dbg_gen("not found");
  190. goto done;
  191. }
  192. goto out;
  193. }
  194. if (dbg_check_name(c, dent, &dentry->d_name)) {
  195. err = -EINVAL;
  196. goto out;
  197. }
  198. inode = ubifs_iget(dir->i_sb, le64_to_cpu(dent->inum));
  199. if (IS_ERR(inode)) {
  200. /*
  201. * This should not happen. Probably the file-system needs
  202. * checking.
  203. */
  204. err = PTR_ERR(inode);
  205. ubifs_err("dead directory entry '%pd', error %d",
  206. dentry, err);
  207. ubifs_ro_mode(c, err);
  208. goto out;
  209. }
  210. done:
  211. kfree(dent);
  212. /*
  213. * Note, d_splice_alias() would be required instead if we supported
  214. * NFS.
  215. */
  216. d_add(dentry, inode);
  217. return NULL;
  218. out:
  219. kfree(dent);
  220. return ERR_PTR(err);
  221. }
  222. static int ubifs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
  223. bool excl)
  224. {
  225. struct inode *inode;
  226. struct ubifs_info *c = dir->i_sb->s_fs_info;
  227. int err, sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  228. struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
  229. .dirtied_ino = 1 };
  230. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  231. /*
  232. * Budget request settings: new inode, new direntry, changing the
  233. * parent directory inode.
  234. */
  235. dbg_gen("dent '%pd', mode %#hx in dir ino %lu",
  236. dentry, mode, dir->i_ino);
  237. err = ubifs_budget_space(c, &req);
  238. if (err)
  239. return err;
  240. inode = ubifs_new_inode(c, dir, mode);
  241. if (IS_ERR(inode)) {
  242. err = PTR_ERR(inode);
  243. goto out_budg;
  244. }
  245. err = ubifs_init_security(dir, inode, &dentry->d_name);
  246. if (err) {
  247. ubifs_err("cannot initialize extended attribute, error %d", err);
  248. goto out_inode;
  249. }
  250. mutex_lock(&dir_ui->ui_mutex);
  251. dir->i_size += sz_change;
  252. dir_ui->ui_size = dir->i_size;
  253. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  254. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
  255. if (err)
  256. goto out_cancel;
  257. mutex_unlock(&dir_ui->ui_mutex);
  258. ubifs_release_budget(c, &req);
  259. insert_inode_hash(inode);
  260. d_instantiate(dentry, inode);
  261. return 0;
  262. out_cancel:
  263. dir->i_size -= sz_change;
  264. dir_ui->ui_size = dir->i_size;
  265. mutex_unlock(&dir_ui->ui_mutex);
  266. make_bad_inode(inode);
  267. out_inode:
  268. iput(inode);
  269. out_budg:
  270. ubifs_release_budget(c, &req);
  271. ubifs_err("cannot create regular file, error %d", err);
  272. return err;
  273. }
  274. /**
  275. * vfs_dent_type - get VFS directory entry type.
  276. * @type: UBIFS directory entry type
  277. *
  278. * This function converts UBIFS directory entry type into VFS directory entry
  279. * type.
  280. */
  281. static unsigned int vfs_dent_type(uint8_t type)
  282. {
  283. switch (type) {
  284. case UBIFS_ITYPE_REG:
  285. return DT_REG;
  286. case UBIFS_ITYPE_DIR:
  287. return DT_DIR;
  288. case UBIFS_ITYPE_LNK:
  289. return DT_LNK;
  290. case UBIFS_ITYPE_BLK:
  291. return DT_BLK;
  292. case UBIFS_ITYPE_CHR:
  293. return DT_CHR;
  294. case UBIFS_ITYPE_FIFO:
  295. return DT_FIFO;
  296. case UBIFS_ITYPE_SOCK:
  297. return DT_SOCK;
  298. default:
  299. BUG();
  300. }
  301. return 0;
  302. }
  303. /*
  304. * The classical Unix view for directory is that it is a linear array of
  305. * (name, inode number) entries. Linux/VFS assumes this model as well.
  306. * Particularly, 'readdir()' call wants us to return a directory entry offset
  307. * which later may be used to continue 'readdir()'ing the directory or to
  308. * 'seek()' to that specific direntry. Obviously UBIFS does not really fit this
  309. * model because directory entries are identified by keys, which may collide.
  310. *
  311. * UBIFS uses directory entry hash value for directory offsets, so
  312. * 'seekdir()'/'telldir()' may not always work because of possible key
  313. * collisions. But UBIFS guarantees that consecutive 'readdir()' calls work
  314. * properly by means of saving full directory entry name in the private field
  315. * of the file description object.
  316. *
  317. * This means that UBIFS cannot support NFS which requires full
  318. * 'seekdir()'/'telldir()' support.
  319. */
  320. static int ubifs_readdir(struct file *file, struct dir_context *ctx)
  321. {
  322. int err;
  323. struct qstr nm;
  324. union ubifs_key key;
  325. struct ubifs_dent_node *dent;
  326. struct inode *dir = file_inode(file);
  327. struct ubifs_info *c = dir->i_sb->s_fs_info;
  328. dbg_gen("dir ino %lu, f_pos %#llx", dir->i_ino, ctx->pos);
  329. if (ctx->pos > UBIFS_S_KEY_HASH_MASK || ctx->pos == 2)
  330. /*
  331. * The directory was seek'ed to a senseless position or there
  332. * are no more entries.
  333. */
  334. return 0;
  335. if (file->f_version == 0) {
  336. /*
  337. * The file was seek'ed, which means that @file->private_data
  338. * is now invalid. This may also be just the first
  339. * 'ubifs_readdir()' invocation, in which case
  340. * @file->private_data is NULL, and the below code is
  341. * basically a no-op.
  342. */
  343. kfree(file->private_data);
  344. file->private_data = NULL;
  345. }
  346. /*
  347. * 'generic_file_llseek()' unconditionally sets @file->f_version to
  348. * zero, and we use this for detecting whether the file was seek'ed.
  349. */
  350. file->f_version = 1;
  351. /* File positions 0 and 1 correspond to "." and ".." */
  352. if (ctx->pos < 2) {
  353. ubifs_assert(!file->private_data);
  354. if (!dir_emit_dots(file, ctx))
  355. return 0;
  356. /* Find the first entry in TNC and save it */
  357. lowest_dent_key(c, &key, dir->i_ino);
  358. nm.name = NULL;
  359. dent = ubifs_tnc_next_ent(c, &key, &nm);
  360. if (IS_ERR(dent)) {
  361. err = PTR_ERR(dent);
  362. goto out;
  363. }
  364. ctx->pos = key_hash_flash(c, &dent->key);
  365. file->private_data = dent;
  366. }
  367. dent = file->private_data;
  368. if (!dent) {
  369. /*
  370. * The directory was seek'ed to and is now readdir'ed.
  371. * Find the entry corresponding to @ctx->pos or the closest one.
  372. */
  373. dent_key_init_hash(c, &key, dir->i_ino, ctx->pos);
  374. nm.name = NULL;
  375. dent = ubifs_tnc_next_ent(c, &key, &nm);
  376. if (IS_ERR(dent)) {
  377. err = PTR_ERR(dent);
  378. goto out;
  379. }
  380. ctx->pos = key_hash_flash(c, &dent->key);
  381. file->private_data = dent;
  382. }
  383. while (1) {
  384. dbg_gen("feed '%s', ino %llu, new f_pos %#x",
  385. dent->name, (unsigned long long)le64_to_cpu(dent->inum),
  386. key_hash_flash(c, &dent->key));
  387. ubifs_assert(le64_to_cpu(dent->ch.sqnum) >
  388. ubifs_inode(dir)->creat_sqnum);
  389. nm.len = le16_to_cpu(dent->nlen);
  390. if (!dir_emit(ctx, dent->name, nm.len,
  391. le64_to_cpu(dent->inum),
  392. vfs_dent_type(dent->type)))
  393. return 0;
  394. /* Switch to the next entry */
  395. key_read(c, &dent->key, &key);
  396. nm.name = dent->name;
  397. dent = ubifs_tnc_next_ent(c, &key, &nm);
  398. if (IS_ERR(dent)) {
  399. err = PTR_ERR(dent);
  400. goto out;
  401. }
  402. kfree(file->private_data);
  403. ctx->pos = key_hash_flash(c, &dent->key);
  404. file->private_data = dent;
  405. cond_resched();
  406. }
  407. out:
  408. if (err != -ENOENT) {
  409. ubifs_err("cannot find next direntry, error %d", err);
  410. return err;
  411. }
  412. kfree(file->private_data);
  413. file->private_data = NULL;
  414. /* 2 is a special value indicating that there are no more direntries */
  415. ctx->pos = 2;
  416. return 0;
  417. }
  418. /* Free saved readdir() state when the directory is closed */
  419. static int ubifs_dir_release(struct inode *dir, struct file *file)
  420. {
  421. kfree(file->private_data);
  422. file->private_data = NULL;
  423. return 0;
  424. }
  425. /**
  426. * lock_2_inodes - a wrapper for locking two UBIFS inodes.
  427. * @inode1: first inode
  428. * @inode2: second inode
  429. *
  430. * We do not implement any tricks to guarantee strict lock ordering, because
  431. * VFS has already done it for us on the @i_mutex. So this is just a simple
  432. * wrapper function.
  433. */
  434. static void lock_2_inodes(struct inode *inode1, struct inode *inode2)
  435. {
  436. mutex_lock_nested(&ubifs_inode(inode1)->ui_mutex, WB_MUTEX_1);
  437. mutex_lock_nested(&ubifs_inode(inode2)->ui_mutex, WB_MUTEX_2);
  438. }
  439. /**
  440. * unlock_2_inodes - a wrapper for unlocking two UBIFS inodes.
  441. * @inode1: first inode
  442. * @inode2: second inode
  443. */
  444. static void unlock_2_inodes(struct inode *inode1, struct inode *inode2)
  445. {
  446. mutex_unlock(&ubifs_inode(inode2)->ui_mutex);
  447. mutex_unlock(&ubifs_inode(inode1)->ui_mutex);
  448. }
  449. static int ubifs_link(struct dentry *old_dentry, struct inode *dir,
  450. struct dentry *dentry)
  451. {
  452. struct ubifs_info *c = dir->i_sb->s_fs_info;
  453. struct inode *inode = old_dentry->d_inode;
  454. struct ubifs_inode *ui = ubifs_inode(inode);
  455. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  456. int err, sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  457. struct ubifs_budget_req req = { .new_dent = 1, .dirtied_ino = 2,
  458. .dirtied_ino_d = ALIGN(ui->data_len, 8) };
  459. /*
  460. * Budget request settings: new direntry, changing the target inode,
  461. * changing the parent inode.
  462. */
  463. dbg_gen("dent '%pd' to ino %lu (nlink %d) in dir ino %lu",
  464. dentry, inode->i_ino,
  465. inode->i_nlink, dir->i_ino);
  466. ubifs_assert(mutex_is_locked(&dir->i_mutex));
  467. ubifs_assert(mutex_is_locked(&inode->i_mutex));
  468. err = dbg_check_synced_i_size(c, inode);
  469. if (err)
  470. return err;
  471. err = ubifs_budget_space(c, &req);
  472. if (err)
  473. return err;
  474. lock_2_inodes(dir, inode);
  475. inc_nlink(inode);
  476. ihold(inode);
  477. inode->i_ctime = ubifs_current_time(inode);
  478. dir->i_size += sz_change;
  479. dir_ui->ui_size = dir->i_size;
  480. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  481. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
  482. if (err)
  483. goto out_cancel;
  484. unlock_2_inodes(dir, inode);
  485. ubifs_release_budget(c, &req);
  486. d_instantiate(dentry, inode);
  487. return 0;
  488. out_cancel:
  489. dir->i_size -= sz_change;
  490. dir_ui->ui_size = dir->i_size;
  491. drop_nlink(inode);
  492. unlock_2_inodes(dir, inode);
  493. ubifs_release_budget(c, &req);
  494. iput(inode);
  495. return err;
  496. }
  497. static int ubifs_unlink(struct inode *dir, struct dentry *dentry)
  498. {
  499. struct ubifs_info *c = dir->i_sb->s_fs_info;
  500. struct inode *inode = dentry->d_inode;
  501. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  502. int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  503. int err, budgeted = 1;
  504. struct ubifs_budget_req req = { .mod_dent = 1, .dirtied_ino = 2 };
  505. unsigned int saved_nlink = inode->i_nlink;
  506. /* MTK start
  507. * add log to delete xattr
  508. */
  509. union ubifs_key key;
  510. struct qstr nm = { .name = NULL };
  511. lowest_xent_key(c, &key, inode->i_ino);
  512. while (1) {
  513. struct ubifs_dent_node *xent;
  514. xent = ubifs_tnc_next_ent(c, &key, &nm);
  515. if (IS_ERR(xent)) {
  516. err = PTR_ERR(xent);
  517. /*ubifs_err("err %d\n", err);*/
  518. break;
  519. }
  520. /*ubifs_err("remove xattr %s\n", xent->name);*/
  521. ubifs_removexattr(dentry, xent->name);
  522. kfree(xent);
  523. }
  524. /* MTK end */
  525. /*
  526. * Budget request settings: deletion direntry, deletion inode (+1 for
  527. * @dirtied_ino), changing the parent directory inode. If budgeting
  528. * fails, go ahead anyway because we have extra space reserved for
  529. * deletions.
  530. */
  531. dbg_gen("dent '%pd' from ino %lu (nlink %d) in dir ino %lu",
  532. dentry, inode->i_ino,
  533. inode->i_nlink, dir->i_ino);
  534. ubifs_assert(mutex_is_locked(&dir->i_mutex));
  535. ubifs_assert(mutex_is_locked(&inode->i_mutex));
  536. err = dbg_check_synced_i_size(c, inode);
  537. if (err)
  538. return err;
  539. err = ubifs_budget_space(c, &req);
  540. if (err) {
  541. if (err != -ENOSPC)
  542. return err;
  543. budgeted = 0;
  544. }
  545. lock_2_inodes(dir, inode);
  546. inode->i_ctime = ubifs_current_time(dir);
  547. drop_nlink(inode);
  548. dir->i_size -= sz_change;
  549. dir_ui->ui_size = dir->i_size;
  550. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  551. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 1, 0);
  552. if (err)
  553. goto out_cancel;
  554. unlock_2_inodes(dir, inode);
  555. if (budgeted)
  556. ubifs_release_budget(c, &req);
  557. else {
  558. /* We've deleted something - clean the "no space" flags */
  559. c->bi.nospace = c->bi.nospace_rp = 0;
  560. smp_wmb();
  561. }
  562. return 0;
  563. out_cancel:
  564. dir->i_size += sz_change;
  565. dir_ui->ui_size = dir->i_size;
  566. set_nlink(inode, saved_nlink);
  567. unlock_2_inodes(dir, inode);
  568. if (budgeted)
  569. ubifs_release_budget(c, &req);
  570. return err;
  571. }
  572. /**
  573. * check_dir_empty - check if a directory is empty or not.
  574. * @c: UBIFS file-system description object
  575. * @dir: VFS inode object of the directory to check
  576. *
  577. * This function checks if directory @dir is empty. Returns zero if the
  578. * directory is empty, %-ENOTEMPTY if it is not, and other negative error codes
  579. * in case of of errors.
  580. */
  581. static int check_dir_empty(struct ubifs_info *c, struct inode *dir)
  582. {
  583. struct qstr nm = { .name = NULL };
  584. struct ubifs_dent_node *dent;
  585. union ubifs_key key;
  586. int err;
  587. lowest_dent_key(c, &key, dir->i_ino);
  588. dent = ubifs_tnc_next_ent(c, &key, &nm);
  589. if (IS_ERR(dent)) {
  590. err = PTR_ERR(dent);
  591. if (err == -ENOENT)
  592. err = 0;
  593. } else {
  594. kfree(dent);
  595. err = -ENOTEMPTY;
  596. }
  597. return err;
  598. }
  599. static int ubifs_rmdir(struct inode *dir, struct dentry *dentry)
  600. {
  601. struct ubifs_info *c = dir->i_sb->s_fs_info;
  602. struct inode *inode = dentry->d_inode;
  603. int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  604. int err, budgeted = 1;
  605. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  606. struct ubifs_budget_req req = { .mod_dent = 1, .dirtied_ino = 2 };
  607. /*
  608. * Budget request settings: deletion direntry, deletion inode and
  609. * changing the parent inode. If budgeting fails, go ahead anyway
  610. * because we have extra space reserved for deletions.
  611. */
  612. dbg_gen("directory '%pd', ino %lu in dir ino %lu", dentry,
  613. inode->i_ino, dir->i_ino);
  614. ubifs_assert(mutex_is_locked(&dir->i_mutex));
  615. ubifs_assert(mutex_is_locked(&inode->i_mutex));
  616. err = check_dir_empty(c, dentry->d_inode);
  617. if (err)
  618. return err;
  619. err = ubifs_budget_space(c, &req);
  620. if (err) {
  621. if (err != -ENOSPC)
  622. return err;
  623. budgeted = 0;
  624. }
  625. lock_2_inodes(dir, inode);
  626. inode->i_ctime = ubifs_current_time(dir);
  627. clear_nlink(inode);
  628. drop_nlink(dir);
  629. dir->i_size -= sz_change;
  630. dir_ui->ui_size = dir->i_size;
  631. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  632. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 1, 0);
  633. if (err)
  634. goto out_cancel;
  635. unlock_2_inodes(dir, inode);
  636. if (budgeted)
  637. ubifs_release_budget(c, &req);
  638. else {
  639. /* We've deleted something - clean the "no space" flags */
  640. c->bi.nospace = c->bi.nospace_rp = 0;
  641. smp_wmb();
  642. }
  643. return 0;
  644. out_cancel:
  645. dir->i_size += sz_change;
  646. dir_ui->ui_size = dir->i_size;
  647. inc_nlink(dir);
  648. set_nlink(inode, 2);
  649. unlock_2_inodes(dir, inode);
  650. if (budgeted)
  651. ubifs_release_budget(c, &req);
  652. return err;
  653. }
  654. static int ubifs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
  655. {
  656. struct inode *inode;
  657. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  658. struct ubifs_info *c = dir->i_sb->s_fs_info;
  659. int err, sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  660. struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1 };
  661. /*
  662. * Budget request settings: new inode, new direntry and changing parent
  663. * directory inode.
  664. */
  665. dbg_gen("dent '%pd', mode %#hx in dir ino %lu",
  666. dentry, mode, dir->i_ino);
  667. err = ubifs_budget_space(c, &req);
  668. if (err)
  669. return err;
  670. inode = ubifs_new_inode(c, dir, S_IFDIR | mode);
  671. if (IS_ERR(inode)) {
  672. err = PTR_ERR(inode);
  673. goto out_budg;
  674. }
  675. err = ubifs_init_security(dir, inode, &dentry->d_name);
  676. if (err) {
  677. ubifs_err("cannot initialize extended attribute, error %d",
  678. err);
  679. goto out_inode;
  680. }
  681. mutex_lock(&dir_ui->ui_mutex);
  682. insert_inode_hash(inode);
  683. inc_nlink(inode);
  684. inc_nlink(dir);
  685. dir->i_size += sz_change;
  686. dir_ui->ui_size = dir->i_size;
  687. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  688. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
  689. if (err) {
  690. ubifs_err("cannot create directory, error %d", err);
  691. goto out_cancel;
  692. }
  693. mutex_unlock(&dir_ui->ui_mutex);
  694. ubifs_release_budget(c, &req);
  695. d_instantiate(dentry, inode);
  696. return 0;
  697. out_cancel:
  698. dir->i_size -= sz_change;
  699. dir_ui->ui_size = dir->i_size;
  700. drop_nlink(dir);
  701. mutex_unlock(&dir_ui->ui_mutex);
  702. make_bad_inode(inode);
  703. out_inode:
  704. iput(inode);
  705. out_budg:
  706. ubifs_release_budget(c, &req);
  707. return err;
  708. }
  709. static int ubifs_mknod(struct inode *dir, struct dentry *dentry,
  710. umode_t mode, dev_t rdev)
  711. {
  712. struct inode *inode;
  713. struct ubifs_inode *ui;
  714. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  715. struct ubifs_info *c = dir->i_sb->s_fs_info;
  716. union ubifs_dev_desc *dev = NULL;
  717. int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  718. int err, devlen = 0;
  719. struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
  720. .new_ino_d = ALIGN(devlen, 8),
  721. .dirtied_ino = 1 };
  722. /*
  723. * Budget request settings: new inode, new direntry and changing parent
  724. * directory inode.
  725. */
  726. dbg_gen("dent '%pd' in dir ino %lu", dentry, dir->i_ino);
  727. if (!new_valid_dev(rdev))
  728. return -EINVAL;
  729. if (S_ISBLK(mode) || S_ISCHR(mode)) {
  730. dev = kmalloc(sizeof(union ubifs_dev_desc), GFP_NOFS);
  731. if (!dev)
  732. return -ENOMEM;
  733. devlen = ubifs_encode_dev(dev, rdev);
  734. }
  735. err = ubifs_budget_space(c, &req);
  736. if (err) {
  737. kfree(dev);
  738. return err;
  739. }
  740. inode = ubifs_new_inode(c, dir, mode);
  741. if (IS_ERR(inode)) {
  742. kfree(dev);
  743. err = PTR_ERR(inode);
  744. goto out_budg;
  745. }
  746. init_special_inode(inode, inode->i_mode, rdev);
  747. inode->i_size = ubifs_inode(inode)->ui_size = devlen;
  748. ui = ubifs_inode(inode);
  749. ui->data = dev;
  750. ui->data_len = devlen;
  751. err = ubifs_init_security(dir, inode, &dentry->d_name);
  752. if (err) {
  753. ubifs_err("cannot initialize extended attribute, error %d",
  754. err);
  755. goto out_inode;
  756. }
  757. mutex_lock(&dir_ui->ui_mutex);
  758. dir->i_size += sz_change;
  759. dir_ui->ui_size = dir->i_size;
  760. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  761. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
  762. if (err)
  763. goto out_cancel;
  764. mutex_unlock(&dir_ui->ui_mutex);
  765. ubifs_release_budget(c, &req);
  766. insert_inode_hash(inode);
  767. d_instantiate(dentry, inode);
  768. return 0;
  769. out_cancel:
  770. dir->i_size -= sz_change;
  771. dir_ui->ui_size = dir->i_size;
  772. mutex_unlock(&dir_ui->ui_mutex);
  773. make_bad_inode(inode);
  774. out_inode:
  775. iput(inode);
  776. out_budg:
  777. ubifs_release_budget(c, &req);
  778. return err;
  779. }
  780. static int ubifs_symlink(struct inode *dir, struct dentry *dentry,
  781. const char *symname)
  782. {
  783. struct inode *inode;
  784. struct ubifs_inode *ui;
  785. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  786. struct ubifs_info *c = dir->i_sb->s_fs_info;
  787. int err, len = strlen(symname);
  788. int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  789. struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
  790. .new_ino_d = ALIGN(len, 8),
  791. .dirtied_ino = 1 };
  792. /*
  793. * Budget request settings: new inode, new direntry and changing parent
  794. * directory inode.
  795. */
  796. dbg_gen("dent '%pd', target '%s' in dir ino %lu", dentry,
  797. symname, dir->i_ino);
  798. if (len > UBIFS_MAX_INO_DATA)
  799. return -ENAMETOOLONG;
  800. err = ubifs_budget_space(c, &req);
  801. if (err)
  802. return err;
  803. inode = ubifs_new_inode(c, dir, S_IFLNK | S_IRWXUGO);
  804. if (IS_ERR(inode)) {
  805. err = PTR_ERR(inode);
  806. goto out_budg;
  807. }
  808. ui = ubifs_inode(inode);
  809. ui->data = kmalloc(len + 1, GFP_NOFS);
  810. if (!ui->data) {
  811. err = -ENOMEM;
  812. goto out_inode;
  813. }
  814. memcpy(ui->data, symname, len);
  815. ((char *)ui->data)[len] = '\0';
  816. /*
  817. * The terminating zero byte is not written to the flash media and it
  818. * is put just to make later in-memory string processing simpler. Thus,
  819. * data length is @len, not @len + %1.
  820. */
  821. ui->data_len = len;
  822. inode->i_size = ubifs_inode(inode)->ui_size = len;
  823. err = ubifs_init_security(dir, inode, &dentry->d_name);
  824. if (err) {
  825. ubifs_err("cannot initialize extended attribute, error %d",
  826. err);
  827. goto out_inode;
  828. }
  829. mutex_lock(&dir_ui->ui_mutex);
  830. dir->i_size += sz_change;
  831. dir_ui->ui_size = dir->i_size;
  832. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  833. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
  834. if (err)
  835. goto out_cancel;
  836. mutex_unlock(&dir_ui->ui_mutex);
  837. ubifs_release_budget(c, &req);
  838. insert_inode_hash(inode);
  839. d_instantiate(dentry, inode);
  840. return 0;
  841. out_cancel:
  842. dir->i_size -= sz_change;
  843. dir_ui->ui_size = dir->i_size;
  844. mutex_unlock(&dir_ui->ui_mutex);
  845. out_inode:
  846. make_bad_inode(inode);
  847. iput(inode);
  848. out_budg:
  849. ubifs_release_budget(c, &req);
  850. return err;
  851. }
  852. /**
  853. * lock_3_inodes - a wrapper for locking three UBIFS inodes.
  854. * @inode1: first inode
  855. * @inode2: second inode
  856. * @inode3: third inode
  857. *
  858. * This function is used for 'ubifs_rename()' and @inode1 may be the same as
  859. * @inode2 whereas @inode3 may be %NULL.
  860. *
  861. * We do not implement any tricks to guarantee strict lock ordering, because
  862. * VFS has already done it for us on the @i_mutex. So this is just a simple
  863. * wrapper function.
  864. */
  865. static void lock_3_inodes(struct inode *inode1, struct inode *inode2,
  866. struct inode *inode3)
  867. {
  868. mutex_lock_nested(&ubifs_inode(inode1)->ui_mutex, WB_MUTEX_1);
  869. if (inode2 != inode1)
  870. mutex_lock_nested(&ubifs_inode(inode2)->ui_mutex, WB_MUTEX_2);
  871. if (inode3)
  872. mutex_lock_nested(&ubifs_inode(inode3)->ui_mutex, WB_MUTEX_3);
  873. }
  874. /**
  875. * unlock_3_inodes - a wrapper for unlocking three UBIFS inodes for rename.
  876. * @inode1: first inode
  877. * @inode2: second inode
  878. * @inode3: third inode
  879. */
  880. static void unlock_3_inodes(struct inode *inode1, struct inode *inode2,
  881. struct inode *inode3)
  882. {
  883. if (inode3)
  884. mutex_unlock(&ubifs_inode(inode3)->ui_mutex);
  885. if (inode1 != inode2)
  886. mutex_unlock(&ubifs_inode(inode2)->ui_mutex);
  887. mutex_unlock(&ubifs_inode(inode1)->ui_mutex);
  888. }
  889. static int ubifs_rename(struct inode *old_dir, struct dentry *old_dentry,
  890. struct inode *new_dir, struct dentry *new_dentry)
  891. {
  892. struct ubifs_info *c = old_dir->i_sb->s_fs_info;
  893. struct inode *old_inode = old_dentry->d_inode;
  894. struct inode *new_inode = new_dentry->d_inode;
  895. struct ubifs_inode *old_inode_ui = ubifs_inode(old_inode);
  896. int err, release, sync = 0, move = (new_dir != old_dir);
  897. int is_dir = S_ISDIR(old_inode->i_mode);
  898. int unlink = !!new_inode;
  899. int new_sz = CALC_DENT_SIZE(new_dentry->d_name.len);
  900. int old_sz = CALC_DENT_SIZE(old_dentry->d_name.len);
  901. struct ubifs_budget_req req = { .new_dent = 1, .mod_dent = 1,
  902. .dirtied_ino = 3 };
  903. struct ubifs_budget_req ino_req = { .dirtied_ino = 1,
  904. .dirtied_ino_d = ALIGN(old_inode_ui->data_len, 8) };
  905. struct timespec time;
  906. unsigned int uninitialized_var(saved_nlink);
  907. /*
  908. * Budget request settings: deletion direntry, new direntry, removing
  909. * the old inode, and changing old and new parent directory inodes.
  910. *
  911. * However, this operation also marks the target inode as dirty and
  912. * does not write it, so we allocate budget for the target inode
  913. * separately.
  914. */
  915. dbg_gen("dent '%pd' ino %lu in dir ino %lu to dent '%pd' in dir ino %lu",
  916. old_dentry, old_inode->i_ino, old_dir->i_ino,
  917. new_dentry, new_dir->i_ino);
  918. ubifs_assert(mutex_is_locked(&old_dir->i_mutex));
  919. ubifs_assert(mutex_is_locked(&new_dir->i_mutex));
  920. if (unlink)
  921. ubifs_assert(mutex_is_locked(&new_inode->i_mutex));
  922. if (unlink && is_dir) {
  923. err = check_dir_empty(c, new_inode);
  924. if (err)
  925. return err;
  926. }
  927. err = ubifs_budget_space(c, &req);
  928. if (err)
  929. return err;
  930. err = ubifs_budget_space(c, &ino_req);
  931. if (err) {
  932. ubifs_release_budget(c, &req);
  933. return err;
  934. }
  935. lock_3_inodes(old_dir, new_dir, new_inode);
  936. /*
  937. * Like most other Unix systems, set the @i_ctime for inodes on a
  938. * rename.
  939. */
  940. time = ubifs_current_time(old_dir);
  941. old_inode->i_ctime = time;
  942. /* We must adjust parent link count when renaming directories */
  943. if (is_dir) {
  944. if (move) {
  945. /*
  946. * @old_dir loses a link because we are moving
  947. * @old_inode to a different directory.
  948. */
  949. drop_nlink(old_dir);
  950. /*
  951. * @new_dir only gains a link if we are not also
  952. * overwriting an existing directory.
  953. */
  954. if (!unlink)
  955. inc_nlink(new_dir);
  956. } else {
  957. /*
  958. * @old_inode is not moving to a different directory,
  959. * but @old_dir still loses a link if we are
  960. * overwriting an existing directory.
  961. */
  962. if (unlink)
  963. drop_nlink(old_dir);
  964. }
  965. }
  966. old_dir->i_size -= old_sz;
  967. ubifs_inode(old_dir)->ui_size = old_dir->i_size;
  968. old_dir->i_mtime = old_dir->i_ctime = time;
  969. new_dir->i_mtime = new_dir->i_ctime = time;
  970. /*
  971. * And finally, if we unlinked a direntry which happened to have the
  972. * same name as the moved direntry, we have to decrement @i_nlink of
  973. * the unlinked inode and change its ctime.
  974. */
  975. if (unlink) {
  976. /*
  977. * Directories cannot have hard-links, so if this is a
  978. * directory, just clear @i_nlink.
  979. */
  980. saved_nlink = new_inode->i_nlink;
  981. if (is_dir)
  982. clear_nlink(new_inode);
  983. else
  984. drop_nlink(new_inode);
  985. new_inode->i_ctime = time;
  986. } else {
  987. new_dir->i_size += new_sz;
  988. ubifs_inode(new_dir)->ui_size = new_dir->i_size;
  989. }
  990. /*
  991. * Do not ask 'ubifs_jnl_rename()' to flush write-buffer if @old_inode
  992. * is dirty, because this will be done later on at the end of
  993. * 'ubifs_rename()'.
  994. */
  995. if (IS_SYNC(old_inode)) {
  996. sync = IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir);
  997. if (unlink && IS_SYNC(new_inode))
  998. sync = 1;
  999. }
  1000. err = ubifs_jnl_rename(c, old_dir, old_dentry, new_dir, new_dentry,
  1001. sync);
  1002. if (err)
  1003. goto out_cancel;
  1004. unlock_3_inodes(old_dir, new_dir, new_inode);
  1005. ubifs_release_budget(c, &req);
  1006. mutex_lock(&old_inode_ui->ui_mutex);
  1007. release = old_inode_ui->dirty;
  1008. mark_inode_dirty_sync(old_inode);
  1009. mutex_unlock(&old_inode_ui->ui_mutex);
  1010. if (release)
  1011. ubifs_release_budget(c, &ino_req);
  1012. if (IS_SYNC(old_inode))
  1013. err = old_inode->i_sb->s_op->write_inode(old_inode, NULL);
  1014. return err;
  1015. out_cancel:
  1016. if (unlink) {
  1017. set_nlink(new_inode, saved_nlink);
  1018. } else {
  1019. new_dir->i_size -= new_sz;
  1020. ubifs_inode(new_dir)->ui_size = new_dir->i_size;
  1021. }
  1022. old_dir->i_size += old_sz;
  1023. ubifs_inode(old_dir)->ui_size = old_dir->i_size;
  1024. if (is_dir) {
  1025. if (move) {
  1026. inc_nlink(old_dir);
  1027. if (!unlink)
  1028. drop_nlink(new_dir);
  1029. } else {
  1030. if (unlink)
  1031. inc_nlink(old_dir);
  1032. }
  1033. }
  1034. unlock_3_inodes(old_dir, new_dir, new_inode);
  1035. ubifs_release_budget(c, &ino_req);
  1036. ubifs_release_budget(c, &req);
  1037. return err;
  1038. }
  1039. int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  1040. struct kstat *stat)
  1041. {
  1042. loff_t size;
  1043. struct inode *inode = dentry->d_inode;
  1044. struct ubifs_inode *ui = ubifs_inode(inode);
  1045. mutex_lock(&ui->ui_mutex);
  1046. generic_fillattr(inode, stat);
  1047. stat->blksize = UBIFS_BLOCK_SIZE;
  1048. stat->size = ui->ui_size;
  1049. /*
  1050. * Unfortunately, the 'stat()' system call was designed for block
  1051. * device based file systems, and it is not appropriate for UBIFS,
  1052. * because UBIFS does not have notion of "block". For example, it is
  1053. * difficult to tell how many block a directory takes - it actually
  1054. * takes less than 300 bytes, but we have to round it to block size,
  1055. * which introduces large mistake. This makes utilities like 'du' to
  1056. * report completely senseless numbers. This is the reason why UBIFS
  1057. * goes the same way as JFFS2 - it reports zero blocks for everything
  1058. * but regular files, which makes more sense than reporting completely
  1059. * wrong sizes.
  1060. */
  1061. if (S_ISREG(inode->i_mode)) {
  1062. size = ui->xattr_size;
  1063. size += stat->size;
  1064. size = ALIGN(size, UBIFS_BLOCK_SIZE);
  1065. /*
  1066. * Note, user-space expects 512-byte blocks count irrespectively
  1067. * of what was reported in @stat->size.
  1068. */
  1069. stat->blocks = size >> 9;
  1070. } else
  1071. stat->blocks = 0;
  1072. mutex_unlock(&ui->ui_mutex);
  1073. return 0;
  1074. }
  1075. const struct inode_operations ubifs_dir_inode_operations = {
  1076. .lookup = ubifs_lookup,
  1077. .create = ubifs_create,
  1078. .link = ubifs_link,
  1079. .symlink = ubifs_symlink,
  1080. .unlink = ubifs_unlink,
  1081. .mkdir = ubifs_mkdir,
  1082. .rmdir = ubifs_rmdir,
  1083. .mknod = ubifs_mknod,
  1084. .rename = ubifs_rename,
  1085. .setattr = ubifs_setattr,
  1086. .getattr = ubifs_getattr,
  1087. .setxattr = ubifs_setxattr,
  1088. .getxattr = ubifs_getxattr,
  1089. .listxattr = ubifs_listxattr,
  1090. .removexattr = ubifs_removexattr,
  1091. };
  1092. const struct file_operations ubifs_dir_operations = {
  1093. .llseek = generic_file_llseek,
  1094. .release = ubifs_dir_release,
  1095. .read = generic_read_dir,
  1096. .iterate = ubifs_readdir,
  1097. .fsync = ubifs_fsync,
  1098. .unlocked_ioctl = ubifs_ioctl,
  1099. #ifdef CONFIG_COMPAT
  1100. .compat_ioctl = ubifs_compat_ioctl,
  1101. #endif
  1102. };