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 defined(CONFIG_QUOTA)
  270. if (sbi->s_mount_opt & EXT2_MOUNT_USRQUOTA)
  271. seq_puts(seq, ",usrquota");
  272. if (sbi->s_mount_opt & EXT2_MOUNT_GRPQUOTA)
  273. seq_puts(seq, ",grpquota");
  274. #endif
  275. #ifdef CONFIG_FS_DAX
  276. if (sbi->s_mount_opt & EXT2_MOUNT_XIP)
  277. seq_puts(seq, ",xip");
  278. if (sbi->s_mount_opt & EXT2_MOUNT_DAX)
  279. seq_puts(seq, ",dax");
  280. #endif
  281. if (!test_opt(sb, RESERVATION))
  282. seq_puts(seq, ",noreservation");
  283. spin_unlock(&sbi->s_lock);
  284. return 0;
  285. }
  286. #ifdef CONFIG_QUOTA
  287. static ssize_t ext2_quota_read(struct super_block *sb, int type, char *data, size_t len, loff_t off);
  288. static ssize_t ext2_quota_write(struct super_block *sb, int type, const char *data, size_t len, loff_t off);
  289. static int ext2_quota_on(struct super_block *sb, int type, int format_id,
  290. const struct path *path);
  291. static struct dquot **ext2_get_dquots(struct inode *inode)
  292. {
  293. return EXT2_I(inode)->i_dquot;
  294. }
  295. static const struct quotactl_ops ext2_quotactl_ops = {
  296. .quota_on = ext2_quota_on,
  297. .quota_off = ext2_quota_off,
  298. .quota_sync = dquot_quota_sync,
  299. .get_state = dquot_get_state,
  300. .set_info = dquot_set_dqinfo,
  301. .get_dqblk = dquot_get_dqblk,
  302. .set_dqblk = dquot_set_dqblk,
  303. .get_nextdqblk = dquot_get_next_dqblk,
  304. };
  305. #endif
  306. static const struct super_operations ext2_sops = {
  307. .alloc_inode = ext2_alloc_inode,
  308. .destroy_inode = ext2_destroy_inode,
  309. .write_inode = ext2_write_inode,
  310. .evict_inode = ext2_evict_inode,
  311. .put_super = ext2_put_super,
  312. .sync_fs = ext2_sync_fs,
  313. .freeze_fs = ext2_freeze,
  314. .unfreeze_fs = ext2_unfreeze,
  315. .statfs = ext2_statfs,
  316. .remount_fs = ext2_remount,
  317. .show_options = ext2_show_options,
  318. #ifdef CONFIG_QUOTA
  319. .quota_read = ext2_quota_read,
  320. .quota_write = ext2_quota_write,
  321. .get_dquots = ext2_get_dquots,
  322. #endif
  323. };
  324. static struct inode *ext2_nfs_get_inode(struct super_block *sb,
  325. u64 ino, u32 generation)
  326. {
  327. struct inode *inode;
  328. if (ino < EXT2_FIRST_INO(sb) && ino != EXT2_ROOT_INO)
  329. return ERR_PTR(-ESTALE);
  330. if (ino > le32_to_cpu(EXT2_SB(sb)->s_es->s_inodes_count))
  331. return ERR_PTR(-ESTALE);
  332. /*
  333. * ext2_iget isn't quite right if the inode is currently unallocated!
  334. * However ext2_iget currently does appropriate checks to handle stale
  335. * inodes so everything is OK.
  336. */
  337. inode = ext2_iget(sb, ino);
  338. if (IS_ERR(inode))
  339. return ERR_CAST(inode);
  340. if (generation && inode->i_generation != generation) {
  341. /* we didn't find the right inode.. */
  342. iput(inode);
  343. return ERR_PTR(-ESTALE);
  344. }
  345. return inode;
  346. }
  347. static struct dentry *ext2_fh_to_dentry(struct super_block *sb, struct fid *fid,
  348. int fh_len, int fh_type)
  349. {
  350. return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
  351. ext2_nfs_get_inode);
  352. }
  353. static struct dentry *ext2_fh_to_parent(struct super_block *sb, struct fid *fid,
  354. int fh_len, int fh_type)
  355. {
  356. return generic_fh_to_parent(sb, fid, fh_len, fh_type,
  357. ext2_nfs_get_inode);
  358. }
  359. static const struct export_operations ext2_export_ops = {
  360. .fh_to_dentry = ext2_fh_to_dentry,
  361. .fh_to_parent = ext2_fh_to_parent,
  362. .get_parent = ext2_get_parent,
  363. };
  364. static unsigned long get_sb_block(void **data)
  365. {
  366. unsigned long sb_block;
  367. char *options = (char *) *data;
  368. if (!options || strncmp(options, "sb=", 3) != 0)
  369. return 1; /* Default location */
  370. options += 3;
  371. sb_block = simple_strtoul(options, &options, 0);
  372. if (*options && *options != ',') {
  373. printk("EXT2-fs: Invalid sb specification: %s\n",
  374. (char *) *data);
  375. return 1;
  376. }
  377. if (*options == ',')
  378. options++;
  379. *data = (void *) options;
  380. return sb_block;
  381. }
  382. enum {
  383. Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid,
  384. Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic,
  385. Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
  386. Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
  387. Opt_acl, Opt_noacl, Opt_xip, Opt_dax, Opt_ignore, Opt_err, Opt_quota,
  388. Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
  389. };
  390. static const match_table_t tokens = {
  391. {Opt_bsd_df, "bsddf"},
  392. {Opt_minix_df, "minixdf"},
  393. {Opt_grpid, "grpid"},
  394. {Opt_grpid, "bsdgroups"},
  395. {Opt_nogrpid, "nogrpid"},
  396. {Opt_nogrpid, "sysvgroups"},
  397. {Opt_resgid, "resgid=%u"},
  398. {Opt_resuid, "resuid=%u"},
  399. {Opt_sb, "sb=%u"},
  400. {Opt_err_cont, "errors=continue"},
  401. {Opt_err_panic, "errors=panic"},
  402. {Opt_err_ro, "errors=remount-ro"},
  403. {Opt_nouid32, "nouid32"},
  404. {Opt_nocheck, "check=none"},
  405. {Opt_nocheck, "nocheck"},
  406. {Opt_debug, "debug"},
  407. {Opt_oldalloc, "oldalloc"},
  408. {Opt_orlov, "orlov"},
  409. {Opt_nobh, "nobh"},
  410. {Opt_user_xattr, "user_xattr"},
  411. {Opt_nouser_xattr, "nouser_xattr"},
  412. {Opt_acl, "acl"},
  413. {Opt_noacl, "noacl"},
  414. {Opt_xip, "xip"},
  415. {Opt_dax, "dax"},
  416. {Opt_grpquota, "grpquota"},
  417. {Opt_ignore, "noquota"},
  418. {Opt_quota, "quota"},
  419. {Opt_usrquota, "usrquota"},
  420. {Opt_reservation, "reservation"},
  421. {Opt_noreservation, "noreservation"},
  422. {Opt_err, NULL}
  423. };
  424. static int parse_options(char *options, struct super_block *sb,
  425. struct ext2_mount_options *opts)
  426. {
  427. char *p;
  428. substring_t args[MAX_OPT_ARGS];
  429. int option;
  430. kuid_t uid;
  431. kgid_t gid;
  432. if (!options)
  433. return 1;
  434. while ((p = strsep (&options, ",")) != NULL) {
  435. int token;
  436. if (!*p)
  437. continue;
  438. token = match_token(p, tokens, args);
  439. switch (token) {
  440. case Opt_bsd_df:
  441. clear_opt (opts->s_mount_opt, MINIX_DF);
  442. break;
  443. case Opt_minix_df:
  444. set_opt (opts->s_mount_opt, MINIX_DF);
  445. break;
  446. case Opt_grpid:
  447. set_opt (opts->s_mount_opt, GRPID);
  448. break;
  449. case Opt_nogrpid:
  450. clear_opt (opts->s_mount_opt, GRPID);
  451. break;
  452. case Opt_resuid:
  453. if (match_int(&args[0], &option))
  454. return 0;
  455. uid = make_kuid(current_user_ns(), option);
  456. if (!uid_valid(uid)) {
  457. ext2_msg(sb, KERN_ERR, "Invalid uid value %d", option);
  458. return 0;
  459. }
  460. opts->s_resuid = uid;
  461. break;
  462. case Opt_resgid:
  463. if (match_int(&args[0], &option))
  464. return 0;
  465. gid = make_kgid(current_user_ns(), option);
  466. if (!gid_valid(gid)) {
  467. ext2_msg(sb, KERN_ERR, "Invalid gid value %d", option);
  468. return 0;
  469. }
  470. opts->s_resgid = gid;
  471. break;
  472. case Opt_sb:
  473. /* handled by get_sb_block() instead of here */
  474. /* *sb_block = match_int(&args[0]); */
  475. break;
  476. case Opt_err_panic:
  477. clear_opt (opts->s_mount_opt, ERRORS_CONT);
  478. clear_opt (opts->s_mount_opt, ERRORS_RO);
  479. set_opt (opts->s_mount_opt, ERRORS_PANIC);
  480. break;
  481. case Opt_err_ro:
  482. clear_opt (opts->s_mount_opt, ERRORS_CONT);
  483. clear_opt (opts->s_mount_opt, ERRORS_PANIC);
  484. set_opt (opts->s_mount_opt, ERRORS_RO);
  485. break;
  486. case Opt_err_cont:
  487. clear_opt (opts->s_mount_opt, ERRORS_RO);
  488. clear_opt (opts->s_mount_opt, ERRORS_PANIC);
  489. set_opt (opts->s_mount_opt, ERRORS_CONT);
  490. break;
  491. case Opt_nouid32:
  492. set_opt (opts->s_mount_opt, NO_UID32);
  493. break;
  494. case Opt_nocheck:
  495. clear_opt (opts->s_mount_opt, CHECK);
  496. break;
  497. case Opt_debug:
  498. set_opt (opts->s_mount_opt, DEBUG);
  499. break;
  500. case Opt_oldalloc:
  501. set_opt (opts->s_mount_opt, OLDALLOC);
  502. break;
  503. case Opt_orlov:
  504. clear_opt (opts->s_mount_opt, OLDALLOC);
  505. break;
  506. case Opt_nobh:
  507. set_opt (opts->s_mount_opt, NOBH);
  508. break;
  509. #ifdef CONFIG_EXT2_FS_XATTR
  510. case Opt_user_xattr:
  511. set_opt (opts->s_mount_opt, XATTR_USER);
  512. break;
  513. case Opt_nouser_xattr:
  514. clear_opt (opts->s_mount_opt, XATTR_USER);
  515. break;
  516. #else
  517. case Opt_user_xattr:
  518. case Opt_nouser_xattr:
  519. ext2_msg(sb, KERN_INFO, "(no)user_xattr options"
  520. "not supported");
  521. break;
  522. #endif
  523. #ifdef CONFIG_EXT2_FS_POSIX_ACL
  524. case Opt_acl:
  525. set_opt(opts->s_mount_opt, POSIX_ACL);
  526. break;
  527. case Opt_noacl:
  528. clear_opt(opts->s_mount_opt, POSIX_ACL);
  529. break;
  530. #else
  531. case Opt_acl:
  532. case Opt_noacl:
  533. ext2_msg(sb, KERN_INFO,
  534. "(no)acl options not supported");
  535. break;
  536. #endif
  537. case Opt_xip:
  538. ext2_msg(sb, KERN_INFO, "use dax instead of xip");
  539. set_opt(opts->s_mount_opt, XIP);
  540. /* Fall through */
  541. case Opt_dax:
  542. #ifdef CONFIG_FS_DAX
  543. ext2_msg(sb, KERN_WARNING,
  544. "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
  545. set_opt(opts->s_mount_opt, DAX);
  546. #else
  547. ext2_msg(sb, KERN_INFO, "dax option not supported");
  548. #endif
  549. break;
  550. #if defined(CONFIG_QUOTA)
  551. case Opt_quota:
  552. case Opt_usrquota:
  553. set_opt(opts->s_mount_opt, USRQUOTA);
  554. break;
  555. case Opt_grpquota:
  556. set_opt(opts->s_mount_opt, GRPQUOTA);
  557. break;
  558. #else
  559. case Opt_quota:
  560. case Opt_usrquota:
  561. case Opt_grpquota:
  562. ext2_msg(sb, KERN_INFO,
  563. "quota operations not supported");
  564. break;
  565. #endif
  566. case Opt_reservation:
  567. set_opt(opts->s_mount_opt, RESERVATION);
  568. ext2_msg(sb, KERN_INFO, "reservations ON");
  569. break;
  570. case Opt_noreservation:
  571. clear_opt(opts->s_mount_opt, RESERVATION);
  572. ext2_msg(sb, KERN_INFO, "reservations OFF");
  573. break;
  574. case Opt_ignore:
  575. break;
  576. default:
  577. return 0;
  578. }
  579. }
  580. return 1;
  581. }
  582. static int ext2_setup_super (struct super_block * sb,
  583. struct ext2_super_block * es,
  584. int read_only)
  585. {
  586. int res = 0;
  587. struct ext2_sb_info *sbi = EXT2_SB(sb);
  588. if (le32_to_cpu(es->s_rev_level) > EXT2_MAX_SUPP_REV) {
  589. ext2_msg(sb, KERN_ERR,
  590. "error: revision level too high, "
  591. "forcing read-only mode");
  592. res = SB_RDONLY;
  593. }
  594. if (read_only)
  595. return res;
  596. if (!(sbi->s_mount_state & EXT2_VALID_FS))
  597. ext2_msg(sb, KERN_WARNING,
  598. "warning: mounting unchecked fs, "
  599. "running e2fsck is recommended");
  600. else if ((sbi->s_mount_state & EXT2_ERROR_FS))
  601. ext2_msg(sb, KERN_WARNING,
  602. "warning: mounting fs with errors, "
  603. "running e2fsck is recommended");
  604. else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 &&
  605. le16_to_cpu(es->s_mnt_count) >=
  606. (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count))
  607. ext2_msg(sb, KERN_WARNING,
  608. "warning: maximal mount count reached, "
  609. "running e2fsck is recommended");
  610. else if (le32_to_cpu(es->s_checkinterval) &&
  611. (le32_to_cpu(es->s_lastcheck) +
  612. le32_to_cpu(es->s_checkinterval) <= get_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 = -EINVAL;
  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. err = -ENOMEM;
  749. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  750. if (!sbi)
  751. goto failed;
  752. sbi->s_blockgroup_lock =
  753. kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
  754. if (!sbi->s_blockgroup_lock) {
  755. kfree(sbi);
  756. goto failed;
  757. }
  758. sb->s_fs_info = sbi;
  759. sbi->s_sb_block = sb_block;
  760. sbi->s_daxdev = dax_dev;
  761. spin_lock_init(&sbi->s_lock);
  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. /* Set defaults before we parse the mount options */
  798. def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
  799. if (def_mount_opts & EXT2_DEFM_DEBUG)
  800. set_opt(opts.s_mount_opt, DEBUG);
  801. if (def_mount_opts & EXT2_DEFM_BSDGROUPS)
  802. set_opt(opts.s_mount_opt, GRPID);
  803. if (def_mount_opts & EXT2_DEFM_UID16)
  804. set_opt(opts.s_mount_opt, NO_UID32);
  805. #ifdef CONFIG_EXT2_FS_XATTR
  806. if (def_mount_opts & EXT2_DEFM_XATTR_USER)
  807. set_opt(opts.s_mount_opt, XATTR_USER);
  808. #endif
  809. #ifdef CONFIG_EXT2_FS_POSIX_ACL
  810. if (def_mount_opts & EXT2_DEFM_ACL)
  811. set_opt(opts.s_mount_opt, POSIX_ACL);
  812. #endif
  813. if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_PANIC)
  814. set_opt(opts.s_mount_opt, ERRORS_PANIC);
  815. else if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_CONTINUE)
  816. set_opt(opts.s_mount_opt, ERRORS_CONT);
  817. else
  818. set_opt(opts.s_mount_opt, ERRORS_RO);
  819. opts.s_resuid = make_kuid(&init_user_ns, le16_to_cpu(es->s_def_resuid));
  820. opts.s_resgid = make_kgid(&init_user_ns, le16_to_cpu(es->s_def_resgid));
  821. set_opt(opts.s_mount_opt, RESERVATION);
  822. if (!parse_options((char *) data, sb, &opts))
  823. goto failed_mount;
  824. sbi->s_mount_opt = opts.s_mount_opt;
  825. sbi->s_resuid = opts.s_resuid;
  826. sbi->s_resgid = opts.s_resgid;
  827. sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
  828. ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
  829. SB_POSIXACL : 0);
  830. sb->s_iflags |= SB_I_CGROUPWB;
  831. if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV &&
  832. (EXT2_HAS_COMPAT_FEATURE(sb, ~0U) ||
  833. EXT2_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
  834. EXT2_HAS_INCOMPAT_FEATURE(sb, ~0U)))
  835. ext2_msg(sb, KERN_WARNING,
  836. "warning: feature flags set on rev 0 fs, "
  837. "running e2fsck is recommended");
  838. /*
  839. * Check feature flags regardless of the revision level, since we
  840. * previously didn't change the revision level when setting the flags,
  841. * so there is a chance incompat flags are set on a rev 0 filesystem.
  842. */
  843. features = EXT2_HAS_INCOMPAT_FEATURE(sb, ~EXT2_FEATURE_INCOMPAT_SUPP);
  844. if (features) {
  845. ext2_msg(sb, KERN_ERR, "error: couldn't mount because of "
  846. "unsupported optional features (%x)",
  847. le32_to_cpu(features));
  848. goto failed_mount;
  849. }
  850. if (!sb_rdonly(sb) && (features = EXT2_HAS_RO_COMPAT_FEATURE(sb, ~EXT2_FEATURE_RO_COMPAT_SUPP))){
  851. ext2_msg(sb, KERN_ERR, "error: couldn't mount RDWR because of "
  852. "unsupported optional features (%x)",
  853. le32_to_cpu(features));
  854. goto failed_mount;
  855. }
  856. blocksize = BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size);
  857. if (sbi->s_mount_opt & EXT2_MOUNT_DAX) {
  858. err = bdev_dax_supported(sb, blocksize);
  859. if (err) {
  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 (db_count * sizeof (struct buffer_head *), GFP_KERNEL);
  968. if (sbi->s_group_desc == NULL) {
  969. ext2_msg(sb, KERN_ERR, "error: not enough memory");
  970. goto failed_mount;
  971. }
  972. bgl_lock_init(sbi->s_blockgroup_lock);
  973. sbi->s_debts = kcalloc(sbi->s_groups_count, sizeof(*sbi->s_debts), GFP_KERNEL);
  974. if (!sbi->s_debts) {
  975. ext2_msg(sb, KERN_ERR, "error: not enough memory");
  976. goto failed_mount_group_desc;
  977. }
  978. for (i = 0; i < db_count; i++) {
  979. block = descriptor_loc(sb, logic_sb_block, i);
  980. sbi->s_group_desc[i] = sb_bread(sb, block);
  981. if (!sbi->s_group_desc[i]) {
  982. for (j = 0; j < i; j++)
  983. brelse (sbi->s_group_desc[j]);
  984. ext2_msg(sb, KERN_ERR,
  985. "error: unable to read group descriptors");
  986. goto failed_mount_group_desc;
  987. }
  988. }
  989. if (!ext2_check_descriptors (sb)) {
  990. ext2_msg(sb, KERN_ERR, "group descriptors corrupted");
  991. goto failed_mount2;
  992. }
  993. sbi->s_gdb_count = db_count;
  994. get_random_bytes(&sbi->s_next_generation, sizeof(u32));
  995. spin_lock_init(&sbi->s_next_gen_lock);
  996. /* per fileystem reservation list head & lock */
  997. spin_lock_init(&sbi->s_rsv_window_lock);
  998. sbi->s_rsv_window_root = RB_ROOT;
  999. /*
  1000. * Add a single, static dummy reservation to the start of the
  1001. * reservation window list --- it gives us a placeholder for
  1002. * append-at-start-of-list which makes the allocation logic
  1003. * _much_ simpler.
  1004. */
  1005. sbi->s_rsv_window_head.rsv_start = EXT2_RESERVE_WINDOW_NOT_ALLOCATED;
  1006. sbi->s_rsv_window_head.rsv_end = EXT2_RESERVE_WINDOW_NOT_ALLOCATED;
  1007. sbi->s_rsv_window_head.rsv_alloc_hit = 0;
  1008. sbi->s_rsv_window_head.rsv_goal_size = 0;
  1009. ext2_rsv_window_add(sb, &sbi->s_rsv_window_head);
  1010. err = percpu_counter_init(&sbi->s_freeblocks_counter,
  1011. ext2_count_free_blocks(sb), GFP_KERNEL);
  1012. if (!err) {
  1013. err = percpu_counter_init(&sbi->s_freeinodes_counter,
  1014. ext2_count_free_inodes(sb), GFP_KERNEL);
  1015. }
  1016. if (!err) {
  1017. err = percpu_counter_init(&sbi->s_dirs_counter,
  1018. ext2_count_dirs(sb), GFP_KERNEL);
  1019. }
  1020. if (err) {
  1021. ext2_msg(sb, KERN_ERR, "error: insufficient memory");
  1022. goto failed_mount3;
  1023. }
  1024. #ifdef CONFIG_EXT2_FS_XATTR
  1025. sbi->s_ea_block_cache = ext2_xattr_create_cache();
  1026. if (!sbi->s_ea_block_cache) {
  1027. ext2_msg(sb, KERN_ERR, "Failed to create ea_block_cache");
  1028. goto failed_mount3;
  1029. }
  1030. #endif
  1031. /*
  1032. * set up enough so that it can read an inode
  1033. */
  1034. sb->s_op = &ext2_sops;
  1035. sb->s_export_op = &ext2_export_ops;
  1036. sb->s_xattr = ext2_xattr_handlers;
  1037. #ifdef CONFIG_QUOTA
  1038. sb->dq_op = &dquot_operations;
  1039. sb->s_qcop = &ext2_quotactl_ops;
  1040. sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
  1041. #endif
  1042. root = ext2_iget(sb, EXT2_ROOT_INO);
  1043. if (IS_ERR(root)) {
  1044. ret = PTR_ERR(root);
  1045. goto failed_mount3;
  1046. }
  1047. if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
  1048. iput(root);
  1049. ext2_msg(sb, KERN_ERR, "error: corrupt root inode, run e2fsck");
  1050. goto failed_mount3;
  1051. }
  1052. sb->s_root = d_make_root(root);
  1053. if (!sb->s_root) {
  1054. ext2_msg(sb, KERN_ERR, "error: get root inode failed");
  1055. ret = -ENOMEM;
  1056. goto failed_mount3;
  1057. }
  1058. if (EXT2_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL))
  1059. ext2_msg(sb, KERN_WARNING,
  1060. "warning: mounting ext3 filesystem as ext2");
  1061. if (ext2_setup_super (sb, es, sb_rdonly(sb)))
  1062. sb->s_flags |= SB_RDONLY;
  1063. ext2_write_super(sb);
  1064. return 0;
  1065. cantfind_ext2:
  1066. if (!silent)
  1067. ext2_msg(sb, KERN_ERR,
  1068. "error: can't find an ext2 filesystem on dev %s.",
  1069. sb->s_id);
  1070. goto failed_mount;
  1071. failed_mount3:
  1072. if (sbi->s_ea_block_cache)
  1073. ext2_xattr_destroy_cache(sbi->s_ea_block_cache);
  1074. percpu_counter_destroy(&sbi->s_freeblocks_counter);
  1075. percpu_counter_destroy(&sbi->s_freeinodes_counter);
  1076. percpu_counter_destroy(&sbi->s_dirs_counter);
  1077. failed_mount2:
  1078. for (i = 0; i < db_count; i++)
  1079. brelse(sbi->s_group_desc[i]);
  1080. failed_mount_group_desc:
  1081. kfree(sbi->s_group_desc);
  1082. kfree(sbi->s_debts);
  1083. failed_mount:
  1084. brelse(bh);
  1085. failed_sbi:
  1086. sb->s_fs_info = NULL;
  1087. kfree(sbi->s_blockgroup_lock);
  1088. kfree(sbi);
  1089. failed:
  1090. fs_put_dax(dax_dev);
  1091. return ret;
  1092. }
  1093. static void ext2_clear_super_error(struct super_block *sb)
  1094. {
  1095. struct buffer_head *sbh = EXT2_SB(sb)->s_sbh;
  1096. if (buffer_write_io_error(sbh)) {
  1097. /*
  1098. * Oh, dear. A previous attempt to write the
  1099. * superblock failed. This could happen because the
  1100. * USB device was yanked out. Or it could happen to
  1101. * be a transient write error and maybe the block will
  1102. * be remapped. Nothing we can do but to retry the
  1103. * write and hope for the best.
  1104. */
  1105. ext2_msg(sb, KERN_ERR,
  1106. "previous I/O error to superblock detected");
  1107. clear_buffer_write_io_error(sbh);
  1108. set_buffer_uptodate(sbh);
  1109. }
  1110. }
  1111. void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es,
  1112. int wait)
  1113. {
  1114. ext2_clear_super_error(sb);
  1115. spin_lock(&EXT2_SB(sb)->s_lock);
  1116. es->s_free_blocks_count = cpu_to_le32(ext2_count_free_blocks(sb));
  1117. es->s_free_inodes_count = cpu_to_le32(ext2_count_free_inodes(sb));
  1118. es->s_wtime = cpu_to_le32(get_seconds());
  1119. /* unlock before we do IO */
  1120. spin_unlock(&EXT2_SB(sb)->s_lock);
  1121. mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
  1122. if (wait)
  1123. sync_dirty_buffer(EXT2_SB(sb)->s_sbh);
  1124. }
  1125. /*
  1126. * In the second extended file system, it is not necessary to
  1127. * write the super block since we use a mapping of the
  1128. * disk super block in a buffer.
  1129. *
  1130. * However, this function is still used to set the fs valid
  1131. * flags to 0. We need to set this flag to 0 since the fs
  1132. * may have been checked while mounted and e2fsck may have
  1133. * set s_state to EXT2_VALID_FS after some corrections.
  1134. */
  1135. static int ext2_sync_fs(struct super_block *sb, int wait)
  1136. {
  1137. struct ext2_sb_info *sbi = EXT2_SB(sb);
  1138. struct ext2_super_block *es = EXT2_SB(sb)->s_es;
  1139. /*
  1140. * Write quota structures to quota file, sync_blockdev() will write
  1141. * them to disk later
  1142. */
  1143. dquot_writeback_dquots(sb, -1);
  1144. spin_lock(&sbi->s_lock);
  1145. if (es->s_state & cpu_to_le16(EXT2_VALID_FS)) {
  1146. ext2_debug("setting valid to 0\n");
  1147. es->s_state &= cpu_to_le16(~EXT2_VALID_FS);
  1148. }
  1149. spin_unlock(&sbi->s_lock);
  1150. ext2_sync_super(sb, es, wait);
  1151. return 0;
  1152. }
  1153. static int ext2_freeze(struct super_block *sb)
  1154. {
  1155. struct ext2_sb_info *sbi = EXT2_SB(sb);
  1156. /*
  1157. * Open but unlinked files present? Keep EXT2_VALID_FS flag cleared
  1158. * because we have unattached inodes and thus filesystem is not fully
  1159. * consistent.
  1160. */
  1161. if (atomic_long_read(&sb->s_remove_count)) {
  1162. ext2_sync_fs(sb, 1);
  1163. return 0;
  1164. }
  1165. /* Set EXT2_FS_VALID flag */
  1166. spin_lock(&sbi->s_lock);
  1167. sbi->s_es->s_state = cpu_to_le16(sbi->s_mount_state);
  1168. spin_unlock(&sbi->s_lock);
  1169. ext2_sync_super(sb, sbi->s_es, 1);
  1170. return 0;
  1171. }
  1172. static int ext2_unfreeze(struct super_block *sb)
  1173. {
  1174. /* Just write sb to clear EXT2_VALID_FS flag */
  1175. ext2_write_super(sb);
  1176. return 0;
  1177. }
  1178. static void ext2_write_super(struct super_block *sb)
  1179. {
  1180. if (!sb_rdonly(sb))
  1181. ext2_sync_fs(sb, 1);
  1182. }
  1183. static int ext2_remount (struct super_block * sb, int * flags, char * data)
  1184. {
  1185. struct ext2_sb_info * sbi = EXT2_SB(sb);
  1186. struct ext2_super_block * es;
  1187. struct ext2_mount_options new_opts;
  1188. int err;
  1189. sync_filesystem(sb);
  1190. spin_lock(&sbi->s_lock);
  1191. new_opts.s_mount_opt = sbi->s_mount_opt;
  1192. new_opts.s_resuid = sbi->s_resuid;
  1193. new_opts.s_resgid = sbi->s_resgid;
  1194. spin_unlock(&sbi->s_lock);
  1195. /*
  1196. * Allow the "check" option to be passed as a remount option.
  1197. */
  1198. if (!parse_options(data, sb, &new_opts))
  1199. return -EINVAL;
  1200. spin_lock(&sbi->s_lock);
  1201. es = sbi->s_es;
  1202. if ((sbi->s_mount_opt ^ new_opts.s_mount_opt) & EXT2_MOUNT_DAX) {
  1203. ext2_msg(sb, KERN_WARNING, "warning: refusing change of "
  1204. "dax flag with busy inodes while remounting");
  1205. new_opts.s_mount_opt ^= EXT2_MOUNT_DAX;
  1206. }
  1207. if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
  1208. goto out_set;
  1209. if (*flags & SB_RDONLY) {
  1210. if (le16_to_cpu(es->s_state) & EXT2_VALID_FS ||
  1211. !(sbi->s_mount_state & EXT2_VALID_FS))
  1212. goto out_set;
  1213. /*
  1214. * OK, we are remounting a valid rw partition rdonly, so set
  1215. * the rdonly flag and then mark the partition as valid again.
  1216. */
  1217. es->s_state = cpu_to_le16(sbi->s_mount_state);
  1218. es->s_mtime = cpu_to_le32(get_seconds());
  1219. spin_unlock(&sbi->s_lock);
  1220. err = dquot_suspend(sb, -1);
  1221. if (err < 0)
  1222. return err;
  1223. ext2_sync_super(sb, es, 1);
  1224. } else {
  1225. __le32 ret = EXT2_HAS_RO_COMPAT_FEATURE(sb,
  1226. ~EXT2_FEATURE_RO_COMPAT_SUPP);
  1227. if (ret) {
  1228. spin_unlock(&sbi->s_lock);
  1229. ext2_msg(sb, KERN_WARNING,
  1230. "warning: couldn't remount RDWR because of "
  1231. "unsupported optional features (%x).",
  1232. le32_to_cpu(ret));
  1233. return -EROFS;
  1234. }
  1235. /*
  1236. * Mounting a RDONLY partition read-write, so reread and
  1237. * store the current valid flag. (It may have been changed
  1238. * by e2fsck since we originally mounted the partition.)
  1239. */
  1240. sbi->s_mount_state = le16_to_cpu(es->s_state);
  1241. if (!ext2_setup_super (sb, es, 0))
  1242. sb->s_flags &= ~SB_RDONLY;
  1243. spin_unlock(&sbi->s_lock);
  1244. ext2_write_super(sb);
  1245. dquot_resume(sb, -1);
  1246. }
  1247. spin_lock(&sbi->s_lock);
  1248. out_set:
  1249. sbi->s_mount_opt = new_opts.s_mount_opt;
  1250. sbi->s_resuid = new_opts.s_resuid;
  1251. sbi->s_resgid = new_opts.s_resgid;
  1252. sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
  1253. ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? SB_POSIXACL : 0);
  1254. spin_unlock(&sbi->s_lock);
  1255. return 0;
  1256. }
  1257. static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf)
  1258. {
  1259. struct super_block *sb = dentry->d_sb;
  1260. struct ext2_sb_info *sbi = EXT2_SB(sb);
  1261. struct ext2_super_block *es = sbi->s_es;
  1262. u64 fsid;
  1263. spin_lock(&sbi->s_lock);
  1264. if (test_opt (sb, MINIX_DF))
  1265. sbi->s_overhead_last = 0;
  1266. else if (sbi->s_blocks_last != le32_to_cpu(es->s_blocks_count)) {
  1267. unsigned long i, overhead = 0;
  1268. smp_rmb();
  1269. /*
  1270. * Compute the overhead (FS structures). This is constant
  1271. * for a given filesystem unless the number of block groups
  1272. * changes so we cache the previous value until it does.
  1273. */
  1274. /*
  1275. * All of the blocks before first_data_block are
  1276. * overhead
  1277. */
  1278. overhead = le32_to_cpu(es->s_first_data_block);
  1279. /*
  1280. * Add the overhead attributed to the superblock and
  1281. * block group descriptors. If the sparse superblocks
  1282. * feature is turned on, then not all groups have this.
  1283. */
  1284. for (i = 0; i < sbi->s_groups_count; i++)
  1285. overhead += ext2_bg_has_super(sb, i) +
  1286. ext2_bg_num_gdb(sb, i);
  1287. /*
  1288. * Every block group has an inode bitmap, a block
  1289. * bitmap, and an inode table.
  1290. */
  1291. overhead += (sbi->s_groups_count *
  1292. (2 + sbi->s_itb_per_group));
  1293. sbi->s_overhead_last = overhead;
  1294. smp_wmb();
  1295. sbi->s_blocks_last = le32_to_cpu(es->s_blocks_count);
  1296. }
  1297. buf->f_type = EXT2_SUPER_MAGIC;
  1298. buf->f_bsize = sb->s_blocksize;
  1299. buf->f_blocks = le32_to_cpu(es->s_blocks_count) - sbi->s_overhead_last;
  1300. buf->f_bfree = ext2_count_free_blocks(sb);
  1301. es->s_free_blocks_count = cpu_to_le32(buf->f_bfree);
  1302. buf->f_bavail = buf->f_bfree - le32_to_cpu(es->s_r_blocks_count);
  1303. if (buf->f_bfree < le32_to_cpu(es->s_r_blocks_count))
  1304. buf->f_bavail = 0;
  1305. buf->f_files = le32_to_cpu(es->s_inodes_count);
  1306. buf->f_ffree = ext2_count_free_inodes(sb);
  1307. es->s_free_inodes_count = cpu_to_le32(buf->f_ffree);
  1308. buf->f_namelen = EXT2_NAME_LEN;
  1309. fsid = le64_to_cpup((void *)es->s_uuid) ^
  1310. le64_to_cpup((void *)es->s_uuid + sizeof(u64));
  1311. buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL;
  1312. buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL;
  1313. spin_unlock(&sbi->s_lock);
  1314. return 0;
  1315. }
  1316. static struct dentry *ext2_mount(struct file_system_type *fs_type,
  1317. int flags, const char *dev_name, void *data)
  1318. {
  1319. return mount_bdev(fs_type, flags, dev_name, data, ext2_fill_super);
  1320. }
  1321. #ifdef CONFIG_QUOTA
  1322. /* Read data from quotafile - avoid pagecache and such because we cannot afford
  1323. * acquiring the locks... As quota files are never truncated and quota code
  1324. * itself serializes the operations (and no one else should touch the files)
  1325. * we don't have to be afraid of races */
  1326. static ssize_t ext2_quota_read(struct super_block *sb, int type, char *data,
  1327. size_t len, loff_t off)
  1328. {
  1329. struct inode *inode = sb_dqopt(sb)->files[type];
  1330. sector_t blk = off >> EXT2_BLOCK_SIZE_BITS(sb);
  1331. int err = 0;
  1332. int offset = off & (sb->s_blocksize - 1);
  1333. int tocopy;
  1334. size_t toread;
  1335. struct buffer_head tmp_bh;
  1336. struct buffer_head *bh;
  1337. loff_t i_size = i_size_read(inode);
  1338. if (off > i_size)
  1339. return 0;
  1340. if (off+len > i_size)
  1341. len = i_size-off;
  1342. toread = len;
  1343. while (toread > 0) {
  1344. tocopy = sb->s_blocksize - offset < toread ?
  1345. sb->s_blocksize - offset : toread;
  1346. tmp_bh.b_state = 0;
  1347. tmp_bh.b_size = sb->s_blocksize;
  1348. err = ext2_get_block(inode, blk, &tmp_bh, 0);
  1349. if (err < 0)
  1350. return err;
  1351. if (!buffer_mapped(&tmp_bh)) /* A hole? */
  1352. memset(data, 0, tocopy);
  1353. else {
  1354. bh = sb_bread(sb, tmp_bh.b_blocknr);
  1355. if (!bh)
  1356. return -EIO;
  1357. memcpy(data, bh->b_data+offset, tocopy);
  1358. brelse(bh);
  1359. }
  1360. offset = 0;
  1361. toread -= tocopy;
  1362. data += tocopy;
  1363. blk++;
  1364. }
  1365. return len;
  1366. }
  1367. /* Write to quotafile */
  1368. static ssize_t ext2_quota_write(struct super_block *sb, int type,
  1369. const char *data, size_t len, loff_t off)
  1370. {
  1371. struct inode *inode = sb_dqopt(sb)->files[type];
  1372. sector_t blk = off >> EXT2_BLOCK_SIZE_BITS(sb);
  1373. int err = 0;
  1374. int offset = off & (sb->s_blocksize - 1);
  1375. int tocopy;
  1376. size_t towrite = len;
  1377. struct buffer_head tmp_bh;
  1378. struct buffer_head *bh;
  1379. while (towrite > 0) {
  1380. tocopy = sb->s_blocksize - offset < towrite ?
  1381. sb->s_blocksize - offset : towrite;
  1382. tmp_bh.b_state = 0;
  1383. tmp_bh.b_size = sb->s_blocksize;
  1384. err = ext2_get_block(inode, blk, &tmp_bh, 1);
  1385. if (err < 0)
  1386. goto out;
  1387. if (offset || tocopy != EXT2_BLOCK_SIZE(sb))
  1388. bh = sb_bread(sb, tmp_bh.b_blocknr);
  1389. else
  1390. bh = sb_getblk(sb, tmp_bh.b_blocknr);
  1391. if (unlikely(!bh)) {
  1392. err = -EIO;
  1393. goto out;
  1394. }
  1395. lock_buffer(bh);
  1396. memcpy(bh->b_data+offset, data, tocopy);
  1397. flush_dcache_page(bh->b_page);
  1398. set_buffer_uptodate(bh);
  1399. mark_buffer_dirty(bh);
  1400. unlock_buffer(bh);
  1401. brelse(bh);
  1402. offset = 0;
  1403. towrite -= tocopy;
  1404. data += tocopy;
  1405. blk++;
  1406. }
  1407. out:
  1408. if (len == towrite)
  1409. return err;
  1410. if (inode->i_size < off+len-towrite)
  1411. i_size_write(inode, off+len-towrite);
  1412. inode_inc_iversion(inode);
  1413. inode->i_mtime = inode->i_ctime = current_time(inode);
  1414. mark_inode_dirty(inode);
  1415. return len - towrite;
  1416. }
  1417. static int ext2_quota_on(struct super_block *sb, int type, int format_id,
  1418. const struct path *path)
  1419. {
  1420. int err;
  1421. struct inode *inode;
  1422. err = dquot_quota_on(sb, type, format_id, path);
  1423. if (err)
  1424. return err;
  1425. inode = d_inode(path->dentry);
  1426. inode_lock(inode);
  1427. EXT2_I(inode)->i_flags |= EXT2_NOATIME_FL | EXT2_IMMUTABLE_FL;
  1428. inode_set_flags(inode, S_NOATIME | S_IMMUTABLE,
  1429. S_NOATIME | S_IMMUTABLE);
  1430. inode_unlock(inode);
  1431. mark_inode_dirty(inode);
  1432. return 0;
  1433. }
  1434. static int ext2_quota_off(struct super_block *sb, int type)
  1435. {
  1436. struct inode *inode = sb_dqopt(sb)->files[type];
  1437. int err;
  1438. if (!inode || !igrab(inode))
  1439. goto out;
  1440. err = dquot_quota_off(sb, type);
  1441. if (err)
  1442. goto out_put;
  1443. inode_lock(inode);
  1444. EXT2_I(inode)->i_flags &= ~(EXT2_NOATIME_FL | EXT2_IMMUTABLE_FL);
  1445. inode_set_flags(inode, 0, S_NOATIME | S_IMMUTABLE);
  1446. inode_unlock(inode);
  1447. mark_inode_dirty(inode);
  1448. out_put:
  1449. iput(inode);
  1450. return err;
  1451. out:
  1452. return dquot_quota_off(sb, type);
  1453. }
  1454. #endif
  1455. static struct file_system_type ext2_fs_type = {
  1456. .owner = THIS_MODULE,
  1457. .name = "ext2",
  1458. .mount = ext2_mount,
  1459. .kill_sb = kill_block_super,
  1460. .fs_flags = FS_REQUIRES_DEV,
  1461. };
  1462. MODULE_ALIAS_FS("ext2");
  1463. static int __init init_ext2_fs(void)
  1464. {
  1465. int err;
  1466. err = init_inodecache();
  1467. if (err)
  1468. return err;
  1469. err = register_filesystem(&ext2_fs_type);
  1470. if (err)
  1471. goto out;
  1472. return 0;
  1473. out:
  1474. destroy_inodecache();
  1475. return err;
  1476. }
  1477. static void __exit exit_ext2_fs(void)
  1478. {
  1479. unregister_filesystem(&ext2_fs_type);
  1480. destroy_inodecache();
  1481. }
  1482. MODULE_AUTHOR("Remy Card and others");
  1483. MODULE_DESCRIPTION("Second Extended Filesystem");
  1484. MODULE_LICENSE("GPL");
  1485. module_init(init_ext2_fs)
  1486. module_exit(exit_ext2_fs)