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. inode->i_generation = ++c->vfs_gen;
  156. /*
  157. * The creation sequence number remains with this inode for its
  158. * lifetime. All nodes for this inode have a greater sequence number,
  159. * and so it is possible to distinguish obsolete nodes belonging to a
  160. * previous incarnation of the same inode number - for example, for the
  161. * purpose of rebuilding the index.
  162. */
  163. ui->creat_sqnum = ++c->max_sqnum;
  164. spin_unlock(&c->cnt_lock);
  165. return inode;
  166. }
  167. #ifdef CONFIG_UBIFS_FS_DEBUG
  168. static int dbg_check_name(struct ubifs_dent_node *dent, struct qstr *nm)
  169. {
  170. if (!(ubifs_chk_flags & UBIFS_CHK_GEN))
  171. return 0;
  172. if (le16_to_cpu(dent->nlen) != nm->len)
  173. return -EINVAL;
  174. if (memcmp(dent->name, nm->name, nm->len))
  175. return -EINVAL;
  176. return 0;
  177. }
  178. #else
  179. #define dbg_check_name(dent, nm) 0
  180. #endif
  181. static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry,
  182. struct nameidata *nd)
  183. {
  184. int err;
  185. union ubifs_key key;
  186. struct inode *inode = NULL;
  187. struct ubifs_dent_node *dent;
  188. struct ubifs_info *c = dir->i_sb->s_fs_info;
  189. dbg_gen("'%.*s' in dir ino %lu",
  190. dentry->d_name.len, dentry->d_name.name, dir->i_ino);
  191. if (dentry->d_name.len > UBIFS_MAX_NLEN)
  192. return ERR_PTR(-ENAMETOOLONG);
  193. dent = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS);
  194. if (!dent)
  195. return ERR_PTR(-ENOMEM);
  196. dent_key_init(c, &key, dir->i_ino, &dentry->d_name);
  197. err = ubifs_tnc_lookup_nm(c, &key, dent, &dentry->d_name);
  198. if (err) {
  199. /*
  200. * Do not hash the direntry if parent 'i_nlink' is zero, because
  201. * this has side-effects - '->delete_inode()' call will not be
  202. * called for the parent orphan inode, because 'd_count' of its
  203. * direntry will stay 1 (it'll be negative direntry I guess)
  204. * and prevent 'iput_final()' until the dentry is destroyed due
  205. * to unmount or memory pressure.
  206. */
  207. if (err == -ENOENT && dir->i_nlink != 0) {
  208. dbg_gen("not found");
  209. goto done;
  210. }
  211. goto out;
  212. }
  213. if (dbg_check_name(dent, &dentry->d_name)) {
  214. err = -EINVAL;
  215. goto out;
  216. }
  217. inode = ubifs_iget(dir->i_sb, le64_to_cpu(dent->inum));
  218. if (IS_ERR(inode)) {
  219. /*
  220. * This should not happen. Probably the file-system needs
  221. * checking.
  222. */
  223. err = PTR_ERR(inode);
  224. ubifs_err("dead directory entry '%.*s', error %d",
  225. dentry->d_name.len, dentry->d_name.name, err);
  226. ubifs_ro_mode(c, err);
  227. goto out;
  228. }
  229. done:
  230. kfree(dent);
  231. /*
  232. * Note, d_splice_alias() would be required instead if we supported
  233. * NFS.
  234. */
  235. d_add(dentry, inode);
  236. return NULL;
  237. out:
  238. kfree(dent);
  239. return ERR_PTR(err);
  240. }
  241. static int ubifs_create(struct inode *dir, struct dentry *dentry, int mode,
  242. struct nameidata *nd)
  243. {
  244. struct inode *inode;
  245. struct ubifs_info *c = dir->i_sb->s_fs_info;
  246. int err, sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  247. struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
  248. .dirtied_ino = 1 };
  249. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  250. /*
  251. * Budget request settings: new inode, new direntry, changing the
  252. * parent directory inode.
  253. */
  254. dbg_gen("dent '%.*s', mode %#x in dir ino %lu",
  255. dentry->d_name.len, dentry->d_name.name, mode, dir->i_ino);
  256. err = ubifs_budget_space(c, &req);
  257. if (err)
  258. return err;
  259. inode = ubifs_new_inode(c, dir, mode);
  260. if (IS_ERR(inode)) {
  261. err = PTR_ERR(inode);
  262. goto out_budg;
  263. }
  264. mutex_lock(&dir_ui->ui_mutex);
  265. dir->i_size += sz_change;
  266. dir_ui->ui_size = dir->i_size;
  267. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  268. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
  269. if (err)
  270. goto out_cancel;
  271. mutex_unlock(&dir_ui->ui_mutex);
  272. ubifs_release_budget(c, &req);
  273. insert_inode_hash(inode);
  274. d_instantiate(dentry, inode);
  275. return 0;
  276. out_cancel:
  277. dir->i_size -= sz_change;
  278. dir_ui->ui_size = dir->i_size;
  279. mutex_unlock(&dir_ui->ui_mutex);
  280. make_bad_inode(inode);
  281. iput(inode);
  282. out_budg:
  283. ubifs_release_budget(c, &req);
  284. ubifs_err("cannot create regular file, error %d", err);
  285. return err;
  286. }
  287. /**
  288. * vfs_dent_type - get VFS directory entry type.
  289. * @type: UBIFS directory entry type
  290. *
  291. * This function converts UBIFS directory entry type into VFS directory entry
  292. * type.
  293. */
  294. static unsigned int vfs_dent_type(uint8_t type)
  295. {
  296. switch (type) {
  297. case UBIFS_ITYPE_REG:
  298. return DT_REG;
  299. case UBIFS_ITYPE_DIR:
  300. return DT_DIR;
  301. case UBIFS_ITYPE_LNK:
  302. return DT_LNK;
  303. case UBIFS_ITYPE_BLK:
  304. return DT_BLK;
  305. case UBIFS_ITYPE_CHR:
  306. return DT_CHR;
  307. case UBIFS_ITYPE_FIFO:
  308. return DT_FIFO;
  309. case UBIFS_ITYPE_SOCK:
  310. return DT_SOCK;
  311. default:
  312. BUG();
  313. }
  314. return 0;
  315. }
  316. /*
  317. * The classical Unix view for directory is that it is a linear array of
  318. * (name, inode number) entries. Linux/VFS assumes this model as well.
  319. * Particularly, 'readdir()' call wants us to return a directory entry offset
  320. * which later may be used to continue 'readdir()'ing the directory or to
  321. * 'seek()' to that specific direntry. Obviously UBIFS does not really fit this
  322. * model because directory entries are identified by keys, which may collide.
  323. *
  324. * UBIFS uses directory entry hash value for directory offsets, so
  325. * 'seekdir()'/'telldir()' may not always work because of possible key
  326. * collisions. But UBIFS guarantees that consecutive 'readdir()' calls work
  327. * properly by means of saving full directory entry name in the private field
  328. * of the file description object.
  329. *
  330. * This means that UBIFS cannot support NFS which requires full
  331. * 'seekdir()'/'telldir()' support.
  332. */
  333. static int ubifs_readdir(struct file *file, void *dirent, filldir_t filldir)
  334. {
  335. int err, over = 0;
  336. struct qstr nm;
  337. union ubifs_key key;
  338. struct ubifs_dent_node *dent;
  339. struct inode *dir = file->f_path.dentry->d_inode;
  340. struct ubifs_info *c = dir->i_sb->s_fs_info;
  341. dbg_gen("dir ino %lu, f_pos %#llx", dir->i_ino, file->f_pos);
  342. if (file->f_pos > UBIFS_S_KEY_HASH_MASK || file->f_pos == 2)
  343. /*
  344. * The directory was seek'ed to a senseless position or there
  345. * are no more entries.
  346. */
  347. return 0;
  348. /* File positions 0 and 1 correspond to "." and ".." */
  349. if (file->f_pos == 0) {
  350. ubifs_assert(!file->private_data);
  351. over = filldir(dirent, ".", 1, 0, dir->i_ino, DT_DIR);
  352. if (over)
  353. return 0;
  354. file->f_pos = 1;
  355. }
  356. if (file->f_pos == 1) {
  357. ubifs_assert(!file->private_data);
  358. over = filldir(dirent, "..", 2, 1,
  359. parent_ino(file->f_path.dentry), DT_DIR);
  360. if (over)
  361. return 0;
  362. /* Find the first entry in TNC and save it */
  363. lowest_dent_key(c, &key, dir->i_ino);
  364. nm.name = NULL;
  365. dent = ubifs_tnc_next_ent(c, &key, &nm);
  366. if (IS_ERR(dent)) {
  367. err = PTR_ERR(dent);
  368. goto out;
  369. }
  370. file->f_pos = key_hash_flash(c, &dent->key);
  371. file->private_data = dent;
  372. }
  373. dent = file->private_data;
  374. if (!dent) {
  375. /*
  376. * The directory was seek'ed to and is now readdir'ed.
  377. * Find the entry corresponding to @file->f_pos or the
  378. * closest one.
  379. */
  380. dent_key_init_hash(c, &key, dir->i_ino, file->f_pos);
  381. nm.name = NULL;
  382. dent = ubifs_tnc_next_ent(c, &key, &nm);
  383. if (IS_ERR(dent)) {
  384. err = PTR_ERR(dent);
  385. goto out;
  386. }
  387. file->f_pos = key_hash_flash(c, &dent->key);
  388. file->private_data = dent;
  389. }
  390. while (1) {
  391. dbg_gen("feed '%s', ino %llu, new f_pos %#x",
  392. dent->name, le64_to_cpu(dent->inum),
  393. key_hash_flash(c, &dent->key));
  394. ubifs_assert(dent->ch.sqnum > ubifs_inode(dir)->creat_sqnum);
  395. nm.len = le16_to_cpu(dent->nlen);
  396. over = filldir(dirent, dent->name, nm.len, file->f_pos,
  397. le64_to_cpu(dent->inum),
  398. vfs_dent_type(dent->type));
  399. if (over)
  400. return 0;
  401. /* Switch to the next entry */
  402. key_read(c, &dent->key, &key);
  403. nm.name = dent->name;
  404. dent = ubifs_tnc_next_ent(c, &key, &nm);
  405. if (IS_ERR(dent)) {
  406. err = PTR_ERR(dent);
  407. goto out;
  408. }
  409. kfree(file->private_data);
  410. file->f_pos = key_hash_flash(c, &dent->key);
  411. file->private_data = dent;
  412. cond_resched();
  413. }
  414. out:
  415. if (err != -ENOENT) {
  416. ubifs_err("cannot find next direntry, error %d", err);
  417. return err;
  418. }
  419. kfree(file->private_data);
  420. file->private_data = NULL;
  421. file->f_pos = 2;
  422. return 0;
  423. }
  424. /* If a directory is seeked, we have to free saved readdir() state */
  425. static loff_t ubifs_dir_llseek(struct file *file, loff_t offset, int origin)
  426. {
  427. kfree(file->private_data);
  428. file->private_data = NULL;
  429. return generic_file_llseek(file, offset, origin);
  430. }
  431. /* Free saved readdir() state when the directory is closed */
  432. static int ubifs_dir_release(struct inode *dir, struct file *file)
  433. {
  434. kfree(file->private_data);
  435. file->private_data = NULL;
  436. return 0;
  437. }
  438. /**
  439. * lock_2_inodes - lock two UBIFS inodes.
  440. * @inode1: first inode
  441. * @inode2: second inode
  442. */
  443. static void lock_2_inodes(struct inode *inode1, struct inode *inode2)
  444. {
  445. if (inode1->i_ino < inode2->i_ino) {
  446. mutex_lock_nested(&ubifs_inode(inode1)->ui_mutex, WB_MUTEX_2);
  447. mutex_lock_nested(&ubifs_inode(inode2)->ui_mutex, WB_MUTEX_3);
  448. } else {
  449. mutex_lock_nested(&ubifs_inode(inode2)->ui_mutex, WB_MUTEX_2);
  450. mutex_lock_nested(&ubifs_inode(inode1)->ui_mutex, WB_MUTEX_3);
  451. }
  452. }
  453. /**
  454. * unlock_2_inodes - unlock two UBIFS inodes inodes.
  455. * @inode1: first inode
  456. * @inode2: second inode
  457. */
  458. static void unlock_2_inodes(struct inode *inode1, struct inode *inode2)
  459. {
  460. mutex_unlock(&ubifs_inode(inode1)->ui_mutex);
  461. mutex_unlock(&ubifs_inode(inode2)->ui_mutex);
  462. }
  463. static int ubifs_link(struct dentry *old_dentry, struct inode *dir,
  464. struct dentry *dentry)
  465. {
  466. struct ubifs_info *c = dir->i_sb->s_fs_info;
  467. struct inode *inode = old_dentry->d_inode;
  468. struct ubifs_inode *ui = ubifs_inode(inode);
  469. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  470. int err, sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  471. struct ubifs_budget_req req = { .new_dent = 1, .dirtied_ino = 2,
  472. .dirtied_ino_d = ui->data_len };
  473. /*
  474. * Budget request settings: new direntry, changing the target inode,
  475. * changing the parent inode.
  476. */
  477. dbg_gen("dent '%.*s' to ino %lu (nlink %d) in dir ino %lu",
  478. dentry->d_name.len, dentry->d_name.name, inode->i_ino,
  479. inode->i_nlink, dir->i_ino);
  480. err = dbg_check_synced_i_size(inode);
  481. if (err)
  482. return err;
  483. err = ubifs_budget_space(c, &req);
  484. if (err)
  485. return err;
  486. lock_2_inodes(dir, inode);
  487. inc_nlink(inode);
  488. atomic_inc(&inode->i_count);
  489. inode->i_ctime = ubifs_current_time(inode);
  490. dir->i_size += sz_change;
  491. dir_ui->ui_size = dir->i_size;
  492. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  493. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
  494. if (err)
  495. goto out_cancel;
  496. unlock_2_inodes(dir, inode);
  497. ubifs_release_budget(c, &req);
  498. d_instantiate(dentry, inode);
  499. return 0;
  500. out_cancel:
  501. dir->i_size -= sz_change;
  502. dir_ui->ui_size = dir->i_size;
  503. drop_nlink(inode);
  504. unlock_2_inodes(dir, inode);
  505. ubifs_release_budget(c, &req);
  506. iput(inode);
  507. return err;
  508. }
  509. static int ubifs_unlink(struct inode *dir, struct dentry *dentry)
  510. {
  511. struct ubifs_info *c = dir->i_sb->s_fs_info;
  512. struct inode *inode = dentry->d_inode;
  513. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  514. int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  515. int err, budgeted = 1;
  516. struct ubifs_budget_req req = { .mod_dent = 1, .dirtied_ino = 2 };
  517. /*
  518. * Budget request settings: deletion direntry, deletion inode (+1 for
  519. * @dirtied_ino), changing the parent directory inode. If budgeting
  520. * fails, go ahead anyway because we have extra space reserved for
  521. * deletions.
  522. */
  523. dbg_gen("dent '%.*s' from ino %lu (nlink %d) in dir ino %lu",
  524. dentry->d_name.len, dentry->d_name.name, inode->i_ino,
  525. inode->i_nlink, dir->i_ino);
  526. err = dbg_check_synced_i_size(inode);
  527. if (err)
  528. return err;
  529. err = ubifs_budget_space(c, &req);
  530. if (err) {
  531. if (err != -ENOSPC)
  532. return err;
  533. err = 0;
  534. budgeted = 0;
  535. }
  536. lock_2_inodes(dir, inode);
  537. inode->i_ctime = ubifs_current_time(dir);
  538. drop_nlink(inode);
  539. dir->i_size -= sz_change;
  540. dir_ui->ui_size = dir->i_size;
  541. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  542. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 1, 0);
  543. if (err)
  544. goto out_cancel;
  545. unlock_2_inodes(dir, inode);
  546. if (budgeted)
  547. ubifs_release_budget(c, &req);
  548. else {
  549. /* We've deleted something - clean the "no space" flags */
  550. c->nospace = c->nospace_rp = 0;
  551. smp_wmb();
  552. }
  553. return 0;
  554. out_cancel:
  555. dir->i_size += sz_change;
  556. dir_ui->ui_size = dir->i_size;
  557. inc_nlink(inode);
  558. unlock_2_inodes(dir, inode);
  559. if (budgeted)
  560. ubifs_release_budget(c, &req);
  561. return err;
  562. }
  563. /**
  564. * check_dir_empty - check if a directory is empty or not.
  565. * @c: UBIFS file-system description object
  566. * @dir: VFS inode object of the directory to check
  567. *
  568. * This function checks if directory @dir is empty. Returns zero if the
  569. * directory is empty, %-ENOTEMPTY if it is not, and other negative error codes
  570. * in case of of errors.
  571. */
  572. static int check_dir_empty(struct ubifs_info *c, struct inode *dir)
  573. {
  574. struct qstr nm = { .name = NULL };
  575. struct ubifs_dent_node *dent;
  576. union ubifs_key key;
  577. int err;
  578. lowest_dent_key(c, &key, dir->i_ino);
  579. dent = ubifs_tnc_next_ent(c, &key, &nm);
  580. if (IS_ERR(dent)) {
  581. err = PTR_ERR(dent);
  582. if (err == -ENOENT)
  583. err = 0;
  584. } else {
  585. kfree(dent);
  586. err = -ENOTEMPTY;
  587. }
  588. return err;
  589. }
  590. static int ubifs_rmdir(struct inode *dir, struct dentry *dentry)
  591. {
  592. struct ubifs_info *c = dir->i_sb->s_fs_info;
  593. struct inode *inode = dentry->d_inode;
  594. int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  595. int err, budgeted = 1;
  596. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  597. struct ubifs_budget_req req = { .mod_dent = 1, .dirtied_ino = 2 };
  598. /*
  599. * Budget request settings: deletion direntry, deletion inode and
  600. * changing the parent inode. If budgeting fails, go ahead anyway
  601. * because we have extra space reserved for deletions.
  602. */
  603. dbg_gen("directory '%.*s', ino %lu in dir ino %lu", dentry->d_name.len,
  604. dentry->d_name.name, inode->i_ino, dir->i_ino);
  605. err = check_dir_empty(c, dentry->d_inode);
  606. if (err)
  607. return err;
  608. err = ubifs_budget_space(c, &req);
  609. if (err) {
  610. if (err != -ENOSPC)
  611. return err;
  612. budgeted = 0;
  613. }
  614. lock_2_inodes(dir, inode);
  615. inode->i_ctime = ubifs_current_time(dir);
  616. clear_nlink(inode);
  617. drop_nlink(dir);
  618. dir->i_size -= sz_change;
  619. dir_ui->ui_size = dir->i_size;
  620. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  621. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 1, 0);
  622. if (err)
  623. goto out_cancel;
  624. unlock_2_inodes(dir, inode);
  625. if (budgeted)
  626. ubifs_release_budget(c, &req);
  627. else {
  628. /* We've deleted something - clean the "no space" flags */
  629. c->nospace = c->nospace_rp = 0;
  630. smp_wmb();
  631. }
  632. return 0;
  633. out_cancel:
  634. dir->i_size += sz_change;
  635. dir_ui->ui_size = dir->i_size;
  636. inc_nlink(dir);
  637. inc_nlink(inode);
  638. inc_nlink(inode);
  639. unlock_2_inodes(dir, inode);
  640. if (budgeted)
  641. ubifs_release_budget(c, &req);
  642. return err;
  643. }
  644. static int ubifs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
  645. {
  646. struct inode *inode;
  647. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  648. struct ubifs_info *c = dir->i_sb->s_fs_info;
  649. int err, sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  650. struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
  651. .dirtied_ino_d = 1 };
  652. /*
  653. * Budget request settings: new inode, new direntry and changing parent
  654. * directory inode.
  655. */
  656. dbg_gen("dent '%.*s', mode %#x in dir ino %lu",
  657. dentry->d_name.len, dentry->d_name.name, mode, dir->i_ino);
  658. err = ubifs_budget_space(c, &req);
  659. if (err)
  660. return err;
  661. inode = ubifs_new_inode(c, dir, S_IFDIR | mode);
  662. if (IS_ERR(inode)) {
  663. err = PTR_ERR(inode);
  664. goto out_budg;
  665. }
  666. mutex_lock(&dir_ui->ui_mutex);
  667. insert_inode_hash(inode);
  668. inc_nlink(inode);
  669. inc_nlink(dir);
  670. dir->i_size += sz_change;
  671. dir_ui->ui_size = dir->i_size;
  672. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  673. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
  674. if (err) {
  675. ubifs_err("cannot create directory, error %d", err);
  676. goto out_cancel;
  677. }
  678. mutex_unlock(&dir_ui->ui_mutex);
  679. ubifs_release_budget(c, &req);
  680. d_instantiate(dentry, inode);
  681. return 0;
  682. out_cancel:
  683. dir->i_size -= sz_change;
  684. dir_ui->ui_size = dir->i_size;
  685. drop_nlink(dir);
  686. mutex_unlock(&dir_ui->ui_mutex);
  687. make_bad_inode(inode);
  688. iput(inode);
  689. out_budg:
  690. ubifs_release_budget(c, &req);
  691. return err;
  692. }
  693. static int ubifs_mknod(struct inode *dir, struct dentry *dentry,
  694. int mode, dev_t rdev)
  695. {
  696. struct inode *inode;
  697. struct ubifs_inode *ui;
  698. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  699. struct ubifs_info *c = dir->i_sb->s_fs_info;
  700. union ubifs_dev_desc *dev = NULL;
  701. int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  702. int err, devlen = 0;
  703. struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
  704. .new_ino_d = devlen, .dirtied_ino = 1 };
  705. /*
  706. * Budget request settings: new inode, new direntry and changing parent
  707. * directory inode.
  708. */
  709. dbg_gen("dent '%.*s' in dir ino %lu",
  710. dentry->d_name.len, dentry->d_name.name, dir->i_ino);
  711. if (!new_valid_dev(rdev))
  712. return -EINVAL;
  713. if (S_ISBLK(mode) || S_ISCHR(mode)) {
  714. dev = kmalloc(sizeof(union ubifs_dev_desc), GFP_NOFS);
  715. if (!dev)
  716. return -ENOMEM;
  717. devlen = ubifs_encode_dev(dev, rdev);
  718. }
  719. err = ubifs_budget_space(c, &req);
  720. if (err) {
  721. kfree(dev);
  722. return err;
  723. }
  724. inode = ubifs_new_inode(c, dir, mode);
  725. if (IS_ERR(inode)) {
  726. kfree(dev);
  727. err = PTR_ERR(inode);
  728. goto out_budg;
  729. }
  730. init_special_inode(inode, inode->i_mode, rdev);
  731. inode->i_size = ubifs_inode(inode)->ui_size = devlen;
  732. ui = ubifs_inode(inode);
  733. ui->data = dev;
  734. ui->data_len = devlen;
  735. mutex_lock(&dir_ui->ui_mutex);
  736. dir->i_size += sz_change;
  737. dir_ui->ui_size = dir->i_size;
  738. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  739. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
  740. if (err)
  741. goto out_cancel;
  742. mutex_unlock(&dir_ui->ui_mutex);
  743. ubifs_release_budget(c, &req);
  744. insert_inode_hash(inode);
  745. d_instantiate(dentry, inode);
  746. return 0;
  747. out_cancel:
  748. dir->i_size -= sz_change;
  749. dir_ui->ui_size = dir->i_size;
  750. mutex_unlock(&dir_ui->ui_mutex);
  751. make_bad_inode(inode);
  752. iput(inode);
  753. out_budg:
  754. ubifs_release_budget(c, &req);
  755. return err;
  756. }
  757. static int ubifs_symlink(struct inode *dir, struct dentry *dentry,
  758. const char *symname)
  759. {
  760. struct inode *inode;
  761. struct ubifs_inode *ui;
  762. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  763. struct ubifs_info *c = dir->i_sb->s_fs_info;
  764. int err, len = strlen(symname);
  765. int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  766. struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
  767. .new_ino_d = len, .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 = old_inode_ui->data_len };
  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. };