super.c 45 KB

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