dir.c 32 KB

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