super.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/fs/ext2/super.c
  4. *
  5. * Copyright (C) 1992, 1993, 1994, 1995
  6. * Remy Card (card@masi.ibp.fr)
  7. * Laboratoire MASI - Institut Blaise Pascal
  8. * Universite Pierre et Marie Curie (Paris VI)
  9. *
  10. * from
  11. *
  12. * linux/fs/minix/inode.c
  13. *
  14. * Copyright (C) 1991, 1992 Linus Torvalds
  15. *
  16. * Big-endian to little-endian byte-swapping/bitmaps by
  17. * David S. Miller (davem@caip.rutgers.edu), 1995
  18. */
  19. #include <linux/module.h>
  20. #include <linux/string.h>
  21. #include <linux/fs.h>
  22. #include <linux/slab.h>
  23. #include <linux/init.h>
  24. #include <linux/blkdev.h>
  25. #include <linux/parser.h>
  26. #include <linux/random.h>
  27. #include <linux/buffer_head.h>
  28. #include <linux/exportfs.h>
  29. #include <linux/vfs.h>
  30. #include <linux/seq_file.h>
  31. #include <linux/mount.h>
  32. #include <linux/log2.h>
  33. #include <linux/quotaops.h>
  34. #include <linux/uaccess.h>
  35. #include <linux/dax.h>
  36. #include <linux/iversion.h>
  37. #include "ext2.h"
  38. #include "xattr.h"
  39. #include "acl.h"
  40. static void ext2_write_super(struct super_block *sb);
  41. static int ext2_remount (struct super_block * sb, int * flags, char * data);
  42. static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf);
  43. static int ext2_sync_fs(struct super_block *sb, int wait);
  44. static int ext2_freeze(struct super_block *sb);
  45. static int ext2_unfreeze(struct super_block *sb);
  46. void ext2_error(struct super_block *sb, const char *function,
  47. const char *fmt, ...)
  48. {
  49. struct va_format vaf;
  50. va_list args;
  51. struct ext2_sb_info *sbi = EXT2_SB(sb);
  52. struct ext2_super_block *es = sbi->s_es;
  53. if (!sb_rdonly(sb)) {
  54. spin_lock(&sbi->s_lock);
  55. sbi->s_mount_state |= EXT2_ERROR_FS;
  56. es->s_state |= cpu_to_le16(EXT2_ERROR_FS);
  57. spin_unlock(&sbi->s_lock);
  58. ext2_sync_super(sb, es, 1);
  59. }
  60. va_start(args, fmt);
  61. vaf.fmt = fmt;
  62. vaf.va = &args;
  63. printk(KERN_CRIT "EXT2-fs (%s): error: %s: %pV\n",
  64. sb->s_id, function, &vaf);
  65. va_end(args);
  66. if (test_opt(sb, ERRORS_PANIC))
  67. panic("EXT2-fs: panic from previous error\n");
  68. if (!sb_rdonly(sb) && test_opt(sb, ERRORS_RO)) {
  69. ext2_msg(sb, KERN_CRIT,
  70. "error: remounting filesystem read-only");
  71. sb->s_flags |= SB_RDONLY;
  72. }
  73. }
  74. void ext2_msg(struct super_block *sb, const char *prefix,
  75. const char *fmt, ...)
  76. {
  77. struct va_format vaf;
  78. va_list args;
  79. va_start(args, fmt);
  80. vaf.fmt = fmt;
  81. vaf.va = &args;
  82. printk("%sEXT2-fs (%s): %pV\n", prefix, sb->s_id, &vaf);
  83. va_end(args);
  84. }
  85. /*
  86. * This must be called with sbi->s_lock held.
  87. */
  88. void ext2_update_dynamic_rev(struct super_block *sb)
  89. {
  90. struct ext2_super_block *es = EXT2_SB(sb)->s_es;
  91. if (le32_to_cpu(es->s_rev_level) > EXT2_GOOD_OLD_REV)
  92. return;
  93. ext2_msg(sb, KERN_WARNING,
  94. "warning: updating to rev %d because of "
  95. "new feature flag, running e2fsck is recommended",
  96. EXT2_DYNAMIC_REV);
  97. es->s_first_ino = cpu_to_le32(EXT2_GOOD_OLD_FIRST_INO);
  98. es->s_inode_size = cpu_to_le16(EXT2_GOOD_OLD_INODE_SIZE);
  99. es->s_rev_level = cpu_to_le32(EXT2_DYNAMIC_REV);
  100. /* leave es->s_feature_*compat flags alone */
  101. /* es->s_uuid will be set by e2fsck if empty */
  102. /*
  103. * The rest of the superblock fields should be zero, and if not it
  104. * means they are likely already in use, so leave them alone. We
  105. * can leave it up to e2fsck to clean up any inconsistencies there.
  106. */
  107. }
  108. #ifdef CONFIG_QUOTA
  109. static int ext2_quota_off(struct super_block *sb, int type);
  110. static void ext2_quota_off_umount(struct super_block *sb)
  111. {
  112. int type;
  113. for (type = 0; type < MAXQUOTAS; type++)
  114. ext2_quota_off(sb, type);
  115. }
  116. #else
  117. static inline void ext2_quota_off_umount(struct super_block *sb)
  118. {
  119. }
  120. #endif
  121. static void ext2_put_super (struct super_block * sb)
  122. {
  123. int db_count;
  124. int i;
  125. struct ext2_sb_info *sbi = EXT2_SB(sb);
  126. ext2_quota_off_umount(sb);
  127. ext2_xattr_destroy_cache(sbi->s_ea_block_cache);
  128. sbi->s_ea_block_cache = NULL;
  129. if (!sb_rdonly(sb)) {
  130. struct ext2_super_block *es = sbi->s_es;
  131. spin_lock(&sbi->s_lock);
  132. es->s_state = cpu_to_le16(sbi->s_mount_state);
  133. spin_unlock(&sbi->s_lock);
  134. ext2_sync_super(sb, es, 1);
  135. }
  136. db_count = sbi->s_gdb_count;
  137. for (i = 0; i < db_count; i++)
  138. brelse(sbi->s_group_desc[i]);
  139. kfree(sbi->s_group_desc);
  140. kfree(sbi->s_debts);
  141. percpu_counter_destroy(&sbi->s_freeblocks_counter);
  142. percpu_counter_destroy(&sbi->s_freeinodes_counter);
  143. percpu_counter_destroy(&sbi->s_dirs_counter);
  144. brelse (sbi->s_sbh);
  145. sb->s_fs_info = NULL;
  146. kfree(sbi->s_blockgroup_lock);
  147. fs_put_dax(sbi->s_daxdev);
  148. kfree(sbi);
  149. }
  150. static struct kmem_cache * ext2_inode_cachep;
  151. static struct inode *ext2_alloc_inode(struct super_block *sb)
  152. {
  153. struct ext2_inode_info *ei;
  154. ei = kmem_cache_alloc(ext2_inode_cachep, GFP_KERNEL);
  155. if (!ei)
  156. return NULL;
  157. ei->i_block_alloc_info = NULL;
  158. inode_set_iversion(&ei->vfs_inode, 1);
  159. #ifdef CONFIG_QUOTA
  160. memset(&ei->i_dquot, 0, sizeof(ei->i_dquot));
  161. #endif
  162. return &ei->vfs_inode;
  163. }
  164. static void ext2_free_in_core_inode(struct inode *inode)
  165. {
  166. kmem_cache_free(ext2_inode_cachep, EXT2_I(inode));
  167. }
  168. static void init_once(void *foo)
  169. {
  170. struct ext2_inode_info *ei = (struct ext2_inode_info *) foo;
  171. rwlock_init(&ei->i_meta_lock);
  172. #ifdef CONFIG_EXT2_FS_XATTR
  173. init_rwsem(&ei->xattr_sem);
  174. #endif
  175. mutex_init(&ei->truncate_mutex);
  176. #ifdef CONFIG_FS_DAX
  177. init_rwsem(&ei->dax_sem);
  178. #endif
  179. inode_init_once(&ei->vfs_inode);
  180. }
  181. static int __init init_inodecache(void)
  182. {
  183. ext2_inode_cachep = kmem_cache_create_usercopy("ext2_inode_cache",
  184. sizeof(struct ext2_inode_info), 0,
  185. (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
  186. SLAB_ACCOUNT),
  187. offsetof(struct ext2_inode_info, i_data),
  188. sizeof_field(struct ext2_inode_info, i_data),
  189. init_once);
  190. if (ext2_inode_cachep == NULL)
  191. return -ENOMEM;
  192. return 0;
  193. }
  194. static void destroy_inodecache(void)
  195. {
  196. /*
  197. * Make sure all delayed rcu free inodes are flushed before we
  198. * destroy cache.
  199. */
  200. rcu_barrier();
  201. kmem_cache_destroy(ext2_inode_cachep);
  202. }
  203. static int ext2_show_options(struct seq_file *seq, struct dentry *root)
  204. {
  205. struct super_block *sb = root->d_sb;
  206. struct ext2_sb_info *sbi = EXT2_SB(sb);
  207. struct ext2_super_block *es = sbi->s_es;
  208. unsigned long def_mount_opts;
  209. spin_lock(&sbi->s_lock);
  210. def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
  211. if (sbi->s_sb_block != 1)
  212. seq_printf(seq, ",sb=%lu", sbi->s_sb_block);
  213. if (test_opt(sb, MINIX_DF))
  214. seq_puts(seq, ",minixdf");
  215. if (test_opt(sb, GRPID))
  216. seq_puts(seq, ",grpid");
  217. if (!test_opt(sb, GRPID) && (def_mount_opts & EXT2_DEFM_BSDGROUPS))
  218. seq_puts(seq, ",nogrpid");
  219. if (!uid_eq(sbi->s_resuid, make_kuid(&init_user_ns, EXT2_DEF_RESUID)) ||
  220. le16_to_cpu(es->s_def_resuid) != EXT2_DEF_RESUID) {
  221. seq_printf(seq, ",resuid=%u",
  222. from_kuid_munged(&init_user_ns, sbi->s_resuid));
  223. }
  224. if (!gid_eq(sbi->s_resgid, make_kgid(&init_user_ns, EXT2_DEF_RESGID)) ||
  225. le16_to_cpu(es->s_def_resgid) != EXT2_DEF_RESGID) {
  226. seq_printf(seq, ",resgid=%u",
  227. from_kgid_munged(&init_user_ns, sbi->s_resgid));
  228. }
  229. if (test_opt(sb, ERRORS_RO)) {
  230. int def_errors = le16_to_cpu(es->s_errors);
  231. if (def_errors == EXT2_ERRORS_PANIC ||
  232. def_errors == EXT2_ERRORS_CONTINUE) {
  233. seq_puts(seq, ",errors=remount-ro");
  234. }
  235. }
  236. if (test_opt(sb, ERRORS_CONT))
  237. seq_puts(seq, ",errors=continue");
  238. if (test_opt(sb, ERRORS_PANIC))
  239. seq_puts(seq, ",errors=panic");
  240. if (test_opt(sb, NO_UID32))
  241. seq_puts(seq, ",nouid32");
  242. if (test_opt(sb, DEBUG))
  243. seq_puts(seq, ",debug");
  244. if (test_opt(sb, OLDALLOC))
  245. seq_puts(seq, ",oldalloc");
  246. #ifdef CONFIG_EXT2_FS_XATTR
  247. if (test_opt(sb, XATTR_USER))
  248. seq_puts(seq, ",user_xattr");
  249. if (!test_opt(sb, XATTR_USER) &&
  250. (def_mount_opts & EXT2_DEFM_XATTR_USER)) {
  251. seq_puts(seq, ",nouser_xattr");
  252. }
  253. #endif
  254. #ifdef CONFIG_EXT2_FS_POSIX_ACL
  255. if (test_opt(sb, POSIX_ACL))
  256. seq_puts(seq, ",acl");
  257. if (!test_opt(sb, POSIX_ACL) && (def_mount_opts & EXT2_DEFM_ACL))
  258. seq_puts(seq, ",noacl");
  259. #endif
  260. if (test_opt(sb, NOBH))
  261. seq_puts(seq, ",nobh");
  262. if (test_opt(sb, USRQUOTA))
  263. seq_puts(seq, ",usrquota");
  264. if (test_opt(sb, GRPQUOTA))
  265. seq_puts(seq, ",grpquota");
  266. if (test_opt(sb, XIP))
  267. seq_puts(seq, ",xip");
  268. if (test_opt(sb, DAX))
  269. seq_puts(seq, ",dax");
  270. if (!test_opt(sb, RESERVATION))
  271. seq_puts(seq, ",noreservation");
  272. spin_unlock(&sbi->s_lock);
  273. return 0;
  274. }
  275. #ifdef CONFIG_QUOTA
  276. static ssize_t ext2_quota_read(struct super_block *sb, int type, char *data, size_t len, loff_t off);
  277. static ssize_t ext2_quota_write(struct super_block *sb, int type, const char *data, size_t len, loff_t off);
  278. static int ext2_quota_on(struct super_block *sb, int type, int format_id,
  279. const struct path *path);
  280. static struct dquot **ext2_get_dquots(struct inode *inode)
  281. {
  282. return EXT2_I(inode)->i_dquot;
  283. }
  284. static const struct quotactl_ops ext2_quotactl_ops = {
  285. .quota_on = ext2_quota_on,
  286. .quota_off = ext2_quota_off,
  287. .quota_sync = dquot_quota_sync,
  288. .get_state = dquot_get_state,
  289. .set_info = dquot_set_dqinfo,
  290. .get_dqblk = dquot_get_dqblk,
  291. .set_dqblk = dquot_set_dqblk,
  292. .get_nextdqblk = dquot_get_next_dqblk,
  293. };
  294. #endif
  295. static const struct super_operations ext2_sops = {
  296. .alloc_inode = ext2_alloc_inode,
  297. .free_inode = ext2_free_in_core_inode,
  298. .write_inode = ext2_write_inode,
  299. .evict_inode = ext2_evict_inode,
  300. .put_super = ext2_put_super,
  301. .sync_fs = ext2_sync_fs,
  302. .freeze_fs = ext2_freeze,
  303. .unfreeze_fs = ext2_unfreeze,
  304. .statfs = ext2_statfs,
  305. .remount_fs = ext2_remount,
  306. .show_options = ext2_show_options,
  307. #ifdef CONFIG_QUOTA
  308. .quota_read = ext2_quota_read,
  309. .quota_write = ext2_quota_write,
  310. .get_dquots = ext2_get_dquots,
  311. #endif
  312. };
  313. static struct inode *ext2_nfs_get_inode(struct super_block *sb,
  314. u64 ino, u32 generation)
  315. {
  316. struct inode *inode;
  317. if (ino < EXT2_FIRST_INO(sb) && ino != EXT2_ROOT_INO)
  318. return ERR_PTR(-ESTALE);
  319. if (ino > le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count))
  320. return ERR_PTR(-ESTALE);
  321. /*
  322. * ext2_iget isn't quite right if the inode is currently unallocated!
  323. * However ext2_iget currently does appropriate checks to handle stale
  324. * inodes so everything is OK.
  325. */
  326. inode = ext2_iget(sb, ino);
  327. if (IS_ERR(inode))
  328. return ERR_CAST(inode);
  329. if (generation && inode->i_generation != generation) {
  330. /* we didn't find the right inode.. */
  331. iput(inode);
  332. return ERR_PTR(-ESTALE);
  333. }
  334. return inode;
  335. }
  336. static struct dentry *ext2_fh_to_dentry(struct super_block *sb, struct fid *fid,
  337. int fh_len, int fh_type)
  338. {
  339. return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
  340. ext2_nfs_get_inode);
  341. }
  342. static struct dentry *ext2_fh_to_parent(struct super_block *sb, struct fid *fid,
  343. int fh_len, int fh_type)
  344. {
  345. return generic_fh_to_parent(sb, fid, fh_len, fh_type,
  346. ext2_nfs_get_inode);
  347. }
  348. static const struct export_operations ext2_export_ops = {
  349. .fh_to_dentry = ext2_fh_to_dentry,
  350. .fh_to_parent = ext2_fh_to_parent,
  351. .get_parent = ext2_get_parent,
  352. };
  353. static unsigned long get_sb_block(void **data)
  354. {
  355. unsigned long sb_block;
  356. char *options = (char *) *data;
  357. if (!options || strncmp(options, "sb=", 3) != 0)
  358. return 1; /* Default location */
  359. options += 3;
  360. sb_block = simple_strtoul(options, &options, 0);
  361. if (*options && *options != ',') {
  362. printk("EXT2-fs: Invalid sb specification: %s\n",
  363. (char *) *data);
  364. return 1;
  365. }
  366. if (*options == ',')
  367. options++;
  368. *data = (void *) options;
  369. return sb_block;
  370. }
  371. enum {
  372. Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid,
  373. Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic,
  374. Opt_err_ro, Opt_nouid32, Opt_debug,
  375. Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
  376. Opt_acl, Opt_noacl, Opt_xip, Opt_dax, Opt_ignore, Opt_err, Opt_quota,
  377. Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
  378. };
  379. static const match_table_t tokens = {
  380. {Opt_bsd_df, "bsddf"},
  381. {Opt_minix_df, "minixdf"},
  382. {Opt_grpid, "grpid"},
  383. {Opt_grpid, "bsdgroups"},
  384. {Opt_nogrpid, "nogrpid"},
  385. {Opt_nogrpid, "sysvgroups"},
  386. {Opt_resgid, "resgid=%u"},
  387. {Opt_resuid, "resuid=%u"},
  388. {Opt_sb, "sb=%u"},
  389. {Opt_err_cont, "errors=continue"},
  390. {Opt_err_panic, "errors=panic"},
  391. {Opt_err_ro, "errors=remount-ro"},
  392. {Opt_nouid32, "nouid32"},
  393. {Opt_debug, "debug"},
  394. {Opt_oldalloc, "oldalloc"},
  395. {Opt_orlov, "orlov"},
  396. {Opt_nobh, "nobh"},
  397. {Opt_user_xattr, "user_xattr"},
  398. {Opt_nouser_xattr, "nouser_xattr"},
  399. {Opt_acl, "acl"},
  400. {Opt_noacl, "noacl"},
  401. {Opt_xip, "xip"},
  402. {Opt_dax, "dax"},
  403. {Opt_grpquota, "grpquota"},
  404. {Opt_ignore, "noquota"},
  405. {Opt_quota, "quota"},
  406. {Opt_usrquota, "usrquota"},
  407. {Opt_reservation, "reservation"},
  408. {Opt_noreservation, "noreservation"},
  409. {Opt_err, NULL}
  410. };
  411. static int parse_options(char *options, struct super_block *sb,
  412. struct ext2_mount_options *opts)
  413. {
  414. char *p;
  415. substring_t args[MAX_OPT_ARGS];
  416. int option;
  417. kuid_t uid;
  418. kgid_t gid;
  419. if (!options)
  420. return 1;
  421. while ((p = strsep (&options, ",")) != NULL) {
  422. int token;
  423. if (!*p)
  424. continue;
  425. token = match_token(p, tokens, args);
  426. switch (token) {
  427. case Opt_bsd_df:
  428. clear_opt (opts->s_mount_opt, MINIX_DF);
  429. break;
  430. case Opt_minix_df:
  431. set_opt (opts->s_mount_opt, MINIX_DF);
  432. break;
  433. case Opt_grpid:
  434. set_opt (opts->s_mount_opt, GRPID);
  435. break;
  436. case Opt_nogrpid:
  437. clear_opt (opts->s_mount_opt, GRPID);
  438. break;
  439. case Opt_resuid:
  440. if (match_int(&args[0], &option))
  441. return 0;
  442. uid = make_kuid(current_user_ns(), option);
  443. if (!uid_valid(uid)) {
  444. ext2_msg(sb, KERN_ERR, "Invalid uid value %d", option);
  445. return 0;
  446. }
  447. opts->s_resuid = uid;
  448. break;
  449. case Opt_resgid:
  450. if (match_int(&args[0], &option))
  451. return 0;
  452. gid = make_kgid(current_user_ns(), option);
  453. if (!gid_valid(gid)) {
  454. ext2_msg(sb, KERN_ERR, "Invalid gid value %d", option);
  455. return 0;
  456. }
  457. opts->s_resgid = gid;
  458. break;
  459. case Opt_sb:
  460. /* handled by get_sb_block() instead of here */
  461. /* *sb_block = match_int(&args[0]); */
  462. break;
  463. case Opt_err_panic:
  464. clear_opt (opts->s_mount_opt, ERRORS_CONT);
  465. clear_opt (opts->s_mount_opt, ERRORS_RO);
  466. set_opt (opts->s_mount_opt, ERRORS_PANIC);
  467. break;
  468. case Opt_err_ro:
  469. clear_opt (opts->s_mount_opt, ERRORS_CONT);
  470. clear_opt (opts->s_mount_opt, ERRORS_PANIC);
  471. set_opt (opts->s_mount_opt, ERRORS_RO);
  472. break;
  473. case Opt_err_cont:
  474. clear_opt (opts->s_mount_opt, ERRORS_RO);
  475. clear_opt (opts->s_mount_opt, ERRORS_PANIC);
  476. set_opt (opts->s_mount_opt, ERRORS_CONT);
  477. break;
  478. case Opt_nouid32:
  479. set_opt (opts->s_mount_opt, NO_UID32);
  480. break;
  481. case Opt_debug:
  482. set_opt (opts->s_mount_opt, DEBUG);
  483. break;
  484. case Opt_oldalloc:
  485. set_opt (opts->s_mount_opt, OLDALLOC);
  486. break;
  487. case Opt_orlov:
  488. clear_opt (opts->s_mount_opt, OLDALLOC);
  489. break;
  490. case Opt_nobh:
  491. set_opt (opts->s_mount_opt, NOBH);
  492. break;
  493. #ifdef CONFIG_EXT2_FS_XATTR
  494. case Opt_user_xattr:
  495. set_opt (opts->s_mount_opt, XATTR_USER);
  496. break;
  497. case Opt_nouser_xattr:
  498. clear_opt (opts->s_mount_opt, XATTR_USER);
  499. break;
  500. #else
  501. case Opt_user_xattr:
  502. case Opt_nouser_xattr:
  503. ext2_msg(sb, KERN_INFO, "(no)user_xattr options"
  504. "not supported");
  505. break;
  506. #endif
  507. #ifdef CONFIG_EXT2_FS_POSIX_ACL
  508. case Opt_acl:
  509. set_opt(opts->s_mount_opt, POSIX_ACL);
  510. break;
  511. case Opt_noacl:
  512. clear_opt(opts->s_mount_opt, POSIX_ACL);
  513. break;
  514. #else
  515. case Opt_acl:
  516. case Opt_noacl:
  517. ext2_msg(sb, KERN_INFO,
  518. "(no)acl options not supported");
  519. break;
  520. #endif
  521. case Opt_xip:
  522. ext2_msg(sb, KERN_INFO, "use dax instead of xip");
  523. set_opt(opts->s_mount_opt, XIP);
  524. fallthrough;
  525. case Opt_dax:
  526. #ifdef CONFIG_FS_DAX
  527. ext2_msg(sb, KERN_WARNING,
  528. "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
  529. set_opt(opts->s_mount_opt, DAX);
  530. #else
  531. ext2_msg(sb, KERN_INFO, "dax option not supported");
  532. #endif
  533. break;
  534. #if defined(CONFIG_QUOTA)
  535. case Opt_quota:
  536. case Opt_usrquota:
  537. set_opt(opts->s_mount_opt, USRQUOTA);
  538. break;
  539. case Opt_grpquota:
  540. set_opt(opts->s_mount_opt, GRPQUOTA);
  541. break;
  542. #else
  543. case Opt_quota:
  544. case Opt_usrquota:
  545. case Opt_grpquota:
  546. ext2_msg(sb, KERN_INFO,
  547. "quota operations not supported");
  548. break;
  549. #endif
  550. case Opt_reservation:
  551. set_opt(opts->s_mount_opt, RESERVATION);
  552. ext2_msg(sb, KERN_INFO, "reservations ON");
  553. break;
  554. case Opt_noreservation:
  555. clear_opt(opts->s_mount_opt, RESERVATION);
  556. ext2_msg(sb, KERN_INFO, "reservations OFF");
  557. break;
  558. case Opt_ignore:
  559. break;
  560. default:
  561. return 0;
  562. }
  563. }
  564. return 1;
  565. }
  566. static int ext2_setup_super (struct super_block * sb,
  567. struct ext2_super_block * es,
  568. int read_only)
  569. {
  570. int res = 0;
  571. struct ext2_sb_info *sbi = EXT2_SB(sb);
  572. if (le32_to_cpu(es->s_rev_level) > EXT2_MAX_SUPP_REV) {
  573. ext2_msg(sb, KERN_ERR,
  574. "error: revision level too high, "
  575. "forcing read-only mode");
  576. res = SB_RDONLY;
  577. }
  578. if (read_only)
  579. return res;
  580. if (!(sbi->s_mount_state & EXT2_VALID_FS))
  581. ext2_msg(sb, KERN_WARNING,
  582. "warning: mounting unchecked fs, "
  583. "running e2fsck is recommended");
  584. else if ((sbi->s_mount_state & EXT2_ERROR_FS))
  585. ext2_msg(sb, KERN_WARNING,
  586. "warning: mounting fs with errors, "
  587. "running e2fsck is recommended");
  588. else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 &&
  589. le16_to_cpu(es->s_mnt_count) >=
  590. (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count))
  591. ext2_msg(sb, KERN_WARNING,
  592. "warning: maximal mount count reached, "
  593. "running e2fsck is recommended");
  594. else if (le32_to_cpu(es->s_checkinterval) &&
  595. (le32_to_cpu(es->s_lastcheck) +
  596. le32_to_cpu(es->s_checkinterval) <=
  597. ktime_get_real_seconds()))
  598. ext2_msg(sb, KERN_WARNING,
  599. "warning: checktime reached, "
  600. "running e2fsck is recommended");
  601. if (!le16_to_cpu(es->s_max_mnt_count))
  602. es->s_max_mnt_count = cpu_to_le16(EXT2_DFL_MAX_MNT_COUNT);
  603. le16_add_cpu(&es->s_mnt_count, 1);
  604. if (test_opt (sb, DEBUG))
  605. ext2_msg(sb, KERN_INFO, "%s, %s, bs=%lu, fs=%lu, gc=%lu, "
  606. "bpg=%lu, ipg=%lu, mo=%04lx]",
  607. EXT2FS_VERSION, EXT2FS_DATE, sb->s_blocksize,
  608. sbi->s_frag_size,
  609. sbi->s_groups_count,
  610. EXT2_BLOCKS_PER_GROUP(sb),
  611. EXT2_INODES_PER_GROUP(sb),
  612. sbi->s_mount_opt);
  613. return res;
  614. }
  615. static int ext2_check_descriptors(struct super_block *sb)
  616. {
  617. int i;
  618. struct ext2_sb_info *sbi = EXT2_SB(sb);
  619. ext2_debug ("Checking group descriptors");
  620. for (i = 0; i < sbi->s_groups_count; i++) {
  621. struct ext2_group_desc *gdp = ext2_get_group_desc(sb, i, NULL);
  622. ext2_fsblk_t first_block = ext2_group_first_block_no(sb, i);
  623. ext2_fsblk_t last_block = ext2_group_last_block_no(sb, i);
  624. if (le32_to_cpu(gdp->bg_block_bitmap) < first_block ||
  625. le32_to_cpu(gdp->bg_block_bitmap) > last_block)
  626. {
  627. ext2_error (sb, "ext2_check_descriptors",
  628. "Block bitmap for group %d"
  629. " not in group (block %lu)!",
  630. i, (unsigned long) le32_to_cpu(gdp->bg_block_bitmap));
  631. return 0;
  632. }
  633. if (le32_to_cpu(gdp->bg_inode_bitmap) < first_block ||
  634. le32_to_cpu(gdp->bg_inode_bitmap) > last_block)
  635. {
  636. ext2_error (sb, "ext2_check_descriptors",
  637. "Inode bitmap for group %d"
  638. " not in group (block %lu)!",
  639. i, (unsigned long) le32_to_cpu(gdp->bg_inode_bitmap));
  640. return 0;
  641. }
  642. if (le32_to_cpu(gdp->bg_inode_table) < first_block ||
  643. le32_to_cpu(gdp->bg_inode_table) + sbi->s_itb_per_group - 1 >
  644. last_block)
  645. {
  646. ext2_error (sb, "ext2_check_descriptors",
  647. "Inode table for group %d"
  648. " not in group (block %lu)!",
  649. i, (unsigned long) le32_to_cpu(gdp->bg_inode_table));
  650. return 0;
  651. }
  652. }
  653. return 1;
  654. }
  655. /*
  656. * Maximal file size. There is a direct, and {,double-,triple-}indirect
  657. * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks.
  658. * We need to be 1 filesystem block less than the 2^32 sector limit.
  659. */
  660. static loff_t ext2_max_size(int bits)
  661. {
  662. loff_t res = EXT2_NDIR_BLOCKS;
  663. int meta_blocks;
  664. unsigned int upper_limit;
  665. unsigned int ppb = 1 << (bits-2);
  666. /* This is calculated to be the largest file size for a
  667. * dense, file such that the total number of
  668. * sectors in the file, including data and all indirect blocks,
  669. * does not exceed 2^32 -1
  670. * __u32 i_blocks representing the total number of
  671. * 512 bytes blocks of the file
  672. */
  673. upper_limit = (1LL << 32) - 1;
  674. /* total blocks in file system block size */
  675. upper_limit >>= (bits - 9);
  676. /* Compute how many blocks we can address by block tree */
  677. res += 1LL << (bits-2);
  678. res += 1LL << (2*(bits-2));
  679. res += 1LL << (3*(bits-2));
  680. /* Compute how many metadata blocks are needed */
  681. meta_blocks = 1;
  682. meta_blocks += 1 + ppb;
  683. meta_blocks += 1 + ppb + ppb * ppb;
  684. /* Does block tree limit file size? */
  685. if (res + meta_blocks <= upper_limit)
  686. goto check_lfs;
  687. res = upper_limit;
  688. /* How many metadata blocks are needed for addressing upper_limit? */
  689. upper_limit -= EXT2_NDIR_BLOCKS;
  690. /* indirect blocks */
  691. meta_blocks = 1;
  692. upper_limit -= ppb;
  693. /* double indirect blocks */
  694. if (upper_limit < ppb * ppb) {
  695. meta_blocks += 1 + DIV_ROUND_UP(upper_limit, ppb);
  696. res -= meta_blocks;
  697. goto check_lfs;
  698. }
  699. meta_blocks += 1 + ppb;
  700. upper_limit -= ppb * ppb;
  701. /* tripple indirect blocks for the rest */
  702. meta_blocks += 1 + DIV_ROUND_UP(upper_limit, ppb) +
  703. DIV_ROUND_UP(upper_limit, ppb*ppb);
  704. res -= meta_blocks;
  705. check_lfs:
  706. res <<= bits;
  707. if (res > MAX_LFS_FILESIZE)
  708. res = MAX_LFS_FILESIZE;
  709. return res;
  710. }
  711. static unsigned long descriptor_loc(struct super_block *sb,
  712. unsigned long logic_sb_block,
  713. int nr)
  714. {
  715. struct ext2_sb_info *sbi = EXT2_SB(sb);
  716. unsigned long bg, first_meta_bg;
  717. first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg);
  718. if (!EXT2_HAS_INCOMPAT_FEATURE(sb, EXT2_FEATURE_INCOMPAT_META_BG) ||
  719. nr < first_meta_bg)
  720. return (logic_sb_block + nr + 1);
  721. bg = sbi->s_desc_per_block * nr;
  722. return ext2_group_first_block_no(sb, bg) + ext2_bg_has_super(sb, bg);
  723. }
  724. static int ext2_fill_super(struct super_block *sb, void *data, int silent)
  725. {
  726. struct dax_device *dax_dev = fs_dax_get_by_bdev(sb->s_bdev);
  727. struct buffer_head * bh;
  728. struct ext2_sb_info * sbi;
  729. struct ext2_super_block * es;
  730. struct inode *root;
  731. unsigned long block;
  732. unsigned long sb_block = get_sb_block(&data);
  733. unsigned long logic_sb_block;
  734. unsigned long offset = 0;
  735. unsigned long def_mount_opts;
  736. long ret = -ENOMEM;
  737. int blocksize = BLOCK_SIZE;
  738. int db_count;
  739. int i, j;
  740. __le32 features;
  741. int err;
  742. struct ext2_mount_options opts;
  743. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  744. if (!sbi)
  745. goto failed;
  746. sbi->s_blockgroup_lock =
  747. kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
  748. if (!sbi->s_blockgroup_lock) {
  749. kfree(sbi);
  750. goto failed;
  751. }
  752. sb->s_fs_info = sbi;
  753. sbi->s_sb_block = sb_block;
  754. sbi->s_daxdev = dax_dev;
  755. spin_lock_init(&sbi->s_lock);
  756. ret = -EINVAL;
  757. /*
  758. * See what the current blocksize for the device is, and
  759. * use that as the blocksize. Otherwise (or if the blocksize
  760. * is smaller than the default) use the default.
  761. * This is important for devices that have a hardware
  762. * sectorsize that is larger than the default.
  763. */
  764. blocksize = sb_min_blocksize(sb, BLOCK_SIZE);
  765. if (!blocksize) {
  766. ext2_msg(sb, KERN_ERR, "error: unable to set blocksize");
  767. goto failed_sbi;
  768. }
  769. /*
  770. * If the superblock doesn't start on a hardware sector boundary,
  771. * calculate the offset.
  772. */
  773. if (blocksize != BLOCK_SIZE) {
  774. logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize;
  775. offset = (sb_block*BLOCK_SIZE) % blocksize;
  776. } else {
  777. logic_sb_block = sb_block;
  778. }
  779. if (!(bh = sb_bread(sb, logic_sb_block))) {
  780. ext2_msg(sb, KERN_ERR, "error: unable to read superblock");
  781. goto failed_sbi;
  782. }
  783. /*
  784. * Note: s_es must be initialized as soon as possible because
  785. * some ext2 macro-instructions depend on its value
  786. */
  787. es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
  788. sbi->s_es = es;
  789. sb->s_magic = le16_to_cpu(es->s_magic);
  790. if (sb->s_magic != EXT2_SUPER_MAGIC)
  791. goto cantfind_ext2;
  792. opts.s_mount_opt = 0;
  793. /* Set defaults before we parse the mount options */
  794. def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
  795. if (def_mount_opts & EXT2_DEFM_DEBUG)
  796. set_opt(opts.s_mount_opt, DEBUG);
  797. if (def_mount_opts & EXT2_DEFM_BSDGROUPS)
  798. set_opt(opts.s_mount_opt, GRPID);
  799. if (def_mount_opts & EXT2_DEFM_UID16)
  800. set_opt(opts.s_mount_opt, NO_UID32);
  801. #ifdef CONFIG_EXT2_FS_XATTR
  802. if (def_mount_opts & EXT2_DEFM_XATTR_USER)
  803. set_opt(opts.s_mount_opt, XATTR_USER);
  804. #endif
  805. #ifdef CONFIG_EXT2_FS_POSIX_ACL
  806. if (def_mount_opts & EXT2_DEFM_ACL)
  807. set_opt(opts.s_mount_opt, POSIX_ACL);
  808. #endif
  809. if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_PANIC)
  810. set_opt(opts.s_mount_opt, ERRORS_PANIC);
  811. else if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_CONTINUE)
  812. set_opt(opts.s_mount_opt, ERRORS_CONT);
  813. else
  814. set_opt(opts.s_mount_opt, ERRORS_RO);
  815. opts.s_resuid = make_kuid(&init_user_ns, le16_to_cpu(es->s_def_resuid));
  816. opts.s_resgid = make_kgid(&init_user_ns, le16_to_cpu(es->s_def_resgid));
  817. set_opt(opts.s_mount_opt, RESERVATION);
  818. if (!parse_options((char *) data, sb, &opts))
  819. goto failed_mount;
  820. sbi->s_mount_opt = opts.s_mount_opt;
  821. sbi->s_resuid = opts.s_resuid;
  822. sbi->s_resgid = opts.s_resgid;
  823. sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
  824. (test_opt(sb, POSIX_ACL) ? SB_POSIXACL : 0);
  825. sb->s_iflags |= SB_I_CGROUPWB;
  826. if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV &&
  827. (EXT2_HAS_COMPAT_FEATURE(sb, ~0U) ||
  828. EXT2_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
  829. EXT2_HAS_INCOMPAT_FEATURE(sb, ~0U)))
  830. ext2_msg(sb, KERN_WARNING,
  831. "warning: feature flags set on rev 0 fs, "
  832. "running e2fsck is recommended");
  833. /*
  834. * Check feature flags regardless of the revision level, since we
  835. * previously didn't change the revision level when setting the flags,
  836. * so there is a chance incompat flags are set on a rev 0 filesystem.
  837. */
  838. features = EXT2_HAS_INCOMPAT_FEATURE(sb, ~EXT2_FEATURE_INCOMPAT_SUPP);
  839. if (features) {
  840. ext2_msg(sb, KERN_ERR, "error: couldn't mount because of "
  841. "unsupported optional features (%x)",
  842. le32_to_cpu(features));
  843. goto failed_mount;
  844. }
  845. if (!sb_rdonly(sb) && (features = EXT2_HAS_RO_COMPAT_FEATURE(sb, ~EXT2_FEATURE_RO_COMPAT_SUPP))){
  846. ext2_msg(sb, KERN_ERR, "error: couldn't mount RDWR because of "
  847. "unsupported optional features (%x)",
  848. le32_to_cpu(features));
  849. goto failed_mount;
  850. }
  851. blocksize = BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size);
  852. if (test_opt(sb, DAX)) {
  853. if (!bdev_dax_supported(sb->s_bdev, blocksize)) {
  854. ext2_msg(sb, KERN_ERR,
  855. "DAX unsupported by block device. Turning off DAX.");
  856. clear_opt(sbi->s_mount_opt, DAX);
  857. }
  858. }
  859. /* If the blocksize doesn't match, re-read the thing.. */
  860. if (sb->s_blocksize != blocksize) {
  861. brelse(bh);
  862. if (!sb_set_blocksize(sb, blocksize)) {
  863. ext2_msg(sb, KERN_ERR,
  864. "error: bad blocksize %d", blocksize);
  865. goto failed_sbi;
  866. }
  867. logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize;
  868. offset = (sb_block*BLOCK_SIZE) % blocksize;
  869. bh = sb_bread(sb, logic_sb_block);
  870. if(!bh) {
  871. ext2_msg(sb, KERN_ERR, "error: couldn't read"
  872. "superblock on 2nd try");
  873. goto failed_sbi;
  874. }
  875. es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
  876. sbi->s_es = es;
  877. if (es->s_magic != cpu_to_le16(EXT2_SUPER_MAGIC)) {
  878. ext2_msg(sb, KERN_ERR, "error: magic mismatch");
  879. goto failed_mount;
  880. }
  881. }
  882. sb->s_maxbytes = ext2_max_size(sb->s_blocksize_bits);
  883. sb->s_max_links = EXT2_LINK_MAX;
  884. sb->s_time_min = S32_MIN;
  885. sb->s_time_max = S32_MAX;
  886. if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV) {
  887. sbi->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE;
  888. sbi->s_first_ino = EXT2_GOOD_OLD_FIRST_INO;
  889. } else {
  890. sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
  891. sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
  892. if ((sbi->s_inode_size < EXT2_GOOD_OLD_INODE_SIZE) ||
  893. !is_power_of_2(sbi->s_inode_size) ||
  894. (sbi->s_inode_size > blocksize)) {
  895. ext2_msg(sb, KERN_ERR,
  896. "error: unsupported inode size: %d",
  897. sbi->s_inode_size);
  898. goto failed_mount;
  899. }
  900. }
  901. sbi->s_frag_size = EXT2_MIN_FRAG_SIZE <<
  902. le32_to_cpu(es->s_log_frag_size);
  903. if (sbi->s_frag_size == 0)
  904. goto cantfind_ext2;
  905. sbi->s_frags_per_block = sb->s_blocksize / sbi->s_frag_size;
  906. sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
  907. sbi->s_frags_per_group = le32_to_cpu(es->s_frags_per_group);
  908. sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
  909. sbi->s_inodes_per_block = sb->s_blocksize / EXT2_INODE_SIZE(sb);
  910. if (sbi->s_inodes_per_block == 0 || sbi->s_inodes_per_group == 0)
  911. goto cantfind_ext2;
  912. sbi->s_itb_per_group = sbi->s_inodes_per_group /
  913. sbi->s_inodes_per_block;
  914. sbi->s_desc_per_block = sb->s_blocksize /
  915. sizeof (struct ext2_group_desc);
  916. sbi->s_sbh = bh;
  917. sbi->s_mount_state = le16_to_cpu(es->s_state);
  918. sbi->s_addr_per_block_bits =
  919. ilog2 (EXT2_ADDR_PER_BLOCK(sb));
  920. sbi->s_desc_per_block_bits =
  921. ilog2 (EXT2_DESC_PER_BLOCK(sb));
  922. if (sb->s_magic != EXT2_SUPER_MAGIC)
  923. goto cantfind_ext2;
  924. if (sb->s_blocksize != bh->b_size) {
  925. if (!silent)
  926. ext2_msg(sb, KERN_ERR, "error: unsupported blocksize");
  927. goto failed_mount;
  928. }
  929. if (sb->s_blocksize != sbi->s_frag_size) {
  930. ext2_msg(sb, KERN_ERR,
  931. "error: fragsize %lu != blocksize %lu"
  932. "(not supported yet)",
  933. sbi->s_frag_size, sb->s_blocksize);
  934. goto failed_mount;
  935. }
  936. if (sbi->s_blocks_per_group > sb->s_blocksize * 8) {
  937. ext2_msg(sb, KERN_ERR,
  938. "error: #blocks per group too big: %lu",
  939. sbi->s_blocks_per_group);
  940. goto failed_mount;
  941. }
  942. if (sbi->s_frags_per_group > sb->s_blocksize * 8) {
  943. ext2_msg(sb, KERN_ERR,
  944. "error: #fragments per group too big: %lu",
  945. sbi->s_frags_per_group);
  946. goto failed_mount;
  947. }
  948. if (sbi->s_inodes_per_group > sb->s_blocksize * 8) {
  949. ext2_msg(sb, KERN_ERR,
  950. "error: #inodes per group too big: %lu",
  951. sbi->s_inodes_per_group);
  952. goto failed_mount;
  953. }
  954. if (EXT2_BLOCKS_PER_GROUP(sb) == 0)
  955. goto cantfind_ext2;
  956. sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) -
  957. le32_to_cpu(es->s_first_data_block) - 1)
  958. / EXT2_BLOCKS_PER_GROUP(sb)) + 1;
  959. db_count = (sbi->s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
  960. EXT2_DESC_PER_BLOCK(sb);
  961. sbi->s_group_desc = kmalloc_array (db_count,
  962. sizeof(struct buffer_head *),
  963. GFP_KERNEL);
  964. if (sbi->s_group_desc == NULL) {
  965. ret = -ENOMEM;
  966. ext2_msg(sb, KERN_ERR, "error: not enough memory");
  967. goto failed_mount;
  968. }
  969. bgl_lock_init(sbi->s_blockgroup_lock);
  970. sbi->s_debts = kcalloc(sbi->s_groups_count, sizeof(*sbi->s_debts), GFP_KERNEL);
  971. if (!sbi->s_debts) {
  972. ret = -ENOMEM;
  973. ext2_msg(sb, KERN_ERR, "error: not enough memory");
  974. goto failed_mount_group_desc;
  975. }
  976. for (i = 0; i < db_count; i++) {
  977. block = descriptor_loc(sb, logic_sb_block, i);
  978. sbi->s_group_desc[i] = sb_bread(sb, block);
  979. if (!sbi->s_group_desc[i]) {
  980. for (j = 0; j < i; j++)
  981. brelse (sbi->s_group_desc[j]);
  982. ext2_msg(sb, KERN_ERR,
  983. "error: unable to read group descriptors");
  984. goto failed_mount_group_desc;
  985. }
  986. }
  987. if (!ext2_check_descriptors (sb)) {
  988. ext2_msg(sb, KERN_ERR, "group descriptors corrupted");
  989. goto failed_mount2;
  990. }
  991. sbi->s_gdb_count = db_count;
  992. get_random_bytes(&sbi->s_next_generation, sizeof(u32));
  993. spin_lock_init(&sbi->s_next_gen_lock);
  994. /* per fileystem reservation list head & lock */
  995. spin_lock_init(&sbi->s_rsv_window_lock);
  996. sbi->s_rsv_window_root = RB_ROOT;
  997. /*
  998. * Add a single, static dummy reservation to the start of the
  999. * reservation window list --- it gives us a placeholder for
  1000. * append-at-start-of-list which makes the allocation logic
  1001. * _much_ simpler.
  1002. */
  1003. sbi->s_rsv_window_head.rsv_start = EXT2_RESERVE_WINDOW_NOT_ALLOCATED;
  1004. sbi->s_rsv_window_head.rsv_end = EXT2_RESERVE_WINDOW_NOT_ALLOCATED;
  1005. sbi->s_rsv_window_head.rsv_alloc_hit = 0;
  1006. sbi->s_rsv_window_head.rsv_goal_size = 0;
  1007. ext2_rsv_window_add(sb, &sbi->s_rsv_window_head);
  1008. err = percpu_counter_init(&sbi->s_freeblocks_counter,
  1009. ext2_count_free_blocks(sb), GFP_KERNEL);
  1010. if (!err) {
  1011. err = percpu_counter_init(&sbi->s_freeinodes_counter,
  1012. ext2_count_free_inodes(sb), GFP_KERNEL);
  1013. }
  1014. if (!err) {
  1015. err = percpu_counter_init(&sbi->s_dirs_counter,
  1016. ext2_count_dirs(sb), GFP_KERNEL);
  1017. }
  1018. if (err) {
  1019. ret = err;
  1020. ext2_msg(sb, KERN_ERR, "error: insufficient memory");
  1021. goto failed_mount3;
  1022. }
  1023. #ifdef CONFIG_EXT2_FS_XATTR
  1024. sbi->s_ea_block_cache = ext2_xattr_create_cache();
  1025. if (!sbi->s_ea_block_cache) {
  1026. ret = -ENOMEM;
  1027. ext2_msg(sb, KERN_ERR, "Failed to create ea_block_cache");
  1028. goto failed_mount3;
  1029. }
  1030. #endif
  1031. /*
  1032. * set up enough so that it can read an inode
  1033. */
  1034. sb->s_op = &ext2_sops;
  1035. sb->s_export_op = &ext2_export_ops;
  1036. sb->s_xattr = ext2_xattr_handlers;
  1037. #ifdef CONFIG_QUOTA
  1038. sb->dq_op = &dquot_operations;
  1039. sb->s_qcop = &ext2_quotactl_ops;
  1040. sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
  1041. #endif
  1042. root = ext2_iget(sb, EXT2_ROOT_INO);
  1043. if (IS_ERR(root)) {
  1044. ret = PTR_ERR(root);
  1045. goto failed_mount3;
  1046. }
  1047. if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
  1048. iput(root);
  1049. ext2_msg(sb, KERN_ERR, "error: corrupt root inode, run e2fsck");
  1050. goto failed_mount3;
  1051. }
  1052. sb->s_root = d_make_root(root);
  1053. if (!sb->s_root) {
  1054. ext2_msg(sb, KERN_ERR, "error: get root inode failed");
  1055. ret = -ENOMEM;
  1056. goto failed_mount3;
  1057. }
  1058. if (EXT2_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL))
  1059. ext2_msg(sb, KERN_WARNING,
  1060. "warning: mounting ext3 filesystem as ext2");
  1061. if (ext2_setup_super (sb, es, sb_rdonly(sb)))
  1062. sb->s_flags |= SB_RDONLY;
  1063. ext2_write_super(sb);
  1064. return 0;
  1065. cantfind_ext2:
  1066. if (!silent)
  1067. ext2_msg(sb, KERN_ERR,
  1068. "error: can't find an ext2 filesystem on dev %s.",
  1069. sb->s_id);
  1070. goto failed_mount;
  1071. failed_mount3:
  1072. ext2_xattr_destroy_cache(sbi->s_ea_block_cache);
  1073. percpu_counter_destroy(&sbi->s_freeblocks_counter);
  1074. percpu_counter_destroy(&sbi->s_freeinodes_counter);
  1075. percpu_counter_destroy(&sbi->s_dirs_counter);
  1076. failed_mount2:
  1077. for (i = 0; i < db_count; i++)
  1078. brelse(sbi->s_group_desc[i]);
  1079. failed_mount_group_desc:
  1080. kfree(sbi->s_group_desc);
  1081. kfree(sbi->s_debts);
  1082. failed_mount:
  1083. brelse(bh);
  1084. failed_sbi:
  1085. sb->s_fs_info = NULL;
  1086. kfree(sbi->s_blockgroup_lock);
  1087. kfree(sbi);
  1088. failed:
  1089. fs_put_dax(dax_dev);
  1090. return ret;
  1091. }
  1092. static void ext2_clear_super_error(struct super_block *sb)
  1093. {
  1094. struct buffer_head *sbh = EXT2_SB(sb)->s_sbh;
  1095. if (buffer_write_io_error(sbh)) {
  1096. /*
  1097. * Oh, dear. A previous attempt to write the
  1098. * superblock failed. This could happen because the
  1099. * USB device was yanked out. Or it could happen to
  1100. * be a transient write error and maybe the block will
  1101. * be remapped. Nothing we can do but to retry the
  1102. * write and hope for the best.
  1103. */
  1104. ext2_msg(sb, KERN_ERR,
  1105. "previous I/O error to superblock detected");
  1106. clear_buffer_write_io_error(sbh);
  1107. set_buffer_uptodate(sbh);
  1108. }
  1109. }
  1110. void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es,
  1111. int wait)
  1112. {
  1113. ext2_clear_super_error(sb);
  1114. spin_lock(&EXT2_SB(sb)->s_lock);
  1115. es->s_free_blocks_count = cpu_to_le32(ext2_count_free_blocks(sb));
  1116. es->s_free_inodes_count = cpu_to_le32(ext2_count_free_inodes(sb));
  1117. es->s_wtime = cpu_to_le32(ktime_get_real_seconds());
  1118. /* unlock before we do IO */
  1119. spin_unlock(&EXT2_SB(sb)->s_lock);
  1120. mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
  1121. if (wait)
  1122. sync_dirty_buffer(EXT2_SB(sb)->s_sbh);
  1123. }
  1124. /*
  1125. * In the second extended file system, it is not necessary to
  1126. * write the super block since we use a mapping of the
  1127. * disk super block in a buffer.
  1128. *
  1129. * However, this function is still used to set the fs valid
  1130. * flags to 0. We need to set this flag to 0 since the fs
  1131. * may have been checked while mounted and e2fsck may have
  1132. * set s_state to EXT2_VALID_FS after some corrections.
  1133. */
  1134. static int ext2_sync_fs(struct super_block *sb, int wait)
  1135. {
  1136. struct ext2_sb_info *sbi = EXT2_SB(sb);
  1137. struct ext2_super_block *es = EXT2_SB(sb)->s_es;
  1138. /*
  1139. * Write quota structures to quota file, sync_blockdev() will write
  1140. * them to disk later
  1141. */
  1142. dquot_writeback_dquots(sb, -1);
  1143. spin_lock(&sbi->s_lock);
  1144. if (es->s_state & cpu_to_le16(EXT2_VALID_FS)) {
  1145. ext2_debug("setting valid to 0\n");
  1146. es->s_state &= cpu_to_le16(~EXT2_VALID_FS);
  1147. }
  1148. spin_unlock(&sbi->s_lock);
  1149. ext2_sync_super(sb, es, wait);
  1150. return 0;
  1151. }
  1152. static int ext2_freeze(struct super_block *sb)
  1153. {
  1154. struct ext2_sb_info *sbi = EXT2_SB(sb);
  1155. /*
  1156. * Open but unlinked files present? Keep EXT2_VALID_FS flag cleared
  1157. * because we have unattached inodes and thus filesystem is not fully
  1158. * consistent.
  1159. */
  1160. if (atomic_long_read(&sb->s_remove_count)) {
  1161. ext2_sync_fs(sb, 1);
  1162. return 0;
  1163. }
  1164. /* Set EXT2_FS_VALID flag */
  1165. spin_lock(&sbi->s_lock);
  1166. sbi->s_es->s_state = cpu_to_le16(sbi->s_mount_state);
  1167. spin_unlock(&sbi->s_lock);
  1168. ext2_sync_super(sb, sbi->s_es, 1);
  1169. return 0;
  1170. }
  1171. static int ext2_unfreeze(struct super_block *sb)
  1172. {
  1173. /* Just write sb to clear EXT2_VALID_FS flag */
  1174. ext2_write_super(sb);
  1175. return 0;
  1176. }
  1177. static void ext2_write_super(struct super_block *sb)
  1178. {
  1179. if (!sb_rdonly(sb))
  1180. ext2_sync_fs(sb, 1);
  1181. }
  1182. static int ext2_remount (struct super_block * sb, int * flags, char * data)
  1183. {
  1184. struct ext2_sb_info * sbi = EXT2_SB(sb);
  1185. struct ext2_super_block * es;
  1186. struct ext2_mount_options new_opts;
  1187. int err;
  1188. sync_filesystem(sb);
  1189. spin_lock(&sbi->s_lock);
  1190. new_opts.s_mount_opt = sbi->s_mount_opt;
  1191. new_opts.s_resuid = sbi->s_resuid;
  1192. new_opts.s_resgid = sbi->s_resgid;
  1193. spin_unlock(&sbi->s_lock);
  1194. if (!parse_options(data, sb, &new_opts))
  1195. return -EINVAL;
  1196. spin_lock(&sbi->s_lock);
  1197. es = sbi->s_es;
  1198. if ((sbi->s_mount_opt ^ new_opts.s_mount_opt) & EXT2_MOUNT_DAX) {
  1199. ext2_msg(sb, KERN_WARNING, "warning: refusing change of "
  1200. "dax flag with busy inodes while remounting");
  1201. new_opts.s_mount_opt ^= EXT2_MOUNT_DAX;
  1202. }
  1203. if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
  1204. goto out_set;
  1205. if (*flags & SB_RDONLY) {
  1206. if (le16_to_cpu(es->s_state) & EXT2_VALID_FS ||
  1207. !(sbi->s_mount_state & EXT2_VALID_FS))
  1208. goto out_set;
  1209. /*
  1210. * OK, we are remounting a valid rw partition rdonly, so set
  1211. * the rdonly flag and then mark the partition as valid again.
  1212. */
  1213. es->s_state = cpu_to_le16(sbi->s_mount_state);
  1214. es->s_mtime = cpu_to_le32(ktime_get_real_seconds());
  1215. spin_unlock(&sbi->s_lock);
  1216. err = dquot_suspend(sb, -1);
  1217. if (err < 0)
  1218. return err;
  1219. ext2_sync_super(sb, es, 1);
  1220. } else {
  1221. __le32 ret = EXT2_HAS_RO_COMPAT_FEATURE(sb,
  1222. ~EXT2_FEATURE_RO_COMPAT_SUPP);
  1223. if (ret) {
  1224. spin_unlock(&sbi->s_lock);
  1225. ext2_msg(sb, KERN_WARNING,
  1226. "warning: couldn't remount RDWR because of "
  1227. "unsupported optional features (%x).",
  1228. le32_to_cpu(ret));
  1229. return -EROFS;
  1230. }
  1231. /*
  1232. * Mounting a RDONLY partition read-write, so reread and
  1233. * store the current valid flag. (It may have been changed
  1234. * by e2fsck since we originally mounted the partition.)
  1235. */
  1236. sbi->s_mount_state = le16_to_cpu(es->s_state);
  1237. if (!ext2_setup_super (sb, es, 0))
  1238. sb->s_flags &= ~SB_RDONLY;
  1239. spin_unlock(&sbi->s_lock);
  1240. ext2_write_super(sb);
  1241. dquot_resume(sb, -1);
  1242. }
  1243. spin_lock(&sbi->s_lock);
  1244. out_set:
  1245. sbi->s_mount_opt = new_opts.s_mount_opt;
  1246. sbi->s_resuid = new_opts.s_resuid;
  1247. sbi->s_resgid = new_opts.s_resgid;
  1248. sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
  1249. (test_opt(sb, POSIX_ACL) ? SB_POSIXACL : 0);
  1250. spin_unlock(&sbi->s_lock);
  1251. return 0;
  1252. }
  1253. static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf)
  1254. {
  1255. struct super_block *sb = dentry->d_sb;
  1256. struct ext2_sb_info *sbi = EXT2_SB(sb);
  1257. struct ext2_super_block *es = sbi->s_es;
  1258. u64 fsid;
  1259. spin_lock(&sbi->s_lock);
  1260. if (test_opt (sb, MINIX_DF))
  1261. sbi->s_overhead_last = 0;
  1262. else if (sbi->s_blocks_last != le32_to_cpu(es->s_blocks_count)) {
  1263. unsigned long i, overhead = 0;
  1264. smp_rmb();
  1265. /*
  1266. * Compute the overhead (FS structures). This is constant
  1267. * for a given filesystem unless the number of block groups
  1268. * changes so we cache the previous value until it does.
  1269. */
  1270. /*
  1271. * All of the blocks before first_data_block are
  1272. * overhead
  1273. */
  1274. overhead = le32_to_cpu(es->s_first_data_block);
  1275. /*
  1276. * Add the overhead attributed to the superblock and
  1277. * block group descriptors. If the sparse superblocks
  1278. * feature is turned on, then not all groups have this.
  1279. */
  1280. for (i = 0; i < sbi->s_groups_count; i++)
  1281. overhead += ext2_bg_has_super(sb, i) +
  1282. ext2_bg_num_gdb(sb, i);
  1283. /*
  1284. * Every block group has an inode bitmap, a block
  1285. * bitmap, and an inode table.
  1286. */
  1287. overhead += (sbi->s_groups_count *
  1288. (2 + sbi->s_itb_per_group));
  1289. sbi->s_overhead_last = overhead;
  1290. smp_wmb();
  1291. sbi->s_blocks_last = le32_to_cpu(es->s_blocks_count);
  1292. }
  1293. buf->f_type = EXT2_SUPER_MAGIC;
  1294. buf->f_bsize = sb->s_blocksize;
  1295. buf->f_blocks = le32_to_cpu(es->s_blocks_count) - sbi->s_overhead_last;
  1296. buf->f_bfree = ext2_count_free_blocks(sb);
  1297. es->s_free_blocks_count = cpu_to_le32(buf->f_bfree);
  1298. buf->f_bavail = buf->f_bfree - le32_to_cpu(es->s_r_blocks_count);
  1299. if (buf->f_bfree < le32_to_cpu(es->s_r_blocks_count))
  1300. buf->f_bavail = 0;
  1301. buf->f_files = le32_to_cpu(es->s_inodes_count);
  1302. buf->f_ffree = ext2_count_free_inodes(sb);
  1303. es->s_free_inodes_count = cpu_to_le32(buf->f_ffree);
  1304. buf->f_namelen = EXT2_NAME_LEN;
  1305. fsid = le64_to_cpup((void *)es->s_uuid) ^
  1306. le64_to_cpup((void *)es->s_uuid + sizeof(u64));
  1307. buf->f_fsid = u64_to_fsid(fsid);
  1308. spin_unlock(&sbi->s_lock);
  1309. return 0;
  1310. }
  1311. static struct dentry *ext2_mount(struct file_system_type *fs_type,
  1312. int flags, const char *dev_name, void *data)
  1313. {
  1314. return mount_bdev(fs_type, flags, dev_name, data, ext2_fill_super);
  1315. }
  1316. #ifdef CONFIG_QUOTA
  1317. /* Read data from quotafile - avoid pagecache and such because we cannot afford
  1318. * acquiring the locks... As quota files are never truncated and quota code
  1319. * itself serializes the operations (and no one else should touch the files)
  1320. * we don't have to be afraid of races */
  1321. static ssize_t ext2_quota_read(struct super_block *sb, int type, char *data,
  1322. size_t len, loff_t off)
  1323. {
  1324. struct inode *inode = sb_dqopt(sb)->files[type];
  1325. sector_t blk = off >> EXT2_BLOCK_SIZE_BITS(sb);
  1326. int err = 0;
  1327. int offset = off & (sb->s_blocksize - 1);
  1328. int tocopy;
  1329. size_t toread;
  1330. struct buffer_head tmp_bh;
  1331. struct buffer_head *bh;
  1332. loff_t i_size = i_size_read(inode);
  1333. if (off > i_size)
  1334. return 0;
  1335. if (off+len > i_size)
  1336. len = i_size-off;
  1337. toread = len;
  1338. while (toread > 0) {
  1339. tocopy = sb->s_blocksize - offset < toread ?
  1340. sb->s_blocksize - offset : toread;
  1341. tmp_bh.b_state = 0;
  1342. tmp_bh.b_size = sb->s_blocksize;
  1343. err = ext2_get_block(inode, blk, &tmp_bh, 0);
  1344. if (err < 0)
  1345. return err;
  1346. if (!buffer_mapped(&tmp_bh)) /* A hole? */
  1347. memset(data, 0, tocopy);
  1348. else {
  1349. bh = sb_bread(sb, tmp_bh.b_blocknr);
  1350. if (!bh)
  1351. return -EIO;
  1352. memcpy(data, bh->b_data+offset, tocopy);
  1353. brelse(bh);
  1354. }
  1355. offset = 0;
  1356. toread -= tocopy;
  1357. data += tocopy;
  1358. blk++;
  1359. }
  1360. return len;
  1361. }
  1362. /* Write to quotafile */
  1363. static ssize_t ext2_quota_write(struct super_block *sb, int type,
  1364. const char *data, size_t len, loff_t off)
  1365. {
  1366. struct inode *inode = sb_dqopt(sb)->files[type];
  1367. sector_t blk = off >> EXT2_BLOCK_SIZE_BITS(sb);
  1368. int err = 0;
  1369. int offset = off & (sb->s_blocksize - 1);
  1370. int tocopy;
  1371. size_t towrite = len;
  1372. struct buffer_head tmp_bh;
  1373. struct buffer_head *bh;
  1374. while (towrite > 0) {
  1375. tocopy = sb->s_blocksize - offset < towrite ?
  1376. sb->s_blocksize - offset : towrite;
  1377. tmp_bh.b_state = 0;
  1378. tmp_bh.b_size = sb->s_blocksize;
  1379. err = ext2_get_block(inode, blk, &tmp_bh, 1);
  1380. if (err < 0)
  1381. goto out;
  1382. if (offset || tocopy != EXT2_BLOCK_SIZE(sb))
  1383. bh = sb_bread(sb, tmp_bh.b_blocknr);
  1384. else
  1385. bh = sb_getblk(sb, tmp_bh.b_blocknr);
  1386. if (unlikely(!bh)) {
  1387. err = -EIO;
  1388. goto out;
  1389. }
  1390. lock_buffer(bh);
  1391. memcpy(bh->b_data+offset, data, tocopy);
  1392. flush_dcache_page(bh->b_page);
  1393. set_buffer_uptodate(bh);
  1394. mark_buffer_dirty(bh);
  1395. unlock_buffer(bh);
  1396. brelse(bh);
  1397. offset = 0;
  1398. towrite -= tocopy;
  1399. data += tocopy;
  1400. blk++;
  1401. }
  1402. out:
  1403. if (len == towrite)
  1404. return err;
  1405. if (inode->i_size < off+len-towrite)
  1406. i_size_write(inode, off+len-towrite);
  1407. inode_inc_iversion(inode);
  1408. inode->i_mtime = inode->i_ctime = current_time(inode);
  1409. mark_inode_dirty(inode);
  1410. return len - towrite;
  1411. }
  1412. static int ext2_quota_on(struct super_block *sb, int type, int format_id,
  1413. const struct path *path)
  1414. {
  1415. int err;
  1416. struct inode *inode;
  1417. err = dquot_quota_on(sb, type, format_id, path);
  1418. if (err)
  1419. return err;
  1420. inode = d_inode(path->dentry);
  1421. inode_lock(inode);
  1422. EXT2_I(inode)->i_flags |= EXT2_NOATIME_FL | EXT2_IMMUTABLE_FL;
  1423. inode_set_flags(inode, S_NOATIME | S_IMMUTABLE,
  1424. S_NOATIME | S_IMMUTABLE);
  1425. inode_unlock(inode);
  1426. mark_inode_dirty(inode);
  1427. return 0;
  1428. }
  1429. static int ext2_quota_off(struct super_block *sb, int type)
  1430. {
  1431. struct inode *inode = sb_dqopt(sb)->files[type];
  1432. int err;
  1433. if (!inode || !igrab(inode))
  1434. goto out;
  1435. err = dquot_quota_off(sb, type);
  1436. if (err)
  1437. goto out_put;
  1438. inode_lock(inode);
  1439. EXT2_I(inode)->i_flags &= ~(EXT2_NOATIME_FL | EXT2_IMMUTABLE_FL);
  1440. inode_set_flags(inode, 0, S_NOATIME | S_IMMUTABLE);
  1441. inode_unlock(inode);
  1442. mark_inode_dirty(inode);
  1443. out_put:
  1444. iput(inode);
  1445. return err;
  1446. out:
  1447. return dquot_quota_off(sb, type);
  1448. }
  1449. #endif
  1450. static struct file_system_type ext2_fs_type = {
  1451. .owner = THIS_MODULE,
  1452. .name = "ext2",
  1453. .mount = ext2_mount,
  1454. .kill_sb = kill_block_super,
  1455. .fs_flags = FS_REQUIRES_DEV,
  1456. };
  1457. MODULE_ALIAS_FS("ext2");
  1458. static int __init init_ext2_fs(void)
  1459. {
  1460. int err;
  1461. err = init_inodecache();
  1462. if (err)
  1463. return err;
  1464. err = register_filesystem(&ext2_fs_type);
  1465. if (err)
  1466. goto out;
  1467. return 0;
  1468. out:
  1469. destroy_inodecache();
  1470. return err;
  1471. }
  1472. static void __exit exit_ext2_fs(void)
  1473. {
  1474. unregister_filesystem(&ext2_fs_type);
  1475. destroy_inodecache();
  1476. }
  1477. MODULE_AUTHOR("Remy Card and others");
  1478. MODULE_DESCRIPTION("Second Extended Filesystem");
  1479. MODULE_LICENSE("GPL");
  1480. MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
  1481. module_init(init_ext2_fs)
  1482. module_exit(exit_ext2_fs)