dir.c 33 KB

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