super.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323
  1. /*
  2. * This file is part of UBIFS.
  3. *
  4. * Copyright (C) 2006-2008 Nokia Corporation.
  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. */
  22. /*
  23. * This file implements UBIFS initialization and VFS superblock operations. Some
  24. * initialization stuff which is rather large and complex is placed at
  25. * corresponding subsystems, but most of it is here.
  26. */
  27. #include <linux/init.h>
  28. #include <linux/slab.h>
  29. #include <linux/module.h>
  30. #include <linux/ctype.h>
  31. #include <linux/kthread.h>
  32. #include <linux/parser.h>
  33. #include <linux/seq_file.h>
  34. #include <linux/mount.h>
  35. #include <linux/math64.h>
  36. #include <linux/writeback.h>
  37. #include "ubifs.h"
  38. /*
  39. * Maximum amount of memory we may 'kmalloc()' without worrying that we are
  40. * allocating too much.
  41. */
  42. #define UBIFS_KMALLOC_OK (128*1024)
  43. /* Slab cache for UBIFS inodes */
  44. struct kmem_cache *ubifs_inode_slab;
  45. /* UBIFS TNC shrinker description */
  46. static struct shrinker ubifs_shrinker_info = {
  47. .shrink = ubifs_shrinker,
  48. .seeks = DEFAULT_SEEKS,
  49. };
  50. /**
  51. * validate_inode - validate inode.
  52. * @c: UBIFS file-system description object
  53. * @inode: the inode to validate
  54. *
  55. * This is a helper function for 'ubifs_iget()' which validates various fields
  56. * of a newly built inode to make sure they contain sane values and prevent
  57. * possible vulnerabilities. Returns zero if the inode is all right and
  58. * a non-zero error code if not.
  59. */
  60. static int validate_inode(struct ubifs_info *c, const struct inode *inode)
  61. {
  62. int err;
  63. const struct ubifs_inode *ui = ubifs_inode(inode);
  64. if (inode->i_size > c->max_inode_sz) {
  65. ubifs_err("inode is too large (%lld)",
  66. (long long)inode->i_size);
  67. return 1;
  68. }
  69. if (ui->compr_type < 0 || ui->compr_type >= UBIFS_COMPR_TYPES_CNT) {
  70. ubifs_err("unknown compression type %d", ui->compr_type);
  71. return 2;
  72. }
  73. if (ui->xattr_names + ui->xattr_cnt > XATTR_LIST_MAX)
  74. return 3;
  75. if (ui->data_len < 0 || ui->data_len > UBIFS_MAX_INO_DATA)
  76. return 4;
  77. if (ui->xattr && !S_ISREG(inode->i_mode))
  78. return 5;
  79. if (!ubifs_compr_present(ui->compr_type)) {
  80. ubifs_warn("inode %lu uses '%s' compression, but it was not "
  81. "compiled in", inode->i_ino,
  82. ubifs_compr_name(ui->compr_type));
  83. }
  84. err = dbg_check_dir(c, inode);
  85. return err;
  86. }
  87. struct inode *ubifs_iget(struct super_block *sb, unsigned long inum)
  88. {
  89. int err;
  90. union ubifs_key key;
  91. struct ubifs_ino_node *ino;
  92. struct ubifs_info *c = sb->s_fs_info;
  93. struct inode *inode;
  94. struct ubifs_inode *ui;
  95. dbg_gen("inode %lu", inum);
  96. inode = iget_locked(sb, inum);
  97. if (!inode)
  98. return ERR_PTR(-ENOMEM);
  99. if (!(inode->i_state & I_NEW))
  100. return inode;
  101. ui = ubifs_inode(inode);
  102. ino = kmalloc(UBIFS_MAX_INO_NODE_SZ, GFP_NOFS);
  103. if (!ino) {
  104. err = -ENOMEM;
  105. goto out;
  106. }
  107. ino_key_init(c, &key, inode->i_ino);
  108. err = ubifs_tnc_lookup(c, &key, ino);
  109. if (err)
  110. goto out_ino;
  111. inode->i_flags |= (S_NOCMTIME | S_NOATIME);
  112. set_nlink(inode, le32_to_cpu(ino->nlink));
  113. inode->i_uid = le32_to_cpu(ino->uid);
  114. inode->i_gid = le32_to_cpu(ino->gid);
  115. inode->i_atime.tv_sec = (int64_t)le64_to_cpu(ino->atime_sec);
  116. inode->i_atime.tv_nsec = le32_to_cpu(ino->atime_nsec);
  117. inode->i_mtime.tv_sec = (int64_t)le64_to_cpu(ino->mtime_sec);
  118. inode->i_mtime.tv_nsec = le32_to_cpu(ino->mtime_nsec);
  119. inode->i_ctime.tv_sec = (int64_t)le64_to_cpu(ino->ctime_sec);
  120. inode->i_ctime.tv_nsec = le32_to_cpu(ino->ctime_nsec);
  121. inode->i_mode = le32_to_cpu(ino->mode);
  122. inode->i_size = le64_to_cpu(ino->size);
  123. ui->data_len = le32_to_cpu(ino->data_len);
  124. ui->flags = le32_to_cpu(ino->flags);
  125. ui->compr_type = le16_to_cpu(ino->compr_type);
  126. ui->creat_sqnum = le64_to_cpu(ino->creat_sqnum);
  127. ui->xattr_cnt = le32_to_cpu(ino->xattr_cnt);
  128. ui->xattr_size = le32_to_cpu(ino->xattr_size);
  129. ui->xattr_names = le32_to_cpu(ino->xattr_names);
  130. ui->synced_i_size = ui->ui_size = inode->i_size;
  131. ui->xattr = (ui->flags & UBIFS_XATTR_FL) ? 1 : 0;
  132. err = validate_inode(c, inode);
  133. if (err)
  134. goto out_invalid;
  135. /* Disable read-ahead */
  136. inode->i_mapping->backing_dev_info = &c->bdi;
  137. switch (inode->i_mode & S_IFMT) {
  138. case S_IFREG:
  139. inode->i_mapping->a_ops = &ubifs_file_address_operations;
  140. inode->i_op = &ubifs_file_inode_operations;
  141. inode->i_fop = &ubifs_file_operations;
  142. if (ui->xattr) {
  143. ui->data = kmalloc(ui->data_len + 1, GFP_NOFS);
  144. if (!ui->data) {
  145. err = -ENOMEM;
  146. goto out_ino;
  147. }
  148. memcpy(ui->data, ino->data, ui->data_len);
  149. ((char *)ui->data)[ui->data_len] = '\0';
  150. } else if (ui->data_len != 0) {
  151. err = 10;
  152. goto out_invalid;
  153. }
  154. break;
  155. case S_IFDIR:
  156. inode->i_op = &ubifs_dir_inode_operations;
  157. inode->i_fop = &ubifs_dir_operations;
  158. if (ui->data_len != 0) {
  159. err = 11;
  160. goto out_invalid;
  161. }
  162. break;
  163. case S_IFLNK:
  164. inode->i_op = &ubifs_symlink_inode_operations;
  165. if (ui->data_len <= 0 || ui->data_len > UBIFS_MAX_INO_DATA) {
  166. err = 12;
  167. goto out_invalid;
  168. }
  169. ui->data = kmalloc(ui->data_len + 1, GFP_NOFS);
  170. if (!ui->data) {
  171. err = -ENOMEM;
  172. goto out_ino;
  173. }
  174. memcpy(ui->data, ino->data, ui->data_len);
  175. ((char *)ui->data)[ui->data_len] = '\0';
  176. break;
  177. case S_IFBLK:
  178. case S_IFCHR:
  179. {
  180. dev_t rdev;
  181. union ubifs_dev_desc *dev;
  182. ui->data = kmalloc(sizeof(union ubifs_dev_desc), GFP_NOFS);
  183. if (!ui->data) {
  184. err = -ENOMEM;
  185. goto out_ino;
  186. }
  187. dev = (union ubifs_dev_desc *)ino->data;
  188. if (ui->data_len == sizeof(dev->new))
  189. rdev = new_decode_dev(le32_to_cpu(dev->new));
  190. else if (ui->data_len == sizeof(dev->huge))
  191. rdev = huge_decode_dev(le64_to_cpu(dev->huge));
  192. else {
  193. err = 13;
  194. goto out_invalid;
  195. }
  196. memcpy(ui->data, ino->data, ui->data_len);
  197. inode->i_op = &ubifs_file_inode_operations;
  198. init_special_inode(inode, inode->i_mode, rdev);
  199. break;
  200. }
  201. case S_IFSOCK:
  202. case S_IFIFO:
  203. inode->i_op = &ubifs_file_inode_operations;
  204. init_special_inode(inode, inode->i_mode, 0);
  205. if (ui->data_len != 0) {
  206. err = 14;
  207. goto out_invalid;
  208. }
  209. break;
  210. default:
  211. err = 15;
  212. goto out_invalid;
  213. }
  214. kfree(ino);
  215. ubifs_set_inode_flags(inode);
  216. unlock_new_inode(inode);
  217. return inode;
  218. out_invalid:
  219. ubifs_err("inode %lu validation failed, error %d", inode->i_ino, err);
  220. dbg_dump_node(c, ino);
  221. dbg_dump_inode(c, inode);
  222. err = -EINVAL;
  223. out_ino:
  224. kfree(ino);
  225. out:
  226. ubifs_err("failed to read inode %lu, error %d", inode->i_ino, err);
  227. iget_failed(inode);
  228. return ERR_PTR(err);
  229. }
  230. static struct inode *ubifs_alloc_inode(struct super_block *sb)
  231. {
  232. struct ubifs_inode *ui;
  233. ui = kmem_cache_alloc(ubifs_inode_slab, GFP_NOFS);
  234. if (!ui)
  235. return NULL;
  236. memset((void *)ui + sizeof(struct inode), 0,
  237. sizeof(struct ubifs_inode) - sizeof(struct inode));
  238. mutex_init(&ui->ui_mutex);
  239. spin_lock_init(&ui->ui_lock);
  240. return &ui->vfs_inode;
  241. };
  242. static void ubifs_i_callback(struct rcu_head *head)
  243. {
  244. struct inode *inode = container_of(head, struct inode, i_rcu);
  245. struct ubifs_inode *ui = ubifs_inode(inode);
  246. kmem_cache_free(ubifs_inode_slab, ui);
  247. }
  248. static void ubifs_destroy_inode(struct inode *inode)
  249. {
  250. struct ubifs_inode *ui = ubifs_inode(inode);
  251. kfree(ui->data);
  252. call_rcu(&inode->i_rcu, ubifs_i_callback);
  253. }
  254. /*
  255. * Note, Linux write-back code calls this without 'i_mutex'.
  256. */
  257. static int ubifs_write_inode(struct inode *inode, struct writeback_control *wbc)
  258. {
  259. int err = 0;
  260. struct ubifs_info *c = inode->i_sb->s_fs_info;
  261. struct ubifs_inode *ui = ubifs_inode(inode);
  262. ubifs_assert(!ui->xattr);
  263. if (is_bad_inode(inode))
  264. return 0;
  265. mutex_lock(&ui->ui_mutex);
  266. /*
  267. * Due to races between write-back forced by budgeting
  268. * (see 'sync_some_inodes()') and pdflush write-back, the inode may
  269. * have already been synchronized, do not do this again. This might
  270. * also happen if it was synchronized in an VFS operation, e.g.
  271. * 'ubifs_link()'.
  272. */
  273. if (!ui->dirty) {
  274. mutex_unlock(&ui->ui_mutex);
  275. return 0;
  276. }
  277. /*
  278. * As an optimization, do not write orphan inodes to the media just
  279. * because this is not needed.
  280. */
  281. dbg_gen("inode %lu, mode %#x, nlink %u",
  282. inode->i_ino, (int)inode->i_mode, inode->i_nlink);
  283. if (inode->i_nlink) {
  284. err = ubifs_jnl_write_inode(c, inode);
  285. if (err)
  286. ubifs_err("can't write inode %lu, error %d",
  287. inode->i_ino, err);
  288. else
  289. err = dbg_check_inode_size(c, inode, ui->ui_size);
  290. }
  291. ui->dirty = 0;
  292. mutex_unlock(&ui->ui_mutex);
  293. ubifs_release_dirty_inode_budget(c, ui);
  294. return err;
  295. }
  296. static void ubifs_evict_inode(struct inode *inode)
  297. {
  298. int err;
  299. struct ubifs_info *c = inode->i_sb->s_fs_info;
  300. struct ubifs_inode *ui = ubifs_inode(inode);
  301. if (ui->xattr)
  302. /*
  303. * Extended attribute inode deletions are fully handled in
  304. * 'ubifs_removexattr()'. These inodes are special and have
  305. * limited usage, so there is nothing to do here.
  306. */
  307. goto out;
  308. dbg_gen("inode %lu, mode %#x", inode->i_ino, (int)inode->i_mode);
  309. ubifs_assert(!atomic_read(&inode->i_count));
  310. truncate_inode_pages(&inode->i_data, 0);
  311. if (inode->i_nlink)
  312. goto done;
  313. if (is_bad_inode(inode))
  314. goto out;
  315. ui->ui_size = inode->i_size = 0;
  316. err = ubifs_jnl_delete_inode(c, inode);
  317. if (err)
  318. /*
  319. * Worst case we have a lost orphan inode wasting space, so a
  320. * simple error message is OK here.
  321. */
  322. ubifs_err("can't delete inode %lu, error %d",
  323. inode->i_ino, err);
  324. out:
  325. if (ui->dirty)
  326. ubifs_release_dirty_inode_budget(c, ui);
  327. else {
  328. /* We've deleted something - clean the "no space" flags */
  329. c->bi.nospace = c->bi.nospace_rp = 0;
  330. smp_wmb();
  331. }
  332. done:
  333. end_writeback(inode);
  334. }
  335. static void ubifs_dirty_inode(struct inode *inode, int flags)
  336. {
  337. struct ubifs_inode *ui = ubifs_inode(inode);
  338. ubifs_assert(mutex_is_locked(&ui->ui_mutex));
  339. if (!ui->dirty) {
  340. ui->dirty = 1;
  341. dbg_gen("inode %lu", inode->i_ino);
  342. }
  343. }
  344. static int ubifs_statfs(struct dentry *dentry, struct kstatfs *buf)
  345. {
  346. struct ubifs_info *c = dentry->d_sb->s_fs_info;
  347. unsigned long long free;
  348. __le32 *uuid = (__le32 *)c->uuid;
  349. free = ubifs_get_free_space(c);
  350. dbg_gen("free space %lld bytes (%lld blocks)",
  351. free, free >> UBIFS_BLOCK_SHIFT);
  352. buf->f_type = UBIFS_SUPER_MAGIC;
  353. buf->f_bsize = UBIFS_BLOCK_SIZE;
  354. buf->f_blocks = c->block_cnt;
  355. buf->f_bfree = free >> UBIFS_BLOCK_SHIFT;
  356. if (free > c->report_rp_size)
  357. buf->f_bavail = (free - c->report_rp_size) >> UBIFS_BLOCK_SHIFT;
  358. else
  359. buf->f_bavail = 0;
  360. buf->f_files = 0;
  361. buf->f_ffree = 0;
  362. buf->f_namelen = UBIFS_MAX_NLEN;
  363. buf->f_fsid.val[0] = le32_to_cpu(uuid[0]) ^ le32_to_cpu(uuid[2]);
  364. buf->f_fsid.val[1] = le32_to_cpu(uuid[1]) ^ le32_to_cpu(uuid[3]);
  365. ubifs_assert(buf->f_bfree <= c->block_cnt);
  366. return 0;
  367. }
  368. static int ubifs_show_options(struct seq_file *s, struct dentry *root)
  369. {
  370. struct ubifs_info *c = root->d_sb->s_fs_info;
  371. if (c->mount_opts.unmount_mode == 2)
  372. seq_printf(s, ",fast_unmount");
  373. else if (c->mount_opts.unmount_mode == 1)
  374. seq_printf(s, ",norm_unmount");
  375. if (c->mount_opts.bulk_read == 2)
  376. seq_printf(s, ",bulk_read");
  377. else if (c->mount_opts.bulk_read == 1)
  378. seq_printf(s, ",no_bulk_read");
  379. if (c->mount_opts.chk_data_crc == 2)
  380. seq_printf(s, ",chk_data_crc");
  381. else if (c->mount_opts.chk_data_crc == 1)
  382. seq_printf(s, ",no_chk_data_crc");
  383. if (c->mount_opts.override_compr) {
  384. seq_printf(s, ",compr=%s",
  385. ubifs_compr_name(c->mount_opts.compr_type));
  386. }
  387. return 0;
  388. }
  389. static int ubifs_sync_fs(struct super_block *sb, int wait)
  390. {
  391. int i, err;
  392. struct ubifs_info *c = sb->s_fs_info;
  393. /*
  394. * Zero @wait is just an advisory thing to help the file system shove
  395. * lots of data into the queues, and there will be the second
  396. * '->sync_fs()' call, with non-zero @wait.
  397. */
  398. if (!wait)
  399. return 0;
  400. /*
  401. * Synchronize write buffers, because 'ubifs_run_commit()' does not
  402. * do this if it waits for an already running commit.
  403. */
  404. for (i = 0; i < c->jhead_cnt; i++) {
  405. err = ubifs_wbuf_sync(&c->jheads[i].wbuf);
  406. if (err)
  407. return err;
  408. }
  409. /*
  410. * Strictly speaking, it is not necessary to commit the journal here,
  411. * synchronizing write-buffers would be enough. But committing makes
  412. * UBIFS free space predictions much more accurate, so we want to let
  413. * the user be able to get more accurate results of 'statfs()' after
  414. * they synchronize the file system.
  415. */
  416. err = ubifs_run_commit(c);
  417. if (err)
  418. return err;
  419. return ubi_sync(c->vi.ubi_num);
  420. }
  421. /**
  422. * init_constants_early - initialize UBIFS constants.
  423. * @c: UBIFS file-system description object
  424. *
  425. * This function initialize UBIFS constants which do not need the superblock to
  426. * be read. It also checks that the UBI volume satisfies basic UBIFS
  427. * requirements. Returns zero in case of success and a negative error code in
  428. * case of failure.
  429. */
  430. static int init_constants_early(struct ubifs_info *c)
  431. {
  432. if (c->vi.corrupted) {
  433. ubifs_warn("UBI volume is corrupted - read-only mode");
  434. c->ro_media = 1;
  435. }
  436. if (c->di.ro_mode) {
  437. ubifs_msg("read-only UBI device");
  438. c->ro_media = 1;
  439. }
  440. if (c->vi.vol_type == UBI_STATIC_VOLUME) {
  441. ubifs_msg("static UBI volume - read-only mode");
  442. c->ro_media = 1;
  443. }
  444. c->leb_cnt = c->vi.size;
  445. c->leb_size = c->vi.usable_leb_size;
  446. c->leb_start = c->di.leb_start;
  447. c->half_leb_size = c->leb_size / 2;
  448. c->min_io_size = c->di.min_io_size;
  449. c->min_io_shift = fls(c->min_io_size) - 1;
  450. c->max_write_size = c->di.max_write_size;
  451. c->max_write_shift = fls(c->max_write_size) - 1;
  452. if (c->leb_size < UBIFS_MIN_LEB_SZ) {
  453. ubifs_err("too small LEBs (%d bytes), min. is %d bytes",
  454. c->leb_size, UBIFS_MIN_LEB_SZ);
  455. return -EINVAL;
  456. }
  457. if (c->leb_cnt < UBIFS_MIN_LEB_CNT) {
  458. ubifs_err("too few LEBs (%d), min. is %d",
  459. c->leb_cnt, UBIFS_MIN_LEB_CNT);
  460. return -EINVAL;
  461. }
  462. if (!is_power_of_2(c->min_io_size)) {
  463. ubifs_err("bad min. I/O size %d", c->min_io_size);
  464. return -EINVAL;
  465. }
  466. /*
  467. * Maximum write size has to be greater or equivalent to min. I/O
  468. * size, and be multiple of min. I/O size.
  469. */
  470. if (c->max_write_size < c->min_io_size ||
  471. c->max_write_size % c->min_io_size ||
  472. !is_power_of_2(c->max_write_size)) {
  473. ubifs_err("bad write buffer size %d for %d min. I/O unit",
  474. c->max_write_size, c->min_io_size);
  475. return -EINVAL;
  476. }
  477. /*
  478. * UBIFS aligns all node to 8-byte boundary, so to make function in
  479. * io.c simpler, assume minimum I/O unit size to be 8 bytes if it is
  480. * less than 8.
  481. */
  482. if (c->min_io_size < 8) {
  483. c->min_io_size = 8;
  484. c->min_io_shift = 3;
  485. if (c->max_write_size < c->min_io_size) {
  486. c->max_write_size = c->min_io_size;
  487. c->max_write_shift = c->min_io_shift;
  488. }
  489. }
  490. c->ref_node_alsz = ALIGN(UBIFS_REF_NODE_SZ, c->min_io_size);
  491. c->mst_node_alsz = ALIGN(UBIFS_MST_NODE_SZ, c->min_io_size);
  492. /*
  493. * Initialize node length ranges which are mostly needed for node
  494. * length validation.
  495. */
  496. c->ranges[UBIFS_PAD_NODE].len = UBIFS_PAD_NODE_SZ;
  497. c->ranges[UBIFS_SB_NODE].len = UBIFS_SB_NODE_SZ;
  498. c->ranges[UBIFS_MST_NODE].len = UBIFS_MST_NODE_SZ;
  499. c->ranges[UBIFS_REF_NODE].len = UBIFS_REF_NODE_SZ;
  500. c->ranges[UBIFS_TRUN_NODE].len = UBIFS_TRUN_NODE_SZ;
  501. c->ranges[UBIFS_CS_NODE].len = UBIFS_CS_NODE_SZ;
  502. c->ranges[UBIFS_INO_NODE].min_len = UBIFS_INO_NODE_SZ;
  503. c->ranges[UBIFS_INO_NODE].max_len = UBIFS_MAX_INO_NODE_SZ;
  504. c->ranges[UBIFS_ORPH_NODE].min_len =
  505. UBIFS_ORPH_NODE_SZ + sizeof(__le64);
  506. c->ranges[UBIFS_ORPH_NODE].max_len = c->leb_size;
  507. c->ranges[UBIFS_DENT_NODE].min_len = UBIFS_DENT_NODE_SZ;
  508. c->ranges[UBIFS_DENT_NODE].max_len = UBIFS_MAX_DENT_NODE_SZ;
  509. c->ranges[UBIFS_XENT_NODE].min_len = UBIFS_XENT_NODE_SZ;
  510. c->ranges[UBIFS_XENT_NODE].max_len = UBIFS_MAX_XENT_NODE_SZ;
  511. c->ranges[UBIFS_DATA_NODE].min_len = UBIFS_DATA_NODE_SZ;
  512. c->ranges[UBIFS_DATA_NODE].max_len = UBIFS_MAX_DATA_NODE_SZ;
  513. /*
  514. * Minimum indexing node size is amended later when superblock is
  515. * read and the key length is known.
  516. */
  517. c->ranges[UBIFS_IDX_NODE].min_len = UBIFS_IDX_NODE_SZ + UBIFS_BRANCH_SZ;
  518. /*
  519. * Maximum indexing node size is amended later when superblock is
  520. * read and the fanout is known.
  521. */
  522. c->ranges[UBIFS_IDX_NODE].max_len = INT_MAX;
  523. /*
  524. * Initialize dead and dark LEB space watermarks. See gc.c for comments
  525. * about these values.
  526. */
  527. c->dead_wm = ALIGN(MIN_WRITE_SZ, c->min_io_size);
  528. c->dark_wm = ALIGN(UBIFS_MAX_NODE_SZ, c->min_io_size);
  529. /*
  530. * Calculate how many bytes would be wasted at the end of LEB if it was
  531. * fully filled with data nodes of maximum size. This is used in
  532. * calculations when reporting free space.
  533. */
  534. c->leb_overhead = c->leb_size % UBIFS_MAX_DATA_NODE_SZ;
  535. /* Buffer size for bulk-reads */
  536. c->max_bu_buf_len = UBIFS_MAX_BULK_READ * UBIFS_MAX_DATA_NODE_SZ;
  537. if (c->max_bu_buf_len > c->leb_size)
  538. c->max_bu_buf_len = c->leb_size;
  539. return 0;
  540. }
  541. /**
  542. * bud_wbuf_callback - bud LEB write-buffer synchronization call-back.
  543. * @c: UBIFS file-system description object
  544. * @lnum: LEB the write-buffer was synchronized to
  545. * @free: how many free bytes left in this LEB
  546. * @pad: how many bytes were padded
  547. *
  548. * This is a callback function which is called by the I/O unit when the
  549. * write-buffer is synchronized. We need this to correctly maintain space
  550. * accounting in bud logical eraseblocks. This function returns zero in case of
  551. * success and a negative error code in case of failure.
  552. *
  553. * This function actually belongs to the journal, but we keep it here because
  554. * we want to keep it static.
  555. */
  556. static int bud_wbuf_callback(struct ubifs_info *c, int lnum, int free, int pad)
  557. {
  558. return ubifs_update_one_lp(c, lnum, free, pad, 0, 0);
  559. }
  560. /*
  561. * init_constants_sb - initialize UBIFS constants.
  562. * @c: UBIFS file-system description object
  563. *
  564. * This is a helper function which initializes various UBIFS constants after
  565. * the superblock has been read. It also checks various UBIFS parameters and
  566. * makes sure they are all right. Returns zero in case of success and a
  567. * negative error code in case of failure.
  568. */
  569. static int init_constants_sb(struct ubifs_info *c)
  570. {
  571. int tmp, err;
  572. long long tmp64;
  573. c->main_bytes = (long long)c->main_lebs * c->leb_size;
  574. c->max_znode_sz = sizeof(struct ubifs_znode) +
  575. c->fanout * sizeof(struct ubifs_zbranch);
  576. tmp = ubifs_idx_node_sz(c, 1);
  577. c->ranges[UBIFS_IDX_NODE].min_len = tmp;
  578. c->min_idx_node_sz = ALIGN(tmp, 8);
  579. tmp = ubifs_idx_node_sz(c, c->fanout);
  580. c->ranges[UBIFS_IDX_NODE].max_len = tmp;
  581. c->max_idx_node_sz = ALIGN(tmp, 8);
  582. /* Make sure LEB size is large enough to fit full commit */
  583. tmp = UBIFS_CS_NODE_SZ + UBIFS_REF_NODE_SZ * c->jhead_cnt;
  584. tmp = ALIGN(tmp, c->min_io_size);
  585. if (tmp > c->leb_size) {
  586. dbg_err("too small LEB size %d, at least %d needed",
  587. c->leb_size, tmp);
  588. return -EINVAL;
  589. }
  590. /*
  591. * Make sure that the log is large enough to fit reference nodes for
  592. * all buds plus one reserved LEB.
  593. */
  594. tmp64 = c->max_bud_bytes + c->leb_size - 1;
  595. c->max_bud_cnt = div_u64(tmp64, c->leb_size);
  596. tmp = (c->ref_node_alsz * c->max_bud_cnt + c->leb_size - 1);
  597. tmp /= c->leb_size;
  598. tmp += 1;
  599. if (c->log_lebs < tmp) {
  600. dbg_err("too small log %d LEBs, required min. %d LEBs",
  601. c->log_lebs, tmp);
  602. return -EINVAL;
  603. }
  604. /*
  605. * When budgeting we assume worst-case scenarios when the pages are not
  606. * be compressed and direntries are of the maximum size.
  607. *
  608. * Note, data, which may be stored in inodes is budgeted separately, so
  609. * it is not included into 'c->bi.inode_budget'.
  610. */
  611. c->bi.page_budget = UBIFS_MAX_DATA_NODE_SZ * UBIFS_BLOCKS_PER_PAGE;
  612. c->bi.inode_budget = UBIFS_INO_NODE_SZ;
  613. c->bi.dent_budget = UBIFS_MAX_DENT_NODE_SZ;
  614. /*
  615. * When the amount of flash space used by buds becomes
  616. * 'c->max_bud_bytes', UBIFS just blocks all writers and starts commit.
  617. * The writers are unblocked when the commit is finished. To avoid
  618. * writers to be blocked UBIFS initiates background commit in advance,
  619. * when number of bud bytes becomes above the limit defined below.
  620. */
  621. c->bg_bud_bytes = (c->max_bud_bytes * 13) >> 4;
  622. /*
  623. * Ensure minimum journal size. All the bytes in the journal heads are
  624. * considered to be used, when calculating the current journal usage.
  625. * Consequently, if the journal is too small, UBIFS will treat it as
  626. * always full.
  627. */
  628. tmp64 = (long long)(c->jhead_cnt + 1) * c->leb_size + 1;
  629. if (c->bg_bud_bytes < tmp64)
  630. c->bg_bud_bytes = tmp64;
  631. if (c->max_bud_bytes < tmp64 + c->leb_size)
  632. c->max_bud_bytes = tmp64 + c->leb_size;
  633. err = ubifs_calc_lpt_geom(c);
  634. if (err)
  635. return err;
  636. /* Initialize effective LEB size used in budgeting calculations */
  637. c->idx_leb_size = c->leb_size - c->max_idx_node_sz;
  638. return 0;
  639. }
  640. /*
  641. * init_constants_master - initialize UBIFS constants.
  642. * @c: UBIFS file-system description object
  643. *
  644. * This is a helper function which initializes various UBIFS constants after
  645. * the master node has been read. It also checks various UBIFS parameters and
  646. * makes sure they are all right.
  647. */
  648. static void init_constants_master(struct ubifs_info *c)
  649. {
  650. long long tmp64;
  651. c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c);
  652. c->report_rp_size = ubifs_reported_space(c, c->rp_size);
  653. /*
  654. * Calculate total amount of FS blocks. This number is not used
  655. * internally because it does not make much sense for UBIFS, but it is
  656. * necessary to report something for the 'statfs()' call.
  657. *
  658. * Subtract the LEB reserved for GC, the LEB which is reserved for
  659. * deletions, minimum LEBs for the index, and assume only one journal
  660. * head is available.
  661. */
  662. tmp64 = c->main_lebs - 1 - 1 - MIN_INDEX_LEBS - c->jhead_cnt + 1;
  663. tmp64 *= (long long)c->leb_size - c->leb_overhead;
  664. tmp64 = ubifs_reported_space(c, tmp64);
  665. c->block_cnt = tmp64 >> UBIFS_BLOCK_SHIFT;
  666. }
  667. /**
  668. * take_gc_lnum - reserve GC LEB.
  669. * @c: UBIFS file-system description object
  670. *
  671. * This function ensures that the LEB reserved for garbage collection is marked
  672. * as "taken" in lprops. We also have to set free space to LEB size and dirty
  673. * space to zero, because lprops may contain out-of-date information if the
  674. * file-system was un-mounted before it has been committed. This function
  675. * returns zero in case of success and a negative error code in case of
  676. * failure.
  677. */
  678. static int take_gc_lnum(struct ubifs_info *c)
  679. {
  680. int err;
  681. if (c->gc_lnum == -1) {
  682. ubifs_err("no LEB for GC");
  683. return -EINVAL;
  684. }
  685. /* And we have to tell lprops that this LEB is taken */
  686. err = ubifs_change_one_lp(c, c->gc_lnum, c->leb_size, 0,
  687. LPROPS_TAKEN, 0, 0);
  688. return err;
  689. }
  690. /**
  691. * alloc_wbufs - allocate write-buffers.
  692. * @c: UBIFS file-system description object
  693. *
  694. * This helper function allocates and initializes UBIFS write-buffers. Returns
  695. * zero in case of success and %-ENOMEM in case of failure.
  696. */
  697. static int alloc_wbufs(struct ubifs_info *c)
  698. {
  699. int i, err;
  700. c->jheads = kzalloc(c->jhead_cnt * sizeof(struct ubifs_jhead),
  701. GFP_KERNEL);
  702. if (!c->jheads)
  703. return -ENOMEM;
  704. /* Initialize journal heads */
  705. for (i = 0; i < c->jhead_cnt; i++) {
  706. INIT_LIST_HEAD(&c->jheads[i].buds_list);
  707. err = ubifs_wbuf_init(c, &c->jheads[i].wbuf);
  708. if (err)
  709. return err;
  710. c->jheads[i].wbuf.sync_callback = &bud_wbuf_callback;
  711. c->jheads[i].wbuf.jhead = i;
  712. c->jheads[i].grouped = 1;
  713. }
  714. c->jheads[BASEHD].wbuf.dtype = UBI_SHORTTERM;
  715. /*
  716. * Garbage Collector head likely contains long-term data and
  717. * does not need to be synchronized by timer. Also GC head nodes are
  718. * not grouped.
  719. */
  720. c->jheads[GCHD].wbuf.dtype = UBI_LONGTERM;
  721. c->jheads[GCHD].wbuf.no_timer = 1;
  722. c->jheads[GCHD].grouped = 0;
  723. return 0;
  724. }
  725. /**
  726. * free_wbufs - free write-buffers.
  727. * @c: UBIFS file-system description object
  728. */
  729. static void free_wbufs(struct ubifs_info *c)
  730. {
  731. int i;
  732. if (c->jheads) {
  733. for (i = 0; i < c->jhead_cnt; i++) {
  734. kfree(c->jheads[i].wbuf.buf);
  735. kfree(c->jheads[i].wbuf.inodes);
  736. }
  737. kfree(c->jheads);
  738. c->jheads = NULL;
  739. }
  740. }
  741. /**
  742. * free_orphans - free orphans.
  743. * @c: UBIFS file-system description object
  744. */
  745. static void free_orphans(struct ubifs_info *c)
  746. {
  747. struct ubifs_orphan *orph;
  748. while (c->orph_dnext) {
  749. orph = c->orph_dnext;
  750. c->orph_dnext = orph->dnext;
  751. list_del(&orph->list);
  752. kfree(orph);
  753. }
  754. while (!list_empty(&c->orph_list)) {
  755. orph = list_entry(c->orph_list.next, struct ubifs_orphan, list);
  756. list_del(&orph->list);
  757. kfree(orph);
  758. dbg_err("orphan list not empty at unmount");
  759. }
  760. vfree(c->orph_buf);
  761. c->orph_buf = NULL;
  762. }
  763. /**
  764. * free_buds - free per-bud objects.
  765. * @c: UBIFS file-system description object
  766. */
  767. static void free_buds(struct ubifs_info *c)
  768. {
  769. struct rb_node *this = c->buds.rb_node;
  770. struct ubifs_bud *bud;
  771. while (this) {
  772. if (this->rb_left)
  773. this = this->rb_left;
  774. else if (this->rb_right)
  775. this = this->rb_right;
  776. else {
  777. bud = rb_entry(this, struct ubifs_bud, rb);
  778. this = rb_parent(this);
  779. if (this) {
  780. if (this->rb_left == &bud->rb)
  781. this->rb_left = NULL;
  782. else
  783. this->rb_right = NULL;
  784. }
  785. kfree(bud);
  786. }
  787. }
  788. }
  789. /**
  790. * check_volume_empty - check if the UBI volume is empty.
  791. * @c: UBIFS file-system description object
  792. *
  793. * This function checks if the UBIFS volume is empty by looking if its LEBs are
  794. * mapped or not. The result of checking is stored in the @c->empty variable.
  795. * Returns zero in case of success and a negative error code in case of
  796. * failure.
  797. */
  798. static int check_volume_empty(struct ubifs_info *c)
  799. {
  800. int lnum, err;
  801. c->empty = 1;
  802. for (lnum = 0; lnum < c->leb_cnt; lnum++) {
  803. err = ubifs_is_mapped(c, lnum);
  804. if (unlikely(err < 0))
  805. return err;
  806. if (err == 1) {
  807. c->empty = 0;
  808. break;
  809. }
  810. cond_resched();
  811. }
  812. return 0;
  813. }
  814. /*
  815. * UBIFS mount options.
  816. *
  817. * Opt_fast_unmount: do not run a journal commit before un-mounting
  818. * Opt_norm_unmount: run a journal commit before un-mounting
  819. * Opt_bulk_read: enable bulk-reads
  820. * Opt_no_bulk_read: disable bulk-reads
  821. * Opt_chk_data_crc: check CRCs when reading data nodes
  822. * Opt_no_chk_data_crc: do not check CRCs when reading data nodes
  823. * Opt_override_compr: override default compressor
  824. * Opt_err: just end of array marker
  825. */
  826. enum {
  827. Opt_fast_unmount,
  828. Opt_norm_unmount,
  829. Opt_bulk_read,
  830. Opt_no_bulk_read,
  831. Opt_chk_data_crc,
  832. Opt_no_chk_data_crc,
  833. Opt_override_compr,
  834. Opt_err,
  835. };
  836. static const match_table_t tokens = {
  837. {Opt_fast_unmount, "fast_unmount"},
  838. {Opt_norm_unmount, "norm_unmount"},
  839. {Opt_bulk_read, "bulk_read"},
  840. {Opt_no_bulk_read, "no_bulk_read"},
  841. {Opt_chk_data_crc, "chk_data_crc"},
  842. {Opt_no_chk_data_crc, "no_chk_data_crc"},
  843. {Opt_override_compr, "compr=%s"},
  844. {Opt_err, NULL},
  845. };
  846. /**
  847. * parse_standard_option - parse a standard mount option.
  848. * @option: the option to parse
  849. *
  850. * Normally, standard mount options like "sync" are passed to file-systems as
  851. * flags. However, when a "rootflags=" kernel boot parameter is used, they may
  852. * be present in the options string. This function tries to deal with this
  853. * situation and parse standard options. Returns 0 if the option was not
  854. * recognized, and the corresponding integer flag if it was.
  855. *
  856. * UBIFS is only interested in the "sync" option, so do not check for anything
  857. * else.
  858. */
  859. static int parse_standard_option(const char *option)
  860. {
  861. ubifs_msg("parse %s", option);
  862. if (!strcmp(option, "sync"))
  863. return MS_SYNCHRONOUS;
  864. return 0;
  865. }
  866. /**
  867. * ubifs_parse_options - parse mount parameters.
  868. * @c: UBIFS file-system description object
  869. * @options: parameters to parse
  870. * @is_remount: non-zero if this is FS re-mount
  871. *
  872. * This function parses UBIFS mount options and returns zero in case success
  873. * and a negative error code in case of failure.
  874. */
  875. static int ubifs_parse_options(struct ubifs_info *c, char *options,
  876. int is_remount)
  877. {
  878. char *p;
  879. substring_t args[MAX_OPT_ARGS];
  880. if (!options)
  881. return 0;
  882. while ((p = strsep(&options, ","))) {
  883. int token;
  884. if (!*p)
  885. continue;
  886. token = match_token(p, tokens, args);
  887. switch (token) {
  888. /*
  889. * %Opt_fast_unmount and %Opt_norm_unmount options are ignored.
  890. * We accept them in order to be backward-compatible. But this
  891. * should be removed at some point.
  892. */
  893. case Opt_fast_unmount:
  894. c->mount_opts.unmount_mode = 2;
  895. break;
  896. case Opt_norm_unmount:
  897. c->mount_opts.unmount_mode = 1;
  898. break;
  899. case Opt_bulk_read:
  900. c->mount_opts.bulk_read = 2;
  901. c->bulk_read = 1;
  902. break;
  903. case Opt_no_bulk_read:
  904. c->mount_opts.bulk_read = 1;
  905. c->bulk_read = 0;
  906. break;
  907. case Opt_chk_data_crc:
  908. c->mount_opts.chk_data_crc = 2;
  909. c->no_chk_data_crc = 0;
  910. break;
  911. case Opt_no_chk_data_crc:
  912. c->mount_opts.chk_data_crc = 1;
  913. c->no_chk_data_crc = 1;
  914. break;
  915. case Opt_override_compr:
  916. {
  917. char *name = match_strdup(&args[0]);
  918. if (!name)
  919. return -ENOMEM;
  920. if (!strcmp(name, "none"))
  921. c->mount_opts.compr_type = UBIFS_COMPR_NONE;
  922. else if (!strcmp(name, "lzo"))
  923. c->mount_opts.compr_type = UBIFS_COMPR_LZO;
  924. else if (!strcmp(name, "zlib"))
  925. c->mount_opts.compr_type = UBIFS_COMPR_ZLIB;
  926. else {
  927. ubifs_err("unknown compressor \"%s\"", name);
  928. kfree(name);
  929. return -EINVAL;
  930. }
  931. kfree(name);
  932. c->mount_opts.override_compr = 1;
  933. c->default_compr = c->mount_opts.compr_type;
  934. break;
  935. }
  936. default:
  937. {
  938. unsigned long flag;
  939. struct super_block *sb = c->vfs_sb;
  940. flag = parse_standard_option(p);
  941. if (!flag) {
  942. ubifs_err("unrecognized mount option \"%s\" "
  943. "or missing value", p);
  944. return -EINVAL;
  945. }
  946. sb->s_flags |= flag;
  947. break;
  948. }
  949. }
  950. }
  951. return 0;
  952. }
  953. /**
  954. * destroy_journal - destroy journal data structures.
  955. * @c: UBIFS file-system description object
  956. *
  957. * This function destroys journal data structures including those that may have
  958. * been created by recovery functions.
  959. */
  960. static void destroy_journal(struct ubifs_info *c)
  961. {
  962. while (!list_empty(&c->unclean_leb_list)) {
  963. struct ubifs_unclean_leb *ucleb;
  964. ucleb = list_entry(c->unclean_leb_list.next,
  965. struct ubifs_unclean_leb, list);
  966. list_del(&ucleb->list);
  967. kfree(ucleb);
  968. }
  969. while (!list_empty(&c->old_buds)) {
  970. struct ubifs_bud *bud;
  971. bud = list_entry(c->old_buds.next, struct ubifs_bud, list);
  972. list_del(&bud->list);
  973. kfree(bud);
  974. }
  975. ubifs_destroy_idx_gc(c);
  976. ubifs_destroy_size_tree(c);
  977. ubifs_tnc_close(c);
  978. free_buds(c);
  979. }
  980. /**
  981. * bu_init - initialize bulk-read information.
  982. * @c: UBIFS file-system description object
  983. */
  984. static void bu_init(struct ubifs_info *c)
  985. {
  986. ubifs_assert(c->bulk_read == 1);
  987. if (c->bu.buf)
  988. return; /* Already initialized */
  989. again:
  990. c->bu.buf = kmalloc(c->max_bu_buf_len, GFP_KERNEL | __GFP_NOWARN);
  991. if (!c->bu.buf) {
  992. if (c->max_bu_buf_len > UBIFS_KMALLOC_OK) {
  993. c->max_bu_buf_len = UBIFS_KMALLOC_OK;
  994. goto again;
  995. }
  996. /* Just disable bulk-read */
  997. ubifs_warn("Cannot allocate %d bytes of memory for bulk-read, "
  998. "disabling it", c->max_bu_buf_len);
  999. c->mount_opts.bulk_read = 1;
  1000. c->bulk_read = 0;
  1001. return;
  1002. }
  1003. }
  1004. /**
  1005. * check_free_space - check if there is enough free space to mount.
  1006. * @c: UBIFS file-system description object
  1007. *
  1008. * This function makes sure UBIFS has enough free space to be mounted in
  1009. * read/write mode. UBIFS must always have some free space to allow deletions.
  1010. */
  1011. static int check_free_space(struct ubifs_info *c)
  1012. {
  1013. ubifs_assert(c->dark_wm > 0);
  1014. if (c->lst.total_free + c->lst.total_dirty < c->dark_wm) {
  1015. ubifs_err("insufficient free space to mount in R/W mode");
  1016. dbg_dump_budg(c, &c->bi);
  1017. dbg_dump_lprops(c);
  1018. return -ENOSPC;
  1019. }
  1020. return 0;
  1021. }
  1022. /**
  1023. * mount_ubifs - mount UBIFS file-system.
  1024. * @c: UBIFS file-system description object
  1025. *
  1026. * This function mounts UBIFS file system. Returns zero in case of success and
  1027. * a negative error code in case of failure.
  1028. *
  1029. * Note, the function does not de-allocate resources it it fails half way
  1030. * through, and the caller has to do this instead.
  1031. */
  1032. static int mount_ubifs(struct ubifs_info *c)
  1033. {
  1034. int err;
  1035. long long x;
  1036. size_t sz;
  1037. c->ro_mount = !!(c->vfs_sb->s_flags & MS_RDONLY);
  1038. err = init_constants_early(c);
  1039. if (err)
  1040. return err;
  1041. err = ubifs_debugging_init(c);
  1042. if (err)
  1043. return err;
  1044. err = check_volume_empty(c);
  1045. if (err)
  1046. goto out_free;
  1047. if (c->empty && (c->ro_mount || c->ro_media)) {
  1048. /*
  1049. * This UBI volume is empty, and read-only, or the file system
  1050. * is mounted read-only - we cannot format it.
  1051. */
  1052. ubifs_err("can't format empty UBI volume: read-only %s",
  1053. c->ro_media ? "UBI volume" : "mount");
  1054. err = -EROFS;
  1055. goto out_free;
  1056. }
  1057. if (c->ro_media && !c->ro_mount) {
  1058. ubifs_err("cannot mount read-write - read-only media");
  1059. err = -EROFS;
  1060. goto out_free;
  1061. }
  1062. /*
  1063. * The requirement for the buffer is that it should fit indexing B-tree
  1064. * height amount of integers. We assume the height if the TNC tree will
  1065. * never exceed 64.
  1066. */
  1067. err = -ENOMEM;
  1068. c->bottom_up_buf = kmalloc(BOTTOM_UP_HEIGHT * sizeof(int), GFP_KERNEL);
  1069. if (!c->bottom_up_buf)
  1070. goto out_free;
  1071. c->sbuf = vmalloc(c->leb_size);
  1072. if (!c->sbuf)
  1073. goto out_free;
  1074. if (!c->ro_mount) {
  1075. c->ileb_buf = vmalloc(c->leb_size);
  1076. if (!c->ileb_buf)
  1077. goto out_free;
  1078. }
  1079. if (c->bulk_read == 1)
  1080. bu_init(c);
  1081. if (!c->ro_mount) {
  1082. c->write_reserve_buf = kmalloc(COMPRESSED_DATA_NODE_BUF_SZ,
  1083. GFP_KERNEL);
  1084. if (!c->write_reserve_buf)
  1085. goto out_free;
  1086. }
  1087. c->mounting = 1;
  1088. err = ubifs_read_superblock(c);
  1089. if (err)
  1090. goto out_free;
  1091. /*
  1092. * Make sure the compressor which is set as default in the superblock
  1093. * or overridden by mount options is actually compiled in.
  1094. */
  1095. if (!ubifs_compr_present(c->default_compr)) {
  1096. ubifs_err("'compressor \"%s\" is not compiled in",
  1097. ubifs_compr_name(c->default_compr));
  1098. err = -ENOTSUPP;
  1099. goto out_free;
  1100. }
  1101. err = init_constants_sb(c);
  1102. if (err)
  1103. goto out_free;
  1104. sz = ALIGN(c->max_idx_node_sz, c->min_io_size);
  1105. sz = ALIGN(sz + c->max_idx_node_sz, c->min_io_size);
  1106. c->cbuf = kmalloc(sz, GFP_NOFS);
  1107. if (!c->cbuf) {
  1108. err = -ENOMEM;
  1109. goto out_free;
  1110. }
  1111. err = alloc_wbufs(c);
  1112. if (err)
  1113. goto out_cbuf;
  1114. sprintf(c->bgt_name, BGT_NAME_PATTERN, c->vi.ubi_num, c->vi.vol_id);
  1115. if (!c->ro_mount) {
  1116. /* Create background thread */
  1117. c->bgt = kthread_create(ubifs_bg_thread, c, "%s", c->bgt_name);
  1118. if (IS_ERR(c->bgt)) {
  1119. err = PTR_ERR(c->bgt);
  1120. c->bgt = NULL;
  1121. ubifs_err("cannot spawn \"%s\", error %d",
  1122. c->bgt_name, err);
  1123. goto out_wbufs;
  1124. }
  1125. wake_up_process(c->bgt);
  1126. }
  1127. err = ubifs_read_master(c);
  1128. if (err)
  1129. goto out_master;
  1130. init_constants_master(c);
  1131. if ((c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY)) != 0) {
  1132. ubifs_msg("recovery needed");
  1133. c->need_recovery = 1;
  1134. }
  1135. if (c->need_recovery && !c->ro_mount) {
  1136. err = ubifs_recover_inl_heads(c, c->sbuf);
  1137. if (err)
  1138. goto out_master;
  1139. }
  1140. err = ubifs_lpt_init(c, 1, !c->ro_mount);
  1141. if (err)
  1142. goto out_master;
  1143. if (!c->ro_mount && c->space_fixup) {
  1144. err = ubifs_fixup_free_space(c);
  1145. if (err)
  1146. goto out_master;
  1147. }
  1148. if (!c->ro_mount) {
  1149. /*
  1150. * Set the "dirty" flag so that if we reboot uncleanly we
  1151. * will notice this immediately on the next mount.
  1152. */
  1153. c->mst_node->flags |= cpu_to_le32(UBIFS_MST_DIRTY);
  1154. err = ubifs_write_master(c);
  1155. if (err)
  1156. goto out_lpt;
  1157. }
  1158. err = dbg_check_idx_size(c, c->bi.old_idx_sz);
  1159. if (err)
  1160. goto out_lpt;
  1161. err = ubifs_replay_journal(c);
  1162. if (err)
  1163. goto out_journal;
  1164. /* Calculate 'min_idx_lebs' after journal replay */
  1165. c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c);
  1166. err = ubifs_mount_orphans(c, c->need_recovery, c->ro_mount);
  1167. if (err)
  1168. goto out_orphans;
  1169. if (!c->ro_mount) {
  1170. int lnum;
  1171. err = check_free_space(c);
  1172. if (err)
  1173. goto out_orphans;
  1174. /* Check for enough log space */
  1175. lnum = c->lhead_lnum + 1;
  1176. if (lnum >= UBIFS_LOG_LNUM + c->log_lebs)
  1177. lnum = UBIFS_LOG_LNUM;
  1178. if (lnum == c->ltail_lnum) {
  1179. err = ubifs_consolidate_log(c);
  1180. if (err)
  1181. goto out_orphans;
  1182. }
  1183. if (c->need_recovery) {
  1184. err = ubifs_recover_size(c);
  1185. if (err)
  1186. goto out_orphans;
  1187. err = ubifs_rcvry_gc_commit(c);
  1188. if (err)
  1189. goto out_orphans;
  1190. } else {
  1191. err = take_gc_lnum(c);
  1192. if (err)
  1193. goto out_orphans;
  1194. /*
  1195. * GC LEB may contain garbage if there was an unclean
  1196. * reboot, and it should be un-mapped.
  1197. */
  1198. err = ubifs_leb_unmap(c, c->gc_lnum);
  1199. if (err)
  1200. goto out_orphans;
  1201. }
  1202. err = dbg_check_lprops(c);
  1203. if (err)
  1204. goto out_orphans;
  1205. } else if (c->need_recovery) {
  1206. err = ubifs_recover_size(c);
  1207. if (err)
  1208. goto out_orphans;
  1209. } else {
  1210. /*
  1211. * Even if we mount read-only, we have to set space in GC LEB
  1212. * to proper value because this affects UBIFS free space
  1213. * reporting. We do not want to have a situation when
  1214. * re-mounting from R/O to R/W changes amount of free space.
  1215. */
  1216. err = take_gc_lnum(c);
  1217. if (err)
  1218. goto out_orphans;
  1219. }
  1220. spin_lock(&ubifs_infos_lock);
  1221. list_add_tail(&c->infos_list, &ubifs_infos);
  1222. spin_unlock(&ubifs_infos_lock);
  1223. if (c->need_recovery) {
  1224. if (c->ro_mount)
  1225. ubifs_msg("recovery deferred");
  1226. else {
  1227. c->need_recovery = 0;
  1228. ubifs_msg("recovery completed");
  1229. /*
  1230. * GC LEB has to be empty and taken at this point. But
  1231. * the journal head LEBs may also be accounted as
  1232. * "empty taken" if they are empty.
  1233. */
  1234. ubifs_assert(c->lst.taken_empty_lebs > 0);
  1235. }
  1236. } else
  1237. ubifs_assert(c->lst.taken_empty_lebs > 0);
  1238. err = dbg_check_filesystem(c);
  1239. if (err)
  1240. goto out_infos;
  1241. err = dbg_debugfs_init_fs(c);
  1242. if (err)
  1243. goto out_infos;
  1244. c->mounting = 0;
  1245. ubifs_msg("mounted UBI device %d, volume %d, name \"%s\"",
  1246. c->vi.ubi_num, c->vi.vol_id, c->vi.name);
  1247. if (c->ro_mount)
  1248. ubifs_msg("mounted read-only");
  1249. x = (long long)c->main_lebs * c->leb_size;
  1250. ubifs_msg("file system size: %lld bytes (%lld KiB, %lld MiB, %d "
  1251. "LEBs)", x, x >> 10, x >> 20, c->main_lebs);
  1252. x = (long long)c->log_lebs * c->leb_size + c->max_bud_bytes;
  1253. ubifs_msg("journal size: %lld bytes (%lld KiB, %lld MiB, %d "
  1254. "LEBs)", x, x >> 10, x >> 20, c->log_lebs + c->max_bud_cnt);
  1255. ubifs_msg("media format: w%d/r%d (latest is w%d/r%d)",
  1256. c->fmt_version, c->ro_compat_version,
  1257. UBIFS_FORMAT_VERSION, UBIFS_RO_COMPAT_VERSION);
  1258. ubifs_msg("default compressor: %s", ubifs_compr_name(c->default_compr));
  1259. ubifs_msg("reserved for root: %llu bytes (%llu KiB)",
  1260. c->report_rp_size, c->report_rp_size >> 10);
  1261. dbg_msg("compiled on: " __DATE__ " at " __TIME__);
  1262. dbg_msg("min. I/O unit size: %d bytes", c->min_io_size);
  1263. dbg_msg("max. write size: %d bytes", c->max_write_size);
  1264. dbg_msg("LEB size: %d bytes (%d KiB)",
  1265. c->leb_size, c->leb_size >> 10);
  1266. dbg_msg("data journal heads: %d",
  1267. c->jhead_cnt - NONDATA_JHEADS_CNT);
  1268. dbg_msg("UUID: %pUB", c->uuid);
  1269. dbg_msg("big_lpt %d", c->big_lpt);
  1270. dbg_msg("log LEBs: %d (%d - %d)",
  1271. c->log_lebs, UBIFS_LOG_LNUM, c->log_last);
  1272. dbg_msg("LPT area LEBs: %d (%d - %d)",
  1273. c->lpt_lebs, c->lpt_first, c->lpt_last);
  1274. dbg_msg("orphan area LEBs: %d (%d - %d)",
  1275. c->orph_lebs, c->orph_first, c->orph_last);
  1276. dbg_msg("main area LEBs: %d (%d - %d)",
  1277. c->main_lebs, c->main_first, c->leb_cnt - 1);
  1278. dbg_msg("index LEBs: %d", c->lst.idx_lebs);
  1279. dbg_msg("total index bytes: %lld (%lld KiB, %lld MiB)",
  1280. c->bi.old_idx_sz, c->bi.old_idx_sz >> 10,
  1281. c->bi.old_idx_sz >> 20);
  1282. dbg_msg("key hash type: %d", c->key_hash_type);
  1283. dbg_msg("tree fanout: %d", c->fanout);
  1284. dbg_msg("reserved GC LEB: %d", c->gc_lnum);
  1285. dbg_msg("first main LEB: %d", c->main_first);
  1286. dbg_msg("max. znode size %d", c->max_znode_sz);
  1287. dbg_msg("max. index node size %d", c->max_idx_node_sz);
  1288. dbg_msg("node sizes: data %zu, inode %zu, dentry %zu",
  1289. UBIFS_DATA_NODE_SZ, UBIFS_INO_NODE_SZ, UBIFS_DENT_NODE_SZ);
  1290. dbg_msg("node sizes: trun %zu, sb %zu, master %zu",
  1291. UBIFS_TRUN_NODE_SZ, UBIFS_SB_NODE_SZ, UBIFS_MST_NODE_SZ);
  1292. dbg_msg("node sizes: ref %zu, cmt. start %zu, orph %zu",
  1293. UBIFS_REF_NODE_SZ, UBIFS_CS_NODE_SZ, UBIFS_ORPH_NODE_SZ);
  1294. dbg_msg("max. node sizes: data %zu, inode %zu dentry %zu, idx %d",
  1295. UBIFS_MAX_DATA_NODE_SZ, UBIFS_MAX_INO_NODE_SZ,
  1296. UBIFS_MAX_DENT_NODE_SZ, ubifs_idx_node_sz(c, c->fanout));
  1297. dbg_msg("dead watermark: %d", c->dead_wm);
  1298. dbg_msg("dark watermark: %d", c->dark_wm);
  1299. dbg_msg("LEB overhead: %d", c->leb_overhead);
  1300. x = (long long)c->main_lebs * c->dark_wm;
  1301. dbg_msg("max. dark space: %lld (%lld KiB, %lld MiB)",
  1302. x, x >> 10, x >> 20);
  1303. dbg_msg("maximum bud bytes: %lld (%lld KiB, %lld MiB)",
  1304. c->max_bud_bytes, c->max_bud_bytes >> 10,
  1305. c->max_bud_bytes >> 20);
  1306. dbg_msg("BG commit bud bytes: %lld (%lld KiB, %lld MiB)",
  1307. c->bg_bud_bytes, c->bg_bud_bytes >> 10,
  1308. c->bg_bud_bytes >> 20);
  1309. dbg_msg("current bud bytes %lld (%lld KiB, %lld MiB)",
  1310. c->bud_bytes, c->bud_bytes >> 10, c->bud_bytes >> 20);
  1311. dbg_msg("max. seq. number: %llu", c->max_sqnum);
  1312. dbg_msg("commit number: %llu", c->cmt_no);
  1313. return 0;
  1314. out_infos:
  1315. spin_lock(&ubifs_infos_lock);
  1316. list_del(&c->infos_list);
  1317. spin_unlock(&ubifs_infos_lock);
  1318. out_orphans:
  1319. free_orphans(c);
  1320. out_journal:
  1321. destroy_journal(c);
  1322. out_lpt:
  1323. ubifs_lpt_free(c, 0);
  1324. out_master:
  1325. kfree(c->mst_node);
  1326. kfree(c->rcvrd_mst_node);
  1327. if (c->bgt)
  1328. kthread_stop(c->bgt);
  1329. out_wbufs:
  1330. free_wbufs(c);
  1331. out_cbuf:
  1332. kfree(c->cbuf);
  1333. out_free:
  1334. kfree(c->write_reserve_buf);
  1335. kfree(c->bu.buf);
  1336. vfree(c->ileb_buf);
  1337. vfree(c->sbuf);
  1338. kfree(c->bottom_up_buf);
  1339. ubifs_debugging_exit(c);
  1340. return err;
  1341. }
  1342. /**
  1343. * ubifs_umount - un-mount UBIFS file-system.
  1344. * @c: UBIFS file-system description object
  1345. *
  1346. * Note, this function is called to free allocated resourced when un-mounting,
  1347. * as well as free resources when an error occurred while we were half way
  1348. * through mounting (error path cleanup function). So it has to make sure the
  1349. * resource was actually allocated before freeing it.
  1350. */
  1351. static void ubifs_umount(struct ubifs_info *c)
  1352. {
  1353. dbg_gen("un-mounting UBI device %d, volume %d", c->vi.ubi_num,
  1354. c->vi.vol_id);
  1355. dbg_debugfs_exit_fs(c);
  1356. spin_lock(&ubifs_infos_lock);
  1357. list_del(&c->infos_list);
  1358. spin_unlock(&ubifs_infos_lock);
  1359. if (c->bgt)
  1360. kthread_stop(c->bgt);
  1361. destroy_journal(c);
  1362. free_wbufs(c);
  1363. free_orphans(c);
  1364. ubifs_lpt_free(c, 0);
  1365. kfree(c->cbuf);
  1366. kfree(c->rcvrd_mst_node);
  1367. kfree(c->mst_node);
  1368. kfree(c->write_reserve_buf);
  1369. kfree(c->bu.buf);
  1370. vfree(c->ileb_buf);
  1371. vfree(c->sbuf);
  1372. kfree(c->bottom_up_buf);
  1373. ubifs_debugging_exit(c);
  1374. }
  1375. /**
  1376. * ubifs_remount_rw - re-mount in read-write mode.
  1377. * @c: UBIFS file-system description object
  1378. *
  1379. * UBIFS avoids allocating many unnecessary resources when mounted in read-only
  1380. * mode. This function allocates the needed resources and re-mounts UBIFS in
  1381. * read-write mode.
  1382. */
  1383. static int ubifs_remount_rw(struct ubifs_info *c)
  1384. {
  1385. int err, lnum;
  1386. if (c->rw_incompat) {
  1387. ubifs_err("the file-system is not R/W-compatible");
  1388. ubifs_msg("on-flash format version is w%d/r%d, but software "
  1389. "only supports up to version w%d/r%d", c->fmt_version,
  1390. c->ro_compat_version, UBIFS_FORMAT_VERSION,
  1391. UBIFS_RO_COMPAT_VERSION);
  1392. return -EROFS;
  1393. }
  1394. mutex_lock(&c->umount_mutex);
  1395. dbg_save_space_info(c);
  1396. c->remounting_rw = 1;
  1397. c->ro_mount = 0;
  1398. if (c->space_fixup) {
  1399. err = ubifs_fixup_free_space(c);
  1400. if (err)
  1401. return err;
  1402. }
  1403. err = check_free_space(c);
  1404. if (err)
  1405. goto out;
  1406. if (c->old_leb_cnt != c->leb_cnt) {
  1407. struct ubifs_sb_node *sup;
  1408. sup = ubifs_read_sb_node(c);
  1409. if (IS_ERR(sup)) {
  1410. err = PTR_ERR(sup);
  1411. goto out;
  1412. }
  1413. sup->leb_cnt = cpu_to_le32(c->leb_cnt);
  1414. err = ubifs_write_sb_node(c, sup);
  1415. kfree(sup);
  1416. if (err)
  1417. goto out;
  1418. }
  1419. if (c->need_recovery) {
  1420. ubifs_msg("completing deferred recovery");
  1421. err = ubifs_write_rcvrd_mst_node(c);
  1422. if (err)
  1423. goto out;
  1424. err = ubifs_recover_size(c);
  1425. if (err)
  1426. goto out;
  1427. err = ubifs_clean_lebs(c, c->sbuf);
  1428. if (err)
  1429. goto out;
  1430. err = ubifs_recover_inl_heads(c, c->sbuf);
  1431. if (err)
  1432. goto out;
  1433. } else {
  1434. /* A readonly mount is not allowed to have orphans */
  1435. ubifs_assert(c->tot_orphans == 0);
  1436. err = ubifs_clear_orphans(c);
  1437. if (err)
  1438. goto out;
  1439. }
  1440. if (!(c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY))) {
  1441. c->mst_node->flags |= cpu_to_le32(UBIFS_MST_DIRTY);
  1442. err = ubifs_write_master(c);
  1443. if (err)
  1444. goto out;
  1445. }
  1446. c->ileb_buf = vmalloc(c->leb_size);
  1447. if (!c->ileb_buf) {
  1448. err = -ENOMEM;
  1449. goto out;
  1450. }
  1451. c->write_reserve_buf = kmalloc(COMPRESSED_DATA_NODE_BUF_SZ, GFP_KERNEL);
  1452. if (!c->write_reserve_buf)
  1453. goto out;
  1454. err = ubifs_lpt_init(c, 0, 1);
  1455. if (err)
  1456. goto out;
  1457. /* Create background thread */
  1458. c->bgt = kthread_create(ubifs_bg_thread, c, "%s", c->bgt_name);
  1459. if (IS_ERR(c->bgt)) {
  1460. err = PTR_ERR(c->bgt);
  1461. c->bgt = NULL;
  1462. ubifs_err("cannot spawn \"%s\", error %d",
  1463. c->bgt_name, err);
  1464. goto out;
  1465. }
  1466. wake_up_process(c->bgt);
  1467. c->orph_buf = vmalloc(c->leb_size);
  1468. if (!c->orph_buf) {
  1469. err = -ENOMEM;
  1470. goto out;
  1471. }
  1472. /* Check for enough log space */
  1473. lnum = c->lhead_lnum + 1;
  1474. if (lnum >= UBIFS_LOG_LNUM + c->log_lebs)
  1475. lnum = UBIFS_LOG_LNUM;
  1476. if (lnum == c->ltail_lnum) {
  1477. err = ubifs_consolidate_log(c);
  1478. if (err)
  1479. goto out;
  1480. }
  1481. if (c->need_recovery)
  1482. err = ubifs_rcvry_gc_commit(c);
  1483. else
  1484. err = ubifs_leb_unmap(c, c->gc_lnum);
  1485. if (err)
  1486. goto out;
  1487. dbg_gen("re-mounted read-write");
  1488. c->remounting_rw = 0;
  1489. if (c->need_recovery) {
  1490. c->need_recovery = 0;
  1491. ubifs_msg("deferred recovery completed");
  1492. } else {
  1493. /*
  1494. * Do not run the debugging space check if the were doing
  1495. * recovery, because when we saved the information we had the
  1496. * file-system in a state where the TNC and lprops has been
  1497. * modified in memory, but all the I/O operations (including a
  1498. * commit) were deferred. So the file-system was in
  1499. * "non-committed" state. Now the file-system is in committed
  1500. * state, and of course the amount of free space will change
  1501. * because, for example, the old index size was imprecise.
  1502. */
  1503. err = dbg_check_space_info(c);
  1504. }
  1505. mutex_unlock(&c->umount_mutex);
  1506. return err;
  1507. out:
  1508. c->ro_mount = 1;
  1509. vfree(c->orph_buf);
  1510. c->orph_buf = NULL;
  1511. if (c->bgt) {
  1512. kthread_stop(c->bgt);
  1513. c->bgt = NULL;
  1514. }
  1515. free_wbufs(c);
  1516. kfree(c->write_reserve_buf);
  1517. c->write_reserve_buf = NULL;
  1518. vfree(c->ileb_buf);
  1519. c->ileb_buf = NULL;
  1520. ubifs_lpt_free(c, 1);
  1521. c->remounting_rw = 0;
  1522. mutex_unlock(&c->umount_mutex);
  1523. return err;
  1524. }
  1525. /**
  1526. * ubifs_remount_ro - re-mount in read-only mode.
  1527. * @c: UBIFS file-system description object
  1528. *
  1529. * We assume VFS has stopped writing. Possibly the background thread could be
  1530. * running a commit, however kthread_stop will wait in that case.
  1531. */
  1532. static void ubifs_remount_ro(struct ubifs_info *c)
  1533. {
  1534. int i, err;
  1535. ubifs_assert(!c->need_recovery);
  1536. ubifs_assert(!c->ro_mount);
  1537. mutex_lock(&c->umount_mutex);
  1538. if (c->bgt) {
  1539. kthread_stop(c->bgt);
  1540. c->bgt = NULL;
  1541. }
  1542. dbg_save_space_info(c);
  1543. for (i = 0; i < c->jhead_cnt; i++)
  1544. ubifs_wbuf_sync(&c->jheads[i].wbuf);
  1545. c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY);
  1546. c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS);
  1547. c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum);
  1548. err = ubifs_write_master(c);
  1549. if (err)
  1550. ubifs_ro_mode(c, err);
  1551. vfree(c->orph_buf);
  1552. c->orph_buf = NULL;
  1553. kfree(c->write_reserve_buf);
  1554. c->write_reserve_buf = NULL;
  1555. vfree(c->ileb_buf);
  1556. c->ileb_buf = NULL;
  1557. ubifs_lpt_free(c, 1);
  1558. c->ro_mount = 1;
  1559. err = dbg_check_space_info(c);
  1560. if (err)
  1561. ubifs_ro_mode(c, err);
  1562. mutex_unlock(&c->umount_mutex);
  1563. }
  1564. static void ubifs_put_super(struct super_block *sb)
  1565. {
  1566. int i;
  1567. struct ubifs_info *c = sb->s_fs_info;
  1568. ubifs_msg("un-mount UBI device %d, volume %d", c->vi.ubi_num,
  1569. c->vi.vol_id);
  1570. /*
  1571. * The following asserts are only valid if there has not been a failure
  1572. * of the media. For example, there will be dirty inodes if we failed
  1573. * to write them back because of I/O errors.
  1574. */
  1575. if (!c->ro_error) {
  1576. ubifs_assert(c->bi.idx_growth == 0);
  1577. ubifs_assert(c->bi.dd_growth == 0);
  1578. ubifs_assert(c->bi.data_growth == 0);
  1579. }
  1580. /*
  1581. * The 'c->umount_lock' prevents races between UBIFS memory shrinker
  1582. * and file system un-mount. Namely, it prevents the shrinker from
  1583. * picking this superblock for shrinking - it will be just skipped if
  1584. * the mutex is locked.
  1585. */
  1586. mutex_lock(&c->umount_mutex);
  1587. if (!c->ro_mount) {
  1588. /*
  1589. * First of all kill the background thread to make sure it does
  1590. * not interfere with un-mounting and freeing resources.
  1591. */
  1592. if (c->bgt) {
  1593. kthread_stop(c->bgt);
  1594. c->bgt = NULL;
  1595. }
  1596. /*
  1597. * On fatal errors c->ro_error is set to 1, in which case we do
  1598. * not write the master node.
  1599. */
  1600. if (!c->ro_error) {
  1601. int err;
  1602. /* Synchronize write-buffers */
  1603. for (i = 0; i < c->jhead_cnt; i++)
  1604. ubifs_wbuf_sync(&c->jheads[i].wbuf);
  1605. /*
  1606. * We are being cleanly unmounted which means the
  1607. * orphans were killed - indicate this in the master
  1608. * node. Also save the reserved GC LEB number.
  1609. */
  1610. c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY);
  1611. c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS);
  1612. c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum);
  1613. err = ubifs_write_master(c);
  1614. if (err)
  1615. /*
  1616. * Recovery will attempt to fix the master area
  1617. * next mount, so we just print a message and
  1618. * continue to unmount normally.
  1619. */
  1620. ubifs_err("failed to write master node, "
  1621. "error %d", err);
  1622. } else {
  1623. for (i = 0; i < c->jhead_cnt; i++)
  1624. /* Make sure write-buffer timers are canceled */
  1625. hrtimer_cancel(&c->jheads[i].wbuf.timer);
  1626. }
  1627. }
  1628. ubifs_umount(c);
  1629. bdi_destroy(&c->bdi);
  1630. ubi_close_volume(c->ubi);
  1631. mutex_unlock(&c->umount_mutex);
  1632. }
  1633. static int ubifs_remount_fs(struct super_block *sb, int *flags, char *data)
  1634. {
  1635. int err;
  1636. struct ubifs_info *c = sb->s_fs_info;
  1637. sync_filesystem(sb);
  1638. dbg_gen("old flags %#lx, new flags %#x", sb->s_flags, *flags);
  1639. err = ubifs_parse_options(c, data, 1);
  1640. if (err) {
  1641. ubifs_err("invalid or unknown remount parameter");
  1642. return err;
  1643. }
  1644. if (c->ro_mount && !(*flags & MS_RDONLY)) {
  1645. if (c->ro_error) {
  1646. ubifs_msg("cannot re-mount R/W due to prior errors");
  1647. return -EROFS;
  1648. }
  1649. if (c->ro_media) {
  1650. ubifs_msg("cannot re-mount R/W - UBI volume is R/O");
  1651. return -EROFS;
  1652. }
  1653. err = ubifs_remount_rw(c);
  1654. if (err)
  1655. return err;
  1656. } else if (!c->ro_mount && (*flags & MS_RDONLY)) {
  1657. if (c->ro_error) {
  1658. ubifs_msg("cannot re-mount R/O due to prior errors");
  1659. return -EROFS;
  1660. }
  1661. ubifs_remount_ro(c);
  1662. }
  1663. if (c->bulk_read == 1)
  1664. bu_init(c);
  1665. else {
  1666. dbg_gen("disable bulk-read");
  1667. kfree(c->bu.buf);
  1668. c->bu.buf = NULL;
  1669. }
  1670. ubifs_assert(c->lst.taken_empty_lebs > 0);
  1671. return 0;
  1672. }
  1673. const struct super_operations ubifs_super_operations = {
  1674. .alloc_inode = ubifs_alloc_inode,
  1675. .destroy_inode = ubifs_destroy_inode,
  1676. .put_super = ubifs_put_super,
  1677. .write_inode = ubifs_write_inode,
  1678. .evict_inode = ubifs_evict_inode,
  1679. .statfs = ubifs_statfs,
  1680. .dirty_inode = ubifs_dirty_inode,
  1681. .remount_fs = ubifs_remount_fs,
  1682. .show_options = ubifs_show_options,
  1683. .sync_fs = ubifs_sync_fs,
  1684. };
  1685. /**
  1686. * open_ubi - parse UBI device name string and open the UBI device.
  1687. * @name: UBI volume name
  1688. * @mode: UBI volume open mode
  1689. *
  1690. * The primary method of mounting UBIFS is by specifying the UBI volume
  1691. * character device node path. However, UBIFS may also be mounted withoug any
  1692. * character device node using one of the following methods:
  1693. *
  1694. * o ubiX_Y - mount UBI device number X, volume Y;
  1695. * o ubiY - mount UBI device number 0, volume Y;
  1696. * o ubiX:NAME - mount UBI device X, volume with name NAME;
  1697. * o ubi:NAME - mount UBI device 0, volume with name NAME.
  1698. *
  1699. * Alternative '!' separator may be used instead of ':' (because some shells
  1700. * like busybox may interpret ':' as an NFS host name separator). This function
  1701. * returns UBI volume description object in case of success and a negative
  1702. * error code in case of failure.
  1703. */
  1704. static struct ubi_volume_desc *open_ubi(const char *name, int mode)
  1705. {
  1706. struct ubi_volume_desc *ubi;
  1707. int dev, vol;
  1708. char *endptr;
  1709. /* First, try to open using the device node path method */
  1710. ubi = ubi_open_volume_path(name, mode);
  1711. if (!IS_ERR(ubi))
  1712. return ubi;
  1713. /* Try the "nodev" method */
  1714. if (name[0] != 'u' || name[1] != 'b' || name[2] != 'i')
  1715. return ERR_PTR(-EINVAL);
  1716. /* ubi:NAME method */
  1717. if ((name[3] == ':' || name[3] == '!') && name[4] != '\0')
  1718. return ubi_open_volume_nm(0, name + 4, mode);
  1719. if (!isdigit(name[3]))
  1720. return ERR_PTR(-EINVAL);
  1721. dev = simple_strtoul(name + 3, &endptr, 0);
  1722. /* ubiY method */
  1723. if (*endptr == '\0')
  1724. return ubi_open_volume(0, dev, mode);
  1725. /* ubiX_Y method */
  1726. if (*endptr == '_' && isdigit(endptr[1])) {
  1727. vol = simple_strtoul(endptr + 1, &endptr, 0);
  1728. if (*endptr != '\0')
  1729. return ERR_PTR(-EINVAL);
  1730. return ubi_open_volume(dev, vol, mode);
  1731. }
  1732. /* ubiX:NAME method */
  1733. if ((*endptr == ':' || *endptr == '!') && endptr[1] != '\0')
  1734. return ubi_open_volume_nm(dev, ++endptr, mode);
  1735. return ERR_PTR(-EINVAL);
  1736. }
  1737. static struct ubifs_info *alloc_ubifs_info(struct ubi_volume_desc *ubi)
  1738. {
  1739. struct ubifs_info *c;
  1740. c = kzalloc(sizeof(struct ubifs_info), GFP_KERNEL);
  1741. if (c) {
  1742. spin_lock_init(&c->cnt_lock);
  1743. spin_lock_init(&c->cs_lock);
  1744. spin_lock_init(&c->buds_lock);
  1745. spin_lock_init(&c->space_lock);
  1746. spin_lock_init(&c->orphan_lock);
  1747. init_rwsem(&c->commit_sem);
  1748. mutex_init(&c->lp_mutex);
  1749. mutex_init(&c->tnc_mutex);
  1750. mutex_init(&c->log_mutex);
  1751. mutex_init(&c->umount_mutex);
  1752. mutex_init(&c->bu_mutex);
  1753. mutex_init(&c->write_reserve_mutex);
  1754. init_waitqueue_head(&c->cmt_wq);
  1755. c->buds = RB_ROOT;
  1756. c->old_idx = RB_ROOT;
  1757. c->size_tree = RB_ROOT;
  1758. c->orph_tree = RB_ROOT;
  1759. INIT_LIST_HEAD(&c->infos_list);
  1760. INIT_LIST_HEAD(&c->idx_gc);
  1761. INIT_LIST_HEAD(&c->replay_list);
  1762. INIT_LIST_HEAD(&c->replay_buds);
  1763. INIT_LIST_HEAD(&c->uncat_list);
  1764. INIT_LIST_HEAD(&c->empty_list);
  1765. INIT_LIST_HEAD(&c->freeable_list);
  1766. INIT_LIST_HEAD(&c->frdi_idx_list);
  1767. INIT_LIST_HEAD(&c->unclean_leb_list);
  1768. INIT_LIST_HEAD(&c->old_buds);
  1769. INIT_LIST_HEAD(&c->orph_list);
  1770. INIT_LIST_HEAD(&c->orph_new);
  1771. c->no_chk_data_crc = 1;
  1772. c->highest_inum = UBIFS_FIRST_INO;
  1773. c->lhead_lnum = c->ltail_lnum = UBIFS_LOG_LNUM;
  1774. ubi_get_volume_info(ubi, &c->vi);
  1775. ubi_get_device_info(c->vi.ubi_num, &c->di);
  1776. }
  1777. return c;
  1778. }
  1779. static int ubifs_fill_super(struct super_block *sb, void *data, int silent)
  1780. {
  1781. struct ubifs_info *c = sb->s_fs_info;
  1782. struct inode *root;
  1783. int err;
  1784. c->vfs_sb = sb;
  1785. /* Re-open the UBI device in read-write mode */
  1786. c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READWRITE);
  1787. if (IS_ERR(c->ubi)) {
  1788. err = PTR_ERR(c->ubi);
  1789. goto out;
  1790. }
  1791. /*
  1792. * UBIFS provides 'backing_dev_info' in order to disable read-ahead. For
  1793. * UBIFS, I/O is not deferred, it is done immediately in readpage,
  1794. * which means the user would have to wait not just for their own I/O
  1795. * but the read-ahead I/O as well i.e. completely pointless.
  1796. *
  1797. * Read-ahead will be disabled because @c->bdi.ra_pages is 0.
  1798. */
  1799. c->bdi.name = "ubifs",
  1800. c->bdi.capabilities = BDI_CAP_MAP_COPY;
  1801. err = bdi_init(&c->bdi);
  1802. if (err)
  1803. goto out_close;
  1804. err = bdi_register(&c->bdi, NULL, "ubifs_%d_%d",
  1805. c->vi.ubi_num, c->vi.vol_id);
  1806. if (err)
  1807. goto out_bdi;
  1808. err = ubifs_parse_options(c, data, 0);
  1809. if (err)
  1810. goto out_bdi;
  1811. sb->s_bdi = &c->bdi;
  1812. sb->s_fs_info = c;
  1813. sb->s_magic = UBIFS_SUPER_MAGIC;
  1814. sb->s_blocksize = UBIFS_BLOCK_SIZE;
  1815. sb->s_blocksize_bits = UBIFS_BLOCK_SHIFT;
  1816. sb->s_maxbytes = c->max_inode_sz = key_max_inode_size(c);
  1817. if (c->max_inode_sz > MAX_LFS_FILESIZE)
  1818. sb->s_maxbytes = c->max_inode_sz = MAX_LFS_FILESIZE;
  1819. sb->s_op = &ubifs_super_operations;
  1820. mutex_lock(&c->umount_mutex);
  1821. err = mount_ubifs(c);
  1822. if (err) {
  1823. ubifs_assert(err < 0);
  1824. goto out_unlock;
  1825. }
  1826. /* Read the root inode */
  1827. root = ubifs_iget(sb, UBIFS_ROOT_INO);
  1828. if (IS_ERR(root)) {
  1829. err = PTR_ERR(root);
  1830. goto out_umount;
  1831. }
  1832. sb->s_root = d_make_root(root);
  1833. if (!sb->s_root)
  1834. goto out_umount;
  1835. mutex_unlock(&c->umount_mutex);
  1836. return 0;
  1837. out_umount:
  1838. ubifs_umount(c);
  1839. out_unlock:
  1840. mutex_unlock(&c->umount_mutex);
  1841. out_bdi:
  1842. bdi_destroy(&c->bdi);
  1843. out_close:
  1844. ubi_close_volume(c->ubi);
  1845. out:
  1846. return err;
  1847. }
  1848. static int sb_test(struct super_block *sb, void *data)
  1849. {
  1850. struct ubifs_info *c1 = data;
  1851. struct ubifs_info *c = sb->s_fs_info;
  1852. return c->vi.cdev == c1->vi.cdev;
  1853. }
  1854. static int sb_set(struct super_block *sb, void *data)
  1855. {
  1856. sb->s_fs_info = data;
  1857. return set_anon_super(sb, NULL);
  1858. }
  1859. static struct dentry *ubifs_mount(struct file_system_type *fs_type, int flags,
  1860. const char *name, void *data)
  1861. {
  1862. struct ubi_volume_desc *ubi;
  1863. struct ubifs_info *c;
  1864. struct super_block *sb;
  1865. int err;
  1866. dbg_gen("name %s, flags %#x", name, flags);
  1867. /*
  1868. * Get UBI device number and volume ID. Mount it read-only so far
  1869. * because this might be a new mount point, and UBI allows only one
  1870. * read-write user at a time.
  1871. */
  1872. ubi = open_ubi(name, UBI_READONLY);
  1873. if (IS_ERR(ubi)) {
  1874. dbg_err("cannot open \"%s\", error %d",
  1875. name, (int)PTR_ERR(ubi));
  1876. return ERR_CAST(ubi);
  1877. }
  1878. c = alloc_ubifs_info(ubi);
  1879. if (!c) {
  1880. err = -ENOMEM;
  1881. goto out_close;
  1882. }
  1883. dbg_gen("opened ubi%d_%d", c->vi.ubi_num, c->vi.vol_id);
  1884. sb = sget(fs_type, sb_test, sb_set, flags, c);
  1885. if (IS_ERR(sb)) {
  1886. err = PTR_ERR(sb);
  1887. kfree(c);
  1888. goto out_close;
  1889. }
  1890. if (sb->s_root) {
  1891. struct ubifs_info *c1 = sb->s_fs_info;
  1892. kfree(c);
  1893. /* A new mount point for already mounted UBIFS */
  1894. dbg_gen("this ubi volume is already mounted");
  1895. if (!!(flags & MS_RDONLY) != c1->ro_mount) {
  1896. err = -EBUSY;
  1897. goto out_deact;
  1898. }
  1899. } else {
  1900. err = ubifs_fill_super(sb, data, flags & MS_SILENT ? 1 : 0);
  1901. if (err)
  1902. goto out_deact;
  1903. /* We do not support atime */
  1904. sb->s_flags |= MS_ACTIVE | MS_NOATIME;
  1905. }
  1906. /* 'fill_super()' opens ubi again so we must close it here */
  1907. ubi_close_volume(ubi);
  1908. return dget(sb->s_root);
  1909. out_deact:
  1910. deactivate_locked_super(sb);
  1911. out_close:
  1912. ubi_close_volume(ubi);
  1913. return ERR_PTR(err);
  1914. }
  1915. static void kill_ubifs_super(struct super_block *s)
  1916. {
  1917. struct ubifs_info *c = s->s_fs_info;
  1918. kill_anon_super(s);
  1919. kfree(c);
  1920. }
  1921. static struct file_system_type ubifs_fs_type = {
  1922. .name = "ubifs",
  1923. .owner = THIS_MODULE,
  1924. .mount = ubifs_mount,
  1925. .kill_sb = kill_ubifs_super,
  1926. };
  1927. MODULE_ALIAS_FS("ubifs");
  1928. /*
  1929. * Inode slab cache constructor.
  1930. */
  1931. static void inode_slab_ctor(void *obj)
  1932. {
  1933. struct ubifs_inode *ui = obj;
  1934. inode_init_once(&ui->vfs_inode);
  1935. }
  1936. static int __init ubifs_init(void)
  1937. {
  1938. int err;
  1939. BUILD_BUG_ON(sizeof(struct ubifs_ch) != 24);
  1940. /* Make sure node sizes are 8-byte aligned */
  1941. BUILD_BUG_ON(UBIFS_CH_SZ & 7);
  1942. BUILD_BUG_ON(UBIFS_INO_NODE_SZ & 7);
  1943. BUILD_BUG_ON(UBIFS_DENT_NODE_SZ & 7);
  1944. BUILD_BUG_ON(UBIFS_XENT_NODE_SZ & 7);
  1945. BUILD_BUG_ON(UBIFS_DATA_NODE_SZ & 7);
  1946. BUILD_BUG_ON(UBIFS_TRUN_NODE_SZ & 7);
  1947. BUILD_BUG_ON(UBIFS_SB_NODE_SZ & 7);
  1948. BUILD_BUG_ON(UBIFS_MST_NODE_SZ & 7);
  1949. BUILD_BUG_ON(UBIFS_REF_NODE_SZ & 7);
  1950. BUILD_BUG_ON(UBIFS_CS_NODE_SZ & 7);
  1951. BUILD_BUG_ON(UBIFS_ORPH_NODE_SZ & 7);
  1952. BUILD_BUG_ON(UBIFS_MAX_DENT_NODE_SZ & 7);
  1953. BUILD_BUG_ON(UBIFS_MAX_XENT_NODE_SZ & 7);
  1954. BUILD_BUG_ON(UBIFS_MAX_DATA_NODE_SZ & 7);
  1955. BUILD_BUG_ON(UBIFS_MAX_INO_NODE_SZ & 7);
  1956. BUILD_BUG_ON(UBIFS_MAX_NODE_SZ & 7);
  1957. BUILD_BUG_ON(MIN_WRITE_SZ & 7);
  1958. /* Check min. node size */
  1959. BUILD_BUG_ON(UBIFS_INO_NODE_SZ < MIN_WRITE_SZ);
  1960. BUILD_BUG_ON(UBIFS_DENT_NODE_SZ < MIN_WRITE_SZ);
  1961. BUILD_BUG_ON(UBIFS_XENT_NODE_SZ < MIN_WRITE_SZ);
  1962. BUILD_BUG_ON(UBIFS_TRUN_NODE_SZ < MIN_WRITE_SZ);
  1963. BUILD_BUG_ON(UBIFS_MAX_DENT_NODE_SZ > UBIFS_MAX_NODE_SZ);
  1964. BUILD_BUG_ON(UBIFS_MAX_XENT_NODE_SZ > UBIFS_MAX_NODE_SZ);
  1965. BUILD_BUG_ON(UBIFS_MAX_DATA_NODE_SZ > UBIFS_MAX_NODE_SZ);
  1966. BUILD_BUG_ON(UBIFS_MAX_INO_NODE_SZ > UBIFS_MAX_NODE_SZ);
  1967. /* Defined node sizes */
  1968. BUILD_BUG_ON(UBIFS_SB_NODE_SZ != 4096);
  1969. BUILD_BUG_ON(UBIFS_MST_NODE_SZ != 512);
  1970. BUILD_BUG_ON(UBIFS_INO_NODE_SZ != 160);
  1971. BUILD_BUG_ON(UBIFS_REF_NODE_SZ != 64);
  1972. /*
  1973. * We use 2 bit wide bit-fields to store compression type, which should
  1974. * be amended if more compressors are added. The bit-fields are:
  1975. * @compr_type in 'struct ubifs_inode', @default_compr in
  1976. * 'struct ubifs_info' and @compr_type in 'struct ubifs_mount_opts'.
  1977. */
  1978. BUILD_BUG_ON(UBIFS_COMPR_TYPES_CNT > 4);
  1979. /*
  1980. * We require that PAGE_CACHE_SIZE is greater-than-or-equal-to
  1981. * UBIFS_BLOCK_SIZE. It is assumed that both are powers of 2.
  1982. */
  1983. if (PAGE_CACHE_SIZE < UBIFS_BLOCK_SIZE) {
  1984. ubifs_err("VFS page cache size is %u bytes, but UBIFS requires"
  1985. " at least 4096 bytes",
  1986. (unsigned int)PAGE_CACHE_SIZE);
  1987. return -EINVAL;
  1988. }
  1989. ubifs_inode_slab = kmem_cache_create("ubifs_inode_slab",
  1990. sizeof(struct ubifs_inode), 0,
  1991. SLAB_MEM_SPREAD | SLAB_RECLAIM_ACCOUNT,
  1992. &inode_slab_ctor);
  1993. if (!ubifs_inode_slab)
  1994. return -ENOMEM;
  1995. register_shrinker(&ubifs_shrinker_info);
  1996. err = ubifs_compressors_init();
  1997. if (err)
  1998. goto out_shrinker;
  1999. err = dbg_debugfs_init();
  2000. if (err)
  2001. goto out_compr;
  2002. err = register_filesystem(&ubifs_fs_type);
  2003. if (err) {
  2004. ubifs_err("cannot register file system, error %d", err);
  2005. goto out_dbg;
  2006. }
  2007. return 0;
  2008. out_dbg:
  2009. dbg_debugfs_exit();
  2010. out_compr:
  2011. ubifs_compressors_exit();
  2012. out_shrinker:
  2013. unregister_shrinker(&ubifs_shrinker_info);
  2014. kmem_cache_destroy(ubifs_inode_slab);
  2015. return err;
  2016. }
  2017. /* late_initcall to let compressors initialize first */
  2018. late_initcall(ubifs_init);
  2019. static void __exit ubifs_exit(void)
  2020. {
  2021. ubifs_assert(list_empty(&ubifs_infos));
  2022. ubifs_assert(atomic_long_read(&ubifs_clean_zn_cnt) == 0);
  2023. dbg_debugfs_exit();
  2024. ubifs_compressors_exit();
  2025. unregister_shrinker(&ubifs_shrinker_info);
  2026. /*
  2027. * Make sure all delayed rcu free inodes are flushed before we
  2028. * destroy cache.
  2029. */
  2030. rcu_barrier();
  2031. kmem_cache_destroy(ubifs_inode_slab);
  2032. unregister_filesystem(&ubifs_fs_type);
  2033. }
  2034. module_exit(ubifs_exit);
  2035. MODULE_LICENSE("GPL");
  2036. MODULE_VERSION(__stringify(UBIFS_VERSION));
  2037. MODULE_AUTHOR("Artem Bityutskiy, Adrian Hunter");
  2038. MODULE_DESCRIPTION("UBIFS - UBI File System");