super.c 44 KB

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