dir.c 33 KB

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