dir.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  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. /*
  652. * Budget request settings: new inode, new direntry and changing parent
  653. * directory inode.
  654. */
  655. dbg_gen("dent '%.*s', mode %#x in dir ino %lu",
  656. dentry->d_name.len, dentry->d_name.name, mode, dir->i_ino);
  657. err = ubifs_budget_space(c, &req);
  658. if (err)
  659. return err;
  660. inode = ubifs_new_inode(c, dir, S_IFDIR | mode);
  661. if (IS_ERR(inode)) {
  662. err = PTR_ERR(inode);
  663. goto out_budg;
  664. }
  665. mutex_lock(&dir_ui->ui_mutex);
  666. insert_inode_hash(inode);
  667. inc_nlink(inode);
  668. inc_nlink(dir);
  669. dir->i_size += sz_change;
  670. dir_ui->ui_size = dir->i_size;
  671. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  672. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
  673. if (err) {
  674. ubifs_err("cannot create directory, error %d", err);
  675. goto out_cancel;
  676. }
  677. mutex_unlock(&dir_ui->ui_mutex);
  678. ubifs_release_budget(c, &req);
  679. d_instantiate(dentry, inode);
  680. return 0;
  681. out_cancel:
  682. dir->i_size -= sz_change;
  683. dir_ui->ui_size = dir->i_size;
  684. drop_nlink(dir);
  685. mutex_unlock(&dir_ui->ui_mutex);
  686. make_bad_inode(inode);
  687. iput(inode);
  688. out_budg:
  689. ubifs_release_budget(c, &req);
  690. return err;
  691. }
  692. static int ubifs_mknod(struct inode *dir, struct dentry *dentry,
  693. int mode, dev_t rdev)
  694. {
  695. struct inode *inode;
  696. struct ubifs_inode *ui;
  697. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  698. struct ubifs_info *c = dir->i_sb->s_fs_info;
  699. union ubifs_dev_desc *dev = NULL;
  700. int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  701. int err, devlen = 0;
  702. struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
  703. .new_ino_d = devlen, .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 = len, .dirtied_ino = 1 };
  767. /*
  768. * Budget request settings: new inode, new direntry and changing parent
  769. * directory inode.
  770. */
  771. dbg_gen("dent '%.*s', target '%s' in dir ino %lu", dentry->d_name.len,
  772. dentry->d_name.name, symname, dir->i_ino);
  773. if (len > UBIFS_MAX_INO_DATA)
  774. return -ENAMETOOLONG;
  775. err = ubifs_budget_space(c, &req);
  776. if (err)
  777. return err;
  778. inode = ubifs_new_inode(c, dir, S_IFLNK | S_IRWXUGO);
  779. if (IS_ERR(inode)) {
  780. err = PTR_ERR(inode);
  781. goto out_budg;
  782. }
  783. ui = ubifs_inode(inode);
  784. ui->data = kmalloc(len + 1, GFP_NOFS);
  785. if (!ui->data) {
  786. err = -ENOMEM;
  787. goto out_inode;
  788. }
  789. memcpy(ui->data, symname, len);
  790. ((char *)ui->data)[len] = '\0';
  791. /*
  792. * The terminating zero byte is not written to the flash media and it
  793. * is put just to make later in-memory string processing simpler. Thus,
  794. * data length is @len, not @len + %1.
  795. */
  796. ui->data_len = len;
  797. inode->i_size = ubifs_inode(inode)->ui_size = len;
  798. mutex_lock(&dir_ui->ui_mutex);
  799. dir->i_size += sz_change;
  800. dir_ui->ui_size = dir->i_size;
  801. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  802. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
  803. if (err)
  804. goto out_cancel;
  805. mutex_unlock(&dir_ui->ui_mutex);
  806. ubifs_release_budget(c, &req);
  807. insert_inode_hash(inode);
  808. d_instantiate(dentry, inode);
  809. return 0;
  810. out_cancel:
  811. dir->i_size -= sz_change;
  812. dir_ui->ui_size = dir->i_size;
  813. mutex_unlock(&dir_ui->ui_mutex);
  814. out_inode:
  815. make_bad_inode(inode);
  816. iput(inode);
  817. out_budg:
  818. ubifs_release_budget(c, &req);
  819. return err;
  820. }
  821. /**
  822. * lock_3_inodes - lock three UBIFS inodes for rename.
  823. * @inode1: first inode
  824. * @inode2: second inode
  825. * @inode3: third inode
  826. *
  827. * For 'ubifs_rename()', @inode1 may be the same as @inode2 whereas @inode3 may
  828. * be null.
  829. */
  830. static void lock_3_inodes(struct inode *inode1, struct inode *inode2,
  831. struct inode *inode3)
  832. {
  833. struct inode *i1, *i2, *i3;
  834. if (!inode3) {
  835. if (inode1 != inode2) {
  836. lock_2_inodes(inode1, inode2);
  837. return;
  838. }
  839. mutex_lock_nested(&ubifs_inode(inode1)->ui_mutex, WB_MUTEX_1);
  840. return;
  841. }
  842. if (inode1 == inode2) {
  843. lock_2_inodes(inode1, inode3);
  844. return;
  845. }
  846. /* 3 different inodes */
  847. if (inode1 < inode2) {
  848. i3 = inode2;
  849. if (inode1 < inode3) {
  850. i1 = inode1;
  851. i2 = inode3;
  852. } else {
  853. i1 = inode3;
  854. i2 = inode1;
  855. }
  856. } else {
  857. i3 = inode1;
  858. if (inode2 < inode3) {
  859. i1 = inode2;
  860. i2 = inode3;
  861. } else {
  862. i1 = inode3;
  863. i2 = inode2;
  864. }
  865. }
  866. mutex_lock_nested(&ubifs_inode(i1)->ui_mutex, WB_MUTEX_1);
  867. lock_2_inodes(i2, i3);
  868. }
  869. /**
  870. * unlock_3_inodes - unlock three UBIFS inodes for rename.
  871. * @inode1: first inode
  872. * @inode2: second inode
  873. * @inode3: third inode
  874. */
  875. static void unlock_3_inodes(struct inode *inode1, struct inode *inode2,
  876. struct inode *inode3)
  877. {
  878. mutex_unlock(&ubifs_inode(inode1)->ui_mutex);
  879. if (inode1 != inode2)
  880. mutex_unlock(&ubifs_inode(inode2)->ui_mutex);
  881. if (inode3)
  882. mutex_unlock(&ubifs_inode(inode3)->ui_mutex);
  883. }
  884. static int ubifs_rename(struct inode *old_dir, struct dentry *old_dentry,
  885. struct inode *new_dir, struct dentry *new_dentry)
  886. {
  887. struct ubifs_info *c = old_dir->i_sb->s_fs_info;
  888. struct inode *old_inode = old_dentry->d_inode;
  889. struct inode *new_inode = new_dentry->d_inode;
  890. struct ubifs_inode *old_inode_ui = ubifs_inode(old_inode);
  891. int err, release, sync = 0, move = (new_dir != old_dir);
  892. int is_dir = S_ISDIR(old_inode->i_mode);
  893. int unlink = !!new_inode;
  894. int new_sz = CALC_DENT_SIZE(new_dentry->d_name.len);
  895. int old_sz = CALC_DENT_SIZE(old_dentry->d_name.len);
  896. struct ubifs_budget_req req = { .new_dent = 1, .mod_dent = 1,
  897. .dirtied_ino = 3 };
  898. struct ubifs_budget_req ino_req = { .dirtied_ino = 1,
  899. .dirtied_ino_d = old_inode_ui->data_len };
  900. struct timespec time;
  901. /*
  902. * Budget request settings: deletion direntry, new direntry, removing
  903. * the old inode, and changing old and new parent directory inodes.
  904. *
  905. * However, this operation also marks the target inode as dirty and
  906. * does not write it, so we allocate budget for the target inode
  907. * separately.
  908. */
  909. dbg_gen("dent '%.*s' ino %lu in dir ino %lu to dent '%.*s' in "
  910. "dir ino %lu", old_dentry->d_name.len, old_dentry->d_name.name,
  911. old_inode->i_ino, old_dir->i_ino, new_dentry->d_name.len,
  912. new_dentry->d_name.name, new_dir->i_ino);
  913. if (unlink && is_dir) {
  914. err = check_dir_empty(c, new_inode);
  915. if (err)
  916. return err;
  917. }
  918. err = ubifs_budget_space(c, &req);
  919. if (err)
  920. return err;
  921. err = ubifs_budget_space(c, &ino_req);
  922. if (err) {
  923. ubifs_release_budget(c, &req);
  924. return err;
  925. }
  926. lock_3_inodes(old_dir, new_dir, new_inode);
  927. /*
  928. * Like most other Unix systems, set the @i_ctime for inodes on a
  929. * rename.
  930. */
  931. time = ubifs_current_time(old_dir);
  932. old_inode->i_ctime = time;
  933. /* We must adjust parent link count when renaming directories */
  934. if (is_dir) {
  935. if (move) {
  936. /*
  937. * @old_dir loses a link because we are moving
  938. * @old_inode to a different directory.
  939. */
  940. drop_nlink(old_dir);
  941. /*
  942. * @new_dir only gains a link if we are not also
  943. * overwriting an existing directory.
  944. */
  945. if (!unlink)
  946. inc_nlink(new_dir);
  947. } else {
  948. /*
  949. * @old_inode is not moving to a different directory,
  950. * but @old_dir still loses a link if we are
  951. * overwriting an existing directory.
  952. */
  953. if (unlink)
  954. drop_nlink(old_dir);
  955. }
  956. }
  957. old_dir->i_size -= old_sz;
  958. ubifs_inode(old_dir)->ui_size = old_dir->i_size;
  959. old_dir->i_mtime = old_dir->i_ctime = time;
  960. new_dir->i_mtime = new_dir->i_ctime = time;
  961. /*
  962. * And finally, if we unlinked a direntry which happened to have the
  963. * same name as the moved direntry, we have to decrement @i_nlink of
  964. * the unlinked inode and change its ctime.
  965. */
  966. if (unlink) {
  967. /*
  968. * Directories cannot have hard-links, so if this is a
  969. * directory, decrement its @i_nlink twice because an empty
  970. * directory has @i_nlink 2.
  971. */
  972. if (is_dir)
  973. drop_nlink(new_inode);
  974. new_inode->i_ctime = time;
  975. drop_nlink(new_inode);
  976. } else {
  977. new_dir->i_size += new_sz;
  978. ubifs_inode(new_dir)->ui_size = new_dir->i_size;
  979. }
  980. /*
  981. * Do not ask 'ubifs_jnl_rename()' to flush write-buffer if @old_inode
  982. * is dirty, because this will be done later on at the end of
  983. * 'ubifs_rename()'.
  984. */
  985. if (IS_SYNC(old_inode)) {
  986. sync = IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir);
  987. if (unlink && IS_SYNC(new_inode))
  988. sync = 1;
  989. }
  990. err = ubifs_jnl_rename(c, old_dir, old_dentry, new_dir, new_dentry,
  991. sync);
  992. if (err)
  993. goto out_cancel;
  994. unlock_3_inodes(old_dir, new_dir, new_inode);
  995. ubifs_release_budget(c, &req);
  996. mutex_lock(&old_inode_ui->ui_mutex);
  997. release = old_inode_ui->dirty;
  998. mark_inode_dirty_sync(old_inode);
  999. mutex_unlock(&old_inode_ui->ui_mutex);
  1000. if (release)
  1001. ubifs_release_budget(c, &ino_req);
  1002. if (IS_SYNC(old_inode))
  1003. err = old_inode->i_sb->s_op->write_inode(old_inode, 1);
  1004. return err;
  1005. out_cancel:
  1006. if (unlink) {
  1007. if (is_dir)
  1008. inc_nlink(new_inode);
  1009. inc_nlink(new_inode);
  1010. } else {
  1011. new_dir->i_size -= new_sz;
  1012. ubifs_inode(new_dir)->ui_size = new_dir->i_size;
  1013. }
  1014. old_dir->i_size += old_sz;
  1015. ubifs_inode(old_dir)->ui_size = old_dir->i_size;
  1016. if (is_dir) {
  1017. if (move) {
  1018. inc_nlink(old_dir);
  1019. if (!unlink)
  1020. drop_nlink(new_dir);
  1021. } else {
  1022. if (unlink)
  1023. inc_nlink(old_dir);
  1024. }
  1025. }
  1026. unlock_3_inodes(old_dir, new_dir, new_inode);
  1027. ubifs_release_budget(c, &ino_req);
  1028. ubifs_release_budget(c, &req);
  1029. return err;
  1030. }
  1031. int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  1032. struct kstat *stat)
  1033. {
  1034. loff_t size;
  1035. struct inode *inode = dentry->d_inode;
  1036. struct ubifs_inode *ui = ubifs_inode(inode);
  1037. mutex_lock(&ui->ui_mutex);
  1038. stat->dev = inode->i_sb->s_dev;
  1039. stat->ino = inode->i_ino;
  1040. stat->mode = inode->i_mode;
  1041. stat->nlink = inode->i_nlink;
  1042. stat->uid = inode->i_uid;
  1043. stat->gid = inode->i_gid;
  1044. stat->rdev = inode->i_rdev;
  1045. stat->atime = inode->i_atime;
  1046. stat->mtime = inode->i_mtime;
  1047. stat->ctime = inode->i_ctime;
  1048. stat->blksize = UBIFS_BLOCK_SIZE;
  1049. stat->size = ui->ui_size;
  1050. /*
  1051. * Unfortunately, the 'stat()' system call was designed for block
  1052. * device based file systems, and it is not appropriate for UBIFS,
  1053. * because UBIFS does not have notion of "block". For example, it is
  1054. * difficult to tell how many block a directory takes - it actually
  1055. * takes less than 300 bytes, but we have to round it to block size,
  1056. * which introduces large mistake. This makes utilities like 'du' to
  1057. * report completely senseless numbers. This is the reason why UBIFS
  1058. * goes the same way as JFFS2 - it reports zero blocks for everything
  1059. * but regular files, which makes more sense than reporting completely
  1060. * wrong sizes.
  1061. */
  1062. if (S_ISREG(inode->i_mode)) {
  1063. size = ui->xattr_size;
  1064. size += stat->size;
  1065. size = ALIGN(size, UBIFS_BLOCK_SIZE);
  1066. /*
  1067. * Note, user-space expects 512-byte blocks count irrespectively
  1068. * of what was reported in @stat->size.
  1069. */
  1070. stat->blocks = size >> 9;
  1071. } else
  1072. stat->blocks = 0;
  1073. mutex_unlock(&ui->ui_mutex);
  1074. return 0;
  1075. }
  1076. struct inode_operations ubifs_dir_inode_operations = {
  1077. .lookup = ubifs_lookup,
  1078. .create = ubifs_create,
  1079. .link = ubifs_link,
  1080. .symlink = ubifs_symlink,
  1081. .unlink = ubifs_unlink,
  1082. .mkdir = ubifs_mkdir,
  1083. .rmdir = ubifs_rmdir,
  1084. .mknod = ubifs_mknod,
  1085. .rename = ubifs_rename,
  1086. .setattr = ubifs_setattr,
  1087. .getattr = ubifs_getattr,
  1088. #ifdef CONFIG_UBIFS_FS_XATTR
  1089. .setxattr = ubifs_setxattr,
  1090. .getxattr = ubifs_getxattr,
  1091. .listxattr = ubifs_listxattr,
  1092. .removexattr = ubifs_removexattr,
  1093. #endif
  1094. };
  1095. struct file_operations ubifs_dir_operations = {
  1096. .llseek = ubifs_dir_llseek,
  1097. .release = ubifs_dir_release,
  1098. .read = generic_read_dir,
  1099. .readdir = ubifs_readdir,
  1100. .fsync = ubifs_fsync,
  1101. .unlocked_ioctl = ubifs_ioctl,
  1102. #ifdef CONFIG_COMPAT
  1103. .compat_ioctl = ubifs_compat_ioctl,
  1104. #endif
  1105. };