dir.c 33 KB

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