dir.c 33 KB

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