dir.c 32 KB

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