super.c 60 KB

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