dir.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  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. err = dbg_check_synced_i_size(inode);
  467. if (err)
  468. return err;
  469. err = ubifs_budget_space(c, &req);
  470. if (err)
  471. return err;
  472. lock_2_inodes(dir, inode);
  473. inc_nlink(inode);
  474. ihold(inode);
  475. inode->i_ctime = ubifs_current_time(inode);
  476. dir->i_size += sz_change;
  477. dir_ui->ui_size = dir->i_size;
  478. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  479. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
  480. if (err)
  481. goto out_cancel;
  482. unlock_2_inodes(dir, inode);
  483. ubifs_release_budget(c, &req);
  484. d_instantiate(dentry, inode);
  485. return 0;
  486. out_cancel:
  487. dir->i_size -= sz_change;
  488. dir_ui->ui_size = dir->i_size;
  489. drop_nlink(inode);
  490. unlock_2_inodes(dir, inode);
  491. ubifs_release_budget(c, &req);
  492. iput(inode);
  493. return err;
  494. }
  495. static int ubifs_unlink(struct inode *dir, struct dentry *dentry)
  496. {
  497. struct ubifs_info *c = dir->i_sb->s_fs_info;
  498. struct inode *inode = dentry->d_inode;
  499. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  500. int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  501. int err, budgeted = 1;
  502. struct ubifs_budget_req req = { .mod_dent = 1, .dirtied_ino = 2 };
  503. /*
  504. * Budget request settings: deletion direntry, deletion inode (+1 for
  505. * @dirtied_ino), changing the parent directory inode. If budgeting
  506. * fails, go ahead anyway because we have extra space reserved for
  507. * deletions.
  508. */
  509. dbg_gen("dent '%.*s' from ino %lu (nlink %d) in dir ino %lu",
  510. dentry->d_name.len, dentry->d_name.name, inode->i_ino,
  511. inode->i_nlink, dir->i_ino);
  512. ubifs_assert(mutex_is_locked(&dir->i_mutex));
  513. ubifs_assert(mutex_is_locked(&inode->i_mutex));
  514. err = dbg_check_synced_i_size(inode);
  515. if (err)
  516. return err;
  517. err = ubifs_budget_space(c, &req);
  518. if (err) {
  519. if (err != -ENOSPC)
  520. return err;
  521. budgeted = 0;
  522. }
  523. lock_2_inodes(dir, inode);
  524. inode->i_ctime = ubifs_current_time(dir);
  525. drop_nlink(inode);
  526. dir->i_size -= sz_change;
  527. dir_ui->ui_size = dir->i_size;
  528. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  529. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 1, 0);
  530. if (err)
  531. goto out_cancel;
  532. unlock_2_inodes(dir, inode);
  533. if (budgeted)
  534. ubifs_release_budget(c, &req);
  535. else {
  536. /* We've deleted something - clean the "no space" flags */
  537. c->bi.nospace = c->bi.nospace_rp = 0;
  538. smp_wmb();
  539. }
  540. return 0;
  541. out_cancel:
  542. dir->i_size += sz_change;
  543. dir_ui->ui_size = dir->i_size;
  544. inc_nlink(inode);
  545. unlock_2_inodes(dir, inode);
  546. if (budgeted)
  547. ubifs_release_budget(c, &req);
  548. return err;
  549. }
  550. /**
  551. * check_dir_empty - check if a directory is empty or not.
  552. * @c: UBIFS file-system description object
  553. * @dir: VFS inode object of the directory to check
  554. *
  555. * This function checks if directory @dir is empty. Returns zero if the
  556. * directory is empty, %-ENOTEMPTY if it is not, and other negative error codes
  557. * in case of of errors.
  558. */
  559. static int check_dir_empty(struct ubifs_info *c, struct inode *dir)
  560. {
  561. struct qstr nm = { .name = NULL };
  562. struct ubifs_dent_node *dent;
  563. union ubifs_key key;
  564. int err;
  565. lowest_dent_key(c, &key, dir->i_ino);
  566. dent = ubifs_tnc_next_ent(c, &key, &nm);
  567. if (IS_ERR(dent)) {
  568. err = PTR_ERR(dent);
  569. if (err == -ENOENT)
  570. err = 0;
  571. } else {
  572. kfree(dent);
  573. err = -ENOTEMPTY;
  574. }
  575. return err;
  576. }
  577. static int ubifs_rmdir(struct inode *dir, struct dentry *dentry)
  578. {
  579. struct ubifs_info *c = dir->i_sb->s_fs_info;
  580. struct inode *inode = dentry->d_inode;
  581. int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  582. int err, budgeted = 1;
  583. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  584. struct ubifs_budget_req req = { .mod_dent = 1, .dirtied_ino = 2 };
  585. /*
  586. * Budget request settings: deletion direntry, deletion inode and
  587. * changing the parent inode. If budgeting fails, go ahead anyway
  588. * because we have extra space reserved for deletions.
  589. */
  590. dbg_gen("directory '%.*s', ino %lu in dir ino %lu", dentry->d_name.len,
  591. dentry->d_name.name, inode->i_ino, dir->i_ino);
  592. ubifs_assert(mutex_is_locked(&dir->i_mutex));
  593. ubifs_assert(mutex_is_locked(&inode->i_mutex));
  594. err = check_dir_empty(c, dentry->d_inode);
  595. if (err)
  596. return err;
  597. err = ubifs_budget_space(c, &req);
  598. if (err) {
  599. if (err != -ENOSPC)
  600. return err;
  601. budgeted = 0;
  602. }
  603. lock_2_inodes(dir, inode);
  604. inode->i_ctime = ubifs_current_time(dir);
  605. clear_nlink(inode);
  606. drop_nlink(dir);
  607. dir->i_size -= sz_change;
  608. dir_ui->ui_size = dir->i_size;
  609. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  610. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 1, 0);
  611. if (err)
  612. goto out_cancel;
  613. unlock_2_inodes(dir, inode);
  614. if (budgeted)
  615. ubifs_release_budget(c, &req);
  616. else {
  617. /* We've deleted something - clean the "no space" flags */
  618. c->bi.nospace = c->bi.nospace_rp = 0;
  619. smp_wmb();
  620. }
  621. return 0;
  622. out_cancel:
  623. dir->i_size += sz_change;
  624. dir_ui->ui_size = dir->i_size;
  625. inc_nlink(dir);
  626. inc_nlink(inode);
  627. inc_nlink(inode);
  628. unlock_2_inodes(dir, inode);
  629. if (budgeted)
  630. ubifs_release_budget(c, &req);
  631. return err;
  632. }
  633. static int ubifs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
  634. {
  635. struct inode *inode;
  636. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  637. struct ubifs_info *c = dir->i_sb->s_fs_info;
  638. int err, sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  639. struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1 };
  640. /*
  641. * Budget request settings: new inode, new direntry and changing parent
  642. * directory inode.
  643. */
  644. dbg_gen("dent '%.*s', mode %#x in dir ino %lu",
  645. dentry->d_name.len, dentry->d_name.name, mode, dir->i_ino);
  646. err = ubifs_budget_space(c, &req);
  647. if (err)
  648. return err;
  649. inode = ubifs_new_inode(c, dir, S_IFDIR | mode);
  650. if (IS_ERR(inode)) {
  651. err = PTR_ERR(inode);
  652. goto out_budg;
  653. }
  654. mutex_lock(&dir_ui->ui_mutex);
  655. insert_inode_hash(inode);
  656. inc_nlink(inode);
  657. inc_nlink(dir);
  658. dir->i_size += sz_change;
  659. dir_ui->ui_size = dir->i_size;
  660. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  661. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
  662. if (err) {
  663. ubifs_err("cannot create directory, error %d", err);
  664. goto out_cancel;
  665. }
  666. mutex_unlock(&dir_ui->ui_mutex);
  667. ubifs_release_budget(c, &req);
  668. d_instantiate(dentry, inode);
  669. return 0;
  670. out_cancel:
  671. dir->i_size -= sz_change;
  672. dir_ui->ui_size = dir->i_size;
  673. drop_nlink(dir);
  674. mutex_unlock(&dir_ui->ui_mutex);
  675. make_bad_inode(inode);
  676. iput(inode);
  677. out_budg:
  678. ubifs_release_budget(c, &req);
  679. return err;
  680. }
  681. static int ubifs_mknod(struct inode *dir, struct dentry *dentry,
  682. int mode, dev_t rdev)
  683. {
  684. struct inode *inode;
  685. struct ubifs_inode *ui;
  686. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  687. struct ubifs_info *c = dir->i_sb->s_fs_info;
  688. union ubifs_dev_desc *dev = NULL;
  689. int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  690. int err, devlen = 0;
  691. struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
  692. .new_ino_d = ALIGN(devlen, 8),
  693. .dirtied_ino = 1 };
  694. /*
  695. * Budget request settings: new inode, new direntry and changing parent
  696. * directory inode.
  697. */
  698. dbg_gen("dent '%.*s' in dir ino %lu",
  699. dentry->d_name.len, dentry->d_name.name, dir->i_ino);
  700. if (!new_valid_dev(rdev))
  701. return -EINVAL;
  702. if (S_ISBLK(mode) || S_ISCHR(mode)) {
  703. dev = kmalloc(sizeof(union ubifs_dev_desc), GFP_NOFS);
  704. if (!dev)
  705. return -ENOMEM;
  706. devlen = ubifs_encode_dev(dev, rdev);
  707. }
  708. err = ubifs_budget_space(c, &req);
  709. if (err) {
  710. kfree(dev);
  711. return err;
  712. }
  713. inode = ubifs_new_inode(c, dir, mode);
  714. if (IS_ERR(inode)) {
  715. kfree(dev);
  716. err = PTR_ERR(inode);
  717. goto out_budg;
  718. }
  719. init_special_inode(inode, inode->i_mode, rdev);
  720. inode->i_size = ubifs_inode(inode)->ui_size = devlen;
  721. ui = ubifs_inode(inode);
  722. ui->data = dev;
  723. ui->data_len = devlen;
  724. mutex_lock(&dir_ui->ui_mutex);
  725. dir->i_size += sz_change;
  726. dir_ui->ui_size = dir->i_size;
  727. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  728. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
  729. if (err)
  730. goto out_cancel;
  731. mutex_unlock(&dir_ui->ui_mutex);
  732. ubifs_release_budget(c, &req);
  733. insert_inode_hash(inode);
  734. d_instantiate(dentry, inode);
  735. return 0;
  736. out_cancel:
  737. dir->i_size -= sz_change;
  738. dir_ui->ui_size = dir->i_size;
  739. mutex_unlock(&dir_ui->ui_mutex);
  740. make_bad_inode(inode);
  741. iput(inode);
  742. out_budg:
  743. ubifs_release_budget(c, &req);
  744. return err;
  745. }
  746. static int ubifs_symlink(struct inode *dir, struct dentry *dentry,
  747. const char *symname)
  748. {
  749. struct inode *inode;
  750. struct ubifs_inode *ui;
  751. struct ubifs_inode *dir_ui = ubifs_inode(dir);
  752. struct ubifs_info *c = dir->i_sb->s_fs_info;
  753. int err, len = strlen(symname);
  754. int sz_change = CALC_DENT_SIZE(dentry->d_name.len);
  755. struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
  756. .new_ino_d = ALIGN(len, 8),
  757. .dirtied_ino = 1 };
  758. /*
  759. * Budget request settings: new inode, new direntry and changing parent
  760. * directory inode.
  761. */
  762. dbg_gen("dent '%.*s', target '%s' in dir ino %lu", dentry->d_name.len,
  763. dentry->d_name.name, symname, dir->i_ino);
  764. if (len > UBIFS_MAX_INO_DATA)
  765. return -ENAMETOOLONG;
  766. err = ubifs_budget_space(c, &req);
  767. if (err)
  768. return err;
  769. inode = ubifs_new_inode(c, dir, S_IFLNK | S_IRWXUGO);
  770. if (IS_ERR(inode)) {
  771. err = PTR_ERR(inode);
  772. goto out_budg;
  773. }
  774. ui = ubifs_inode(inode);
  775. ui->data = kmalloc(len + 1, GFP_NOFS);
  776. if (!ui->data) {
  777. err = -ENOMEM;
  778. goto out_inode;
  779. }
  780. memcpy(ui->data, symname, len);
  781. ((char *)ui->data)[len] = '\0';
  782. /*
  783. * The terminating zero byte is not written to the flash media and it
  784. * is put just to make later in-memory string processing simpler. Thus,
  785. * data length is @len, not @len + %1.
  786. */
  787. ui->data_len = len;
  788. inode->i_size = ubifs_inode(inode)->ui_size = len;
  789. mutex_lock(&dir_ui->ui_mutex);
  790. dir->i_size += sz_change;
  791. dir_ui->ui_size = dir->i_size;
  792. dir->i_mtime = dir->i_ctime = inode->i_ctime;
  793. err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 0, 0);
  794. if (err)
  795. goto out_cancel;
  796. mutex_unlock(&dir_ui->ui_mutex);
  797. ubifs_release_budget(c, &req);
  798. insert_inode_hash(inode);
  799. d_instantiate(dentry, inode);
  800. return 0;
  801. out_cancel:
  802. dir->i_size -= sz_change;
  803. dir_ui->ui_size = dir->i_size;
  804. mutex_unlock(&dir_ui->ui_mutex);
  805. out_inode:
  806. make_bad_inode(inode);
  807. iput(inode);
  808. out_budg:
  809. ubifs_release_budget(c, &req);
  810. return err;
  811. }
  812. /**
  813. * lock_3_inodes - a wrapper for locking three UBIFS inodes.
  814. * @inode1: first inode
  815. * @inode2: second inode
  816. * @inode3: third inode
  817. *
  818. * This function is used for 'ubifs_rename()' and @inode1 may be the same as
  819. * @inode2 whereas @inode3 may be %NULL.
  820. *
  821. * We do not implement any tricks to guarantee strict lock ordering, because
  822. * VFS has already done it for us on the @i_mutex. So this is just a simple
  823. * wrapper function.
  824. */
  825. static void lock_3_inodes(struct inode *inode1, struct inode *inode2,
  826. struct inode *inode3)
  827. {
  828. mutex_lock_nested(&ubifs_inode(inode1)->ui_mutex, WB_MUTEX_1);
  829. if (inode2 != inode1)
  830. mutex_lock_nested(&ubifs_inode(inode2)->ui_mutex, WB_MUTEX_2);
  831. if (inode3)
  832. mutex_lock_nested(&ubifs_inode(inode3)->ui_mutex, WB_MUTEX_3);
  833. }
  834. /**
  835. * unlock_3_inodes - a wrapper for unlocking three UBIFS inodes for rename.
  836. * @inode1: first inode
  837. * @inode2: second inode
  838. * @inode3: third inode
  839. */
  840. static void unlock_3_inodes(struct inode *inode1, struct inode *inode2,
  841. struct inode *inode3)
  842. {
  843. if (inode3)
  844. mutex_unlock(&ubifs_inode(inode3)->ui_mutex);
  845. if (inode1 != inode2)
  846. mutex_unlock(&ubifs_inode(inode2)->ui_mutex);
  847. mutex_unlock(&ubifs_inode(inode1)->ui_mutex);
  848. }
  849. static int ubifs_rename(struct inode *old_dir, struct dentry *old_dentry,
  850. struct inode *new_dir, struct dentry *new_dentry)
  851. {
  852. struct ubifs_info *c = old_dir->i_sb->s_fs_info;
  853. struct inode *old_inode = old_dentry->d_inode;
  854. struct inode *new_inode = new_dentry->d_inode;
  855. struct ubifs_inode *old_inode_ui = ubifs_inode(old_inode);
  856. int err, release, sync = 0, move = (new_dir != old_dir);
  857. int is_dir = S_ISDIR(old_inode->i_mode);
  858. int unlink = !!new_inode;
  859. int new_sz = CALC_DENT_SIZE(new_dentry->d_name.len);
  860. int old_sz = CALC_DENT_SIZE(old_dentry->d_name.len);
  861. struct ubifs_budget_req req = { .new_dent = 1, .mod_dent = 1,
  862. .dirtied_ino = 3 };
  863. struct ubifs_budget_req ino_req = { .dirtied_ino = 1,
  864. .dirtied_ino_d = ALIGN(old_inode_ui->data_len, 8) };
  865. struct timespec time;
  866. /*
  867. * Budget request settings: deletion direntry, new direntry, removing
  868. * the old inode, and changing old and new parent directory inodes.
  869. *
  870. * However, this operation also marks the target inode as dirty and
  871. * does not write it, so we allocate budget for the target inode
  872. * separately.
  873. */
  874. dbg_gen("dent '%.*s' ino %lu in dir ino %lu to dent '%.*s' in "
  875. "dir ino %lu", old_dentry->d_name.len, old_dentry->d_name.name,
  876. old_inode->i_ino, old_dir->i_ino, new_dentry->d_name.len,
  877. new_dentry->d_name.name, new_dir->i_ino);
  878. ubifs_assert(mutex_is_locked(&old_dir->i_mutex));
  879. ubifs_assert(mutex_is_locked(&new_dir->i_mutex));
  880. if (unlink)
  881. ubifs_assert(mutex_is_locked(&new_inode->i_mutex));
  882. if (unlink && is_dir) {
  883. err = check_dir_empty(c, new_inode);
  884. if (err)
  885. return err;
  886. }
  887. err = ubifs_budget_space(c, &req);
  888. if (err)
  889. return err;
  890. err = ubifs_budget_space(c, &ino_req);
  891. if (err) {
  892. ubifs_release_budget(c, &req);
  893. return err;
  894. }
  895. lock_3_inodes(old_dir, new_dir, new_inode);
  896. /*
  897. * Like most other Unix systems, set the @i_ctime for inodes on a
  898. * rename.
  899. */
  900. time = ubifs_current_time(old_dir);
  901. old_inode->i_ctime = time;
  902. /* We must adjust parent link count when renaming directories */
  903. if (is_dir) {
  904. if (move) {
  905. /*
  906. * @old_dir loses a link because we are moving
  907. * @old_inode to a different directory.
  908. */
  909. drop_nlink(old_dir);
  910. /*
  911. * @new_dir only gains a link if we are not also
  912. * overwriting an existing directory.
  913. */
  914. if (!unlink)
  915. inc_nlink(new_dir);
  916. } else {
  917. /*
  918. * @old_inode is not moving to a different directory,
  919. * but @old_dir still loses a link if we are
  920. * overwriting an existing directory.
  921. */
  922. if (unlink)
  923. drop_nlink(old_dir);
  924. }
  925. }
  926. old_dir->i_size -= old_sz;
  927. ubifs_inode(old_dir)->ui_size = old_dir->i_size;
  928. old_dir->i_mtime = old_dir->i_ctime = time;
  929. new_dir->i_mtime = new_dir->i_ctime = time;
  930. /*
  931. * And finally, if we unlinked a direntry which happened to have the
  932. * same name as the moved direntry, we have to decrement @i_nlink of
  933. * the unlinked inode and change its ctime.
  934. */
  935. if (unlink) {
  936. /*
  937. * Directories cannot have hard-links, so if this is a
  938. * directory, decrement its @i_nlink twice because an empty
  939. * directory has @i_nlink 2.
  940. */
  941. if (is_dir)
  942. drop_nlink(new_inode);
  943. new_inode->i_ctime = time;
  944. drop_nlink(new_inode);
  945. } else {
  946. new_dir->i_size += new_sz;
  947. ubifs_inode(new_dir)->ui_size = new_dir->i_size;
  948. }
  949. /*
  950. * Do not ask 'ubifs_jnl_rename()' to flush write-buffer if @old_inode
  951. * is dirty, because this will be done later on at the end of
  952. * 'ubifs_rename()'.
  953. */
  954. if (IS_SYNC(old_inode)) {
  955. sync = IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir);
  956. if (unlink && IS_SYNC(new_inode))
  957. sync = 1;
  958. }
  959. err = ubifs_jnl_rename(c, old_dir, old_dentry, new_dir, new_dentry,
  960. sync);
  961. if (err)
  962. goto out_cancel;
  963. unlock_3_inodes(old_dir, new_dir, new_inode);
  964. ubifs_release_budget(c, &req);
  965. mutex_lock(&old_inode_ui->ui_mutex);
  966. release = old_inode_ui->dirty;
  967. mark_inode_dirty_sync(old_inode);
  968. mutex_unlock(&old_inode_ui->ui_mutex);
  969. if (release)
  970. ubifs_release_budget(c, &ino_req);
  971. if (IS_SYNC(old_inode))
  972. err = old_inode->i_sb->s_op->write_inode(old_inode, NULL);
  973. return err;
  974. out_cancel:
  975. if (unlink) {
  976. if (is_dir)
  977. inc_nlink(new_inode);
  978. inc_nlink(new_inode);
  979. } else {
  980. new_dir->i_size -= new_sz;
  981. ubifs_inode(new_dir)->ui_size = new_dir->i_size;
  982. }
  983. old_dir->i_size += old_sz;
  984. ubifs_inode(old_dir)->ui_size = old_dir->i_size;
  985. if (is_dir) {
  986. if (move) {
  987. inc_nlink(old_dir);
  988. if (!unlink)
  989. drop_nlink(new_dir);
  990. } else {
  991. if (unlink)
  992. inc_nlink(old_dir);
  993. }
  994. }
  995. unlock_3_inodes(old_dir, new_dir, new_inode);
  996. ubifs_release_budget(c, &ino_req);
  997. ubifs_release_budget(c, &req);
  998. return err;
  999. }
  1000. int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  1001. struct kstat *stat)
  1002. {
  1003. loff_t size;
  1004. struct inode *inode = dentry->d_inode;
  1005. struct ubifs_inode *ui = ubifs_inode(inode);
  1006. mutex_lock(&ui->ui_mutex);
  1007. stat->dev = inode->i_sb->s_dev;
  1008. stat->ino = inode->i_ino;
  1009. stat->mode = inode->i_mode;
  1010. stat->nlink = inode->i_nlink;
  1011. stat->uid = inode->i_uid;
  1012. stat->gid = inode->i_gid;
  1013. stat->rdev = inode->i_rdev;
  1014. stat->atime = inode->i_atime;
  1015. stat->mtime = inode->i_mtime;
  1016. stat->ctime = inode->i_ctime;
  1017. stat->blksize = UBIFS_BLOCK_SIZE;
  1018. stat->size = ui->ui_size;
  1019. /*
  1020. * Unfortunately, the 'stat()' system call was designed for block
  1021. * device based file systems, and it is not appropriate for UBIFS,
  1022. * because UBIFS does not have notion of "block". For example, it is
  1023. * difficult to tell how many block a directory takes - it actually
  1024. * takes less than 300 bytes, but we have to round it to block size,
  1025. * which introduces large mistake. This makes utilities like 'du' to
  1026. * report completely senseless numbers. This is the reason why UBIFS
  1027. * goes the same way as JFFS2 - it reports zero blocks for everything
  1028. * but regular files, which makes more sense than reporting completely
  1029. * wrong sizes.
  1030. */
  1031. if (S_ISREG(inode->i_mode)) {
  1032. size = ui->xattr_size;
  1033. size += stat->size;
  1034. size = ALIGN(size, UBIFS_BLOCK_SIZE);
  1035. /*
  1036. * Note, user-space expects 512-byte blocks count irrespectively
  1037. * of what was reported in @stat->size.
  1038. */
  1039. stat->blocks = size >> 9;
  1040. } else
  1041. stat->blocks = 0;
  1042. mutex_unlock(&ui->ui_mutex);
  1043. return 0;
  1044. }
  1045. const struct inode_operations ubifs_dir_inode_operations = {
  1046. .lookup = ubifs_lookup,
  1047. .create = ubifs_create,
  1048. .link = ubifs_link,
  1049. .symlink = ubifs_symlink,
  1050. .unlink = ubifs_unlink,
  1051. .mkdir = ubifs_mkdir,
  1052. .rmdir = ubifs_rmdir,
  1053. .mknod = ubifs_mknod,
  1054. .rename = ubifs_rename,
  1055. .setattr = ubifs_setattr,
  1056. .getattr = ubifs_getattr,
  1057. #ifdef CONFIG_UBIFS_FS_XATTR
  1058. .setxattr = ubifs_setxattr,
  1059. .getxattr = ubifs_getxattr,
  1060. .listxattr = ubifs_listxattr,
  1061. .removexattr = ubifs_removexattr,
  1062. #endif
  1063. };
  1064. const struct file_operations ubifs_dir_operations = {
  1065. .llseek = ubifs_dir_llseek,
  1066. .release = ubifs_dir_release,
  1067. .read = generic_read_dir,
  1068. .readdir = ubifs_readdir,
  1069. .fsync = ubifs_fsync,
  1070. .unlocked_ioctl = ubifs_ioctl,
  1071. #ifdef CONFIG_COMPAT
  1072. .compat_ioctl = ubifs_compat_ioctl,
  1073. #endif
  1074. };