super.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681
  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. ext2_msg(sb, KERN_WARNING,
  496. "Option nocheck/check=none is deprecated and"
  497. " will be removed in June 2020.");
  498. clear_opt (opts->s_mount_opt, CHECK);
  499. break;
  500. case Opt_debug:
  501. set_opt (opts->s_mount_opt, DEBUG);
  502. break;
  503. case Opt_oldalloc:
  504. set_opt (opts->s_mount_opt, OLDALLOC);
  505. break;
  506. case Opt_orlov:
  507. clear_opt (opts->s_mount_opt, OLDALLOC);
  508. break;
  509. case Opt_nobh:
  510. set_opt (opts->s_mount_opt, NOBH);
  511. break;
  512. #ifdef CONFIG_EXT2_FS_XATTR
  513. case Opt_user_xattr:
  514. set_opt (opts->s_mount_opt, XATTR_USER);
  515. break;
  516. case Opt_nouser_xattr:
  517. clear_opt (opts->s_mount_opt, XATTR_USER);
  518. break;
  519. #else
  520. case Opt_user_xattr:
  521. case Opt_nouser_xattr:
  522. ext2_msg(sb, KERN_INFO, "(no)user_xattr options"
  523. "not supported");
  524. break;
  525. #endif
  526. #ifdef CONFIG_EXT2_FS_POSIX_ACL
  527. case Opt_acl:
  528. set_opt(opts->s_mount_opt, POSIX_ACL);
  529. break;
  530. case Opt_noacl:
  531. clear_opt(opts->s_mount_opt, POSIX_ACL);
  532. break;
  533. #else
  534. case Opt_acl:
  535. case Opt_noacl:
  536. ext2_msg(sb, KERN_INFO,
  537. "(no)acl options not supported");
  538. break;
  539. #endif
  540. case Opt_xip:
  541. ext2_msg(sb, KERN_INFO, "use dax instead of xip");
  542. set_opt(opts->s_mount_opt, XIP);
  543. /* Fall through */
  544. case Opt_dax:
  545. #ifdef CONFIG_FS_DAX
  546. ext2_msg(sb, KERN_WARNING,
  547. "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
  548. set_opt(opts->s_mount_opt, DAX);
  549. #else
  550. ext2_msg(sb, KERN_INFO, "dax option not supported");
  551. #endif
  552. break;
  553. #if defined(CONFIG_QUOTA)
  554. case Opt_quota:
  555. case Opt_usrquota:
  556. set_opt(opts->s_mount_opt, USRQUOTA);
  557. break;
  558. case Opt_grpquota:
  559. set_opt(opts->s_mount_opt, GRPQUOTA);
  560. break;
  561. #else
  562. case Opt_quota:
  563. case Opt_usrquota:
  564. case Opt_grpquota:
  565. ext2_msg(sb, KERN_INFO,
  566. "quota operations not supported");
  567. break;
  568. #endif
  569. case Opt_reservation:
  570. set_opt(opts->s_mount_opt, RESERVATION);
  571. ext2_msg(sb, KERN_INFO, "reservations ON");
  572. break;
  573. case Opt_noreservation:
  574. clear_opt(opts->s_mount_opt, RESERVATION);
  575. ext2_msg(sb, KERN_INFO, "reservations OFF");
  576. break;
  577. case Opt_ignore:
  578. break;
  579. default:
  580. return 0;
  581. }
  582. }
  583. return 1;
  584. }
  585. static int ext2_setup_super (struct super_block * sb,
  586. struct ext2_super_block * es,
  587. int read_only)
  588. {
  589. int res = 0;
  590. struct ext2_sb_info *sbi = EXT2_SB(sb);
  591. if (le32_to_cpu(es->s_rev_level) > EXT2_MAX_SUPP_REV) {
  592. ext2_msg(sb, KERN_ERR,
  593. "error: revision level too high, "
  594. "forcing read-only mode");
  595. res = SB_RDONLY;
  596. }
  597. if (read_only)
  598. return res;
  599. if (!(sbi->s_mount_state & EXT2_VALID_FS))
  600. ext2_msg(sb, KERN_WARNING,
  601. "warning: mounting unchecked fs, "
  602. "running e2fsck is recommended");
  603. else if ((sbi->s_mount_state & EXT2_ERROR_FS))
  604. ext2_msg(sb, KERN_WARNING,
  605. "warning: mounting fs with errors, "
  606. "running e2fsck is recommended");
  607. else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 &&
  608. le16_to_cpu(es->s_mnt_count) >=
  609. (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count))
  610. ext2_msg(sb, KERN_WARNING,
  611. "warning: maximal mount count reached, "
  612. "running e2fsck is recommended");
  613. else if (le32_to_cpu(es->s_checkinterval) &&
  614. (le32_to_cpu(es->s_lastcheck) +
  615. le32_to_cpu(es->s_checkinterval) <=
  616. ktime_get_real_seconds()))
  617. ext2_msg(sb, KERN_WARNING,
  618. "warning: checktime reached, "
  619. "running e2fsck is recommended");
  620. if (!le16_to_cpu(es->s_max_mnt_count))
  621. es->s_max_mnt_count = cpu_to_le16(EXT2_DFL_MAX_MNT_COUNT);
  622. le16_add_cpu(&es->s_mnt_count, 1);
  623. if (test_opt (sb, DEBUG))
  624. ext2_msg(sb, KERN_INFO, "%s, %s, bs=%lu, fs=%lu, gc=%lu, "
  625. "bpg=%lu, ipg=%lu, mo=%04lx]",
  626. EXT2FS_VERSION, EXT2FS_DATE, sb->s_blocksize,
  627. sbi->s_frag_size,
  628. sbi->s_groups_count,
  629. EXT2_BLOCKS_PER_GROUP(sb),
  630. EXT2_INODES_PER_GROUP(sb),
  631. sbi->s_mount_opt);
  632. return res;
  633. }
  634. static int ext2_check_descriptors(struct super_block *sb)
  635. {
  636. int i;
  637. struct ext2_sb_info *sbi = EXT2_SB(sb);
  638. ext2_debug ("Checking group descriptors");
  639. for (i = 0; i < sbi->s_groups_count; i++) {
  640. struct ext2_group_desc *gdp = ext2_get_group_desc(sb, i, NULL);
  641. ext2_fsblk_t first_block = ext2_group_first_block_no(sb, i);
  642. ext2_fsblk_t last_block;
  643. if (i == sbi->s_groups_count - 1)
  644. last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1;
  645. else
  646. last_block = first_block +
  647. (EXT2_BLOCKS_PER_GROUP(sb) - 1);
  648. if (le32_to_cpu(gdp->bg_block_bitmap) < first_block ||
  649. le32_to_cpu(gdp->bg_block_bitmap) > last_block)
  650. {
  651. ext2_error (sb, "ext2_check_descriptors",
  652. "Block bitmap for group %d"
  653. " not in group (block %lu)!",
  654. i, (unsigned long) le32_to_cpu(gdp->bg_block_bitmap));
  655. return 0;
  656. }
  657. if (le32_to_cpu(gdp->bg_inode_bitmap) < first_block ||
  658. le32_to_cpu(gdp->bg_inode_bitmap) > last_block)
  659. {
  660. ext2_error (sb, "ext2_check_descriptors",
  661. "Inode bitmap for group %d"
  662. " not in group (block %lu)!",
  663. i, (unsigned long) le32_to_cpu(gdp->bg_inode_bitmap));
  664. return 0;
  665. }
  666. if (le32_to_cpu(gdp->bg_inode_table) < first_block ||
  667. le32_to_cpu(gdp->bg_inode_table) + sbi->s_itb_per_group - 1 >
  668. last_block)
  669. {
  670. ext2_error (sb, "ext2_check_descriptors",
  671. "Inode table for group %d"
  672. " not in group (block %lu)!",
  673. i, (unsigned long) le32_to_cpu(gdp->bg_inode_table));
  674. return 0;
  675. }
  676. }
  677. return 1;
  678. }
  679. /*
  680. * Maximal file size. There is a direct, and {,double-,triple-}indirect
  681. * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks.
  682. * We need to be 1 filesystem block less than the 2^32 sector limit.
  683. */
  684. static loff_t ext2_max_size(int bits)
  685. {
  686. loff_t res = EXT2_NDIR_BLOCKS;
  687. int meta_blocks;
  688. unsigned int upper_limit;
  689. unsigned int ppb = 1 << (bits-2);
  690. /* This is calculated to be the largest file size for a
  691. * dense, file such that the total number of
  692. * sectors in the file, including data and all indirect blocks,
  693. * does not exceed 2^32 -1
  694. * __u32 i_blocks representing the total number of
  695. * 512 bytes blocks of the file
  696. */
  697. upper_limit = (1LL << 32) - 1;
  698. /* total blocks in file system block size */
  699. upper_limit >>= (bits - 9);
  700. /* Compute how many blocks we can address by block tree */
  701. res += 1LL << (bits-2);
  702. res += 1LL << (2*(bits-2));
  703. res += 1LL << (3*(bits-2));
  704. /* Does block tree limit file size? */
  705. if (res < upper_limit)
  706. goto check_lfs;
  707. res = upper_limit;
  708. /* How many metadata blocks are needed for addressing upper_limit? */
  709. upper_limit -= EXT2_NDIR_BLOCKS;
  710. /* indirect blocks */
  711. meta_blocks = 1;
  712. upper_limit -= ppb;
  713. /* double indirect blocks */
  714. if (upper_limit < ppb * ppb) {
  715. meta_blocks += 1 + DIV_ROUND_UP(upper_limit, ppb);
  716. res -= meta_blocks;
  717. goto check_lfs;
  718. }
  719. meta_blocks += 1 + ppb;
  720. upper_limit -= ppb * ppb;
  721. /* tripple indirect blocks for the rest */
  722. meta_blocks += 1 + DIV_ROUND_UP(upper_limit, ppb) +
  723. DIV_ROUND_UP(upper_limit, ppb*ppb);
  724. res -= meta_blocks;
  725. check_lfs:
  726. res <<= bits;
  727. if (res > MAX_LFS_FILESIZE)
  728. res = MAX_LFS_FILESIZE;
  729. return res;
  730. }
  731. static unsigned long descriptor_loc(struct super_block *sb,
  732. unsigned long logic_sb_block,
  733. int nr)
  734. {
  735. struct ext2_sb_info *sbi = EXT2_SB(sb);
  736. unsigned long bg, first_meta_bg;
  737. int has_super = 0;
  738. first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg);
  739. if (!EXT2_HAS_INCOMPAT_FEATURE(sb, EXT2_FEATURE_INCOMPAT_META_BG) ||
  740. nr < first_meta_bg)
  741. return (logic_sb_block + nr + 1);
  742. bg = sbi->s_desc_per_block * nr;
  743. if (ext2_bg_has_super(sb, bg))
  744. has_super = 1;
  745. return ext2_group_first_block_no(sb, bg) + has_super;
  746. }
  747. static int ext2_fill_super(struct super_block *sb, void *data, int silent)
  748. {
  749. struct dax_device *dax_dev = fs_dax_get_by_bdev(sb->s_bdev);
  750. struct buffer_head * bh;
  751. struct ext2_sb_info * sbi;
  752. struct ext2_super_block * es;
  753. struct inode *root;
  754. unsigned long block;
  755. unsigned long sb_block = get_sb_block(&data);
  756. unsigned long logic_sb_block;
  757. unsigned long offset = 0;
  758. unsigned long def_mount_opts;
  759. long ret = -ENOMEM;
  760. int blocksize = BLOCK_SIZE;
  761. int db_count;
  762. int i, j;
  763. __le32 features;
  764. int err;
  765. struct ext2_mount_options opts;
  766. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  767. if (!sbi)
  768. goto failed;
  769. sbi->s_blockgroup_lock =
  770. kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
  771. if (!sbi->s_blockgroup_lock) {
  772. kfree(sbi);
  773. goto failed;
  774. }
  775. sb->s_fs_info = sbi;
  776. sbi->s_sb_block = sb_block;
  777. sbi->s_daxdev = dax_dev;
  778. spin_lock_init(&sbi->s_lock);
  779. ret = -EINVAL;
  780. /*
  781. * See what the current blocksize for the device is, and
  782. * use that as the blocksize. Otherwise (or if the blocksize
  783. * is smaller than the default) use the default.
  784. * This is important for devices that have a hardware
  785. * sectorsize that is larger than the default.
  786. */
  787. blocksize = sb_min_blocksize(sb, BLOCK_SIZE);
  788. if (!blocksize) {
  789. ext2_msg(sb, KERN_ERR, "error: unable to set blocksize");
  790. goto failed_sbi;
  791. }
  792. /*
  793. * If the superblock doesn't start on a hardware sector boundary,
  794. * calculate the offset.
  795. */
  796. if (blocksize != BLOCK_SIZE) {
  797. logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize;
  798. offset = (sb_block*BLOCK_SIZE) % blocksize;
  799. } else {
  800. logic_sb_block = sb_block;
  801. }
  802. if (!(bh = sb_bread(sb, logic_sb_block))) {
  803. ext2_msg(sb, KERN_ERR, "error: unable to read superblock");
  804. goto failed_sbi;
  805. }
  806. /*
  807. * Note: s_es must be initialized as soon as possible because
  808. * some ext2 macro-instructions depend on its value
  809. */
  810. es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
  811. sbi->s_es = es;
  812. sb->s_magic = le16_to_cpu(es->s_magic);
  813. if (sb->s_magic != EXT2_SUPER_MAGIC)
  814. goto cantfind_ext2;
  815. opts.s_mount_opt = 0;
  816. /* Set defaults before we parse the mount options */
  817. def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
  818. if (def_mount_opts & EXT2_DEFM_DEBUG)
  819. set_opt(opts.s_mount_opt, DEBUG);
  820. if (def_mount_opts & EXT2_DEFM_BSDGROUPS)
  821. set_opt(opts.s_mount_opt, GRPID);
  822. if (def_mount_opts & EXT2_DEFM_UID16)
  823. set_opt(opts.s_mount_opt, NO_UID32);
  824. #ifdef CONFIG_EXT2_FS_XATTR
  825. if (def_mount_opts & EXT2_DEFM_XATTR_USER)
  826. set_opt(opts.s_mount_opt, XATTR_USER);
  827. #endif
  828. #ifdef CONFIG_EXT2_FS_POSIX_ACL
  829. if (def_mount_opts & EXT2_DEFM_ACL)
  830. set_opt(opts.s_mount_opt, POSIX_ACL);
  831. #endif
  832. if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_PANIC)
  833. set_opt(opts.s_mount_opt, ERRORS_PANIC);
  834. else if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_CONTINUE)
  835. set_opt(opts.s_mount_opt, ERRORS_CONT);
  836. else
  837. set_opt(opts.s_mount_opt, ERRORS_RO);
  838. opts.s_resuid = make_kuid(&init_user_ns, le16_to_cpu(es->s_def_resuid));
  839. opts.s_resgid = make_kgid(&init_user_ns, le16_to_cpu(es->s_def_resgid));
  840. set_opt(opts.s_mount_opt, RESERVATION);
  841. if (!parse_options((char *) data, sb, &opts))
  842. goto failed_mount;
  843. sbi->s_mount_opt = opts.s_mount_opt;
  844. sbi->s_resuid = opts.s_resuid;
  845. sbi->s_resgid = opts.s_resgid;
  846. sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
  847. ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
  848. SB_POSIXACL : 0);
  849. sb->s_iflags |= SB_I_CGROUPWB;
  850. if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV &&
  851. (EXT2_HAS_COMPAT_FEATURE(sb, ~0U) ||
  852. EXT2_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
  853. EXT2_HAS_INCOMPAT_FEATURE(sb, ~0U)))
  854. ext2_msg(sb, KERN_WARNING,
  855. "warning: feature flags set on rev 0 fs, "
  856. "running e2fsck is recommended");
  857. /*
  858. * Check feature flags regardless of the revision level, since we
  859. * previously didn't change the revision level when setting the flags,
  860. * so there is a chance incompat flags are set on a rev 0 filesystem.
  861. */
  862. features = EXT2_HAS_INCOMPAT_FEATURE(sb, ~EXT2_FEATURE_INCOMPAT_SUPP);
  863. if (features) {
  864. ext2_msg(sb, KERN_ERR, "error: couldn't mount because of "
  865. "unsupported optional features (%x)",
  866. le32_to_cpu(features));
  867. goto failed_mount;
  868. }
  869. if (!sb_rdonly(sb) && (features = EXT2_HAS_RO_COMPAT_FEATURE(sb, ~EXT2_FEATURE_RO_COMPAT_SUPP))){
  870. ext2_msg(sb, KERN_ERR, "error: couldn't mount RDWR because of "
  871. "unsupported optional features (%x)",
  872. le32_to_cpu(features));
  873. goto failed_mount;
  874. }
  875. blocksize = BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size);
  876. if (sbi->s_mount_opt & EXT2_MOUNT_DAX) {
  877. if (!bdev_dax_supported(sb->s_bdev, blocksize)) {
  878. ext2_msg(sb, KERN_ERR,
  879. "DAX unsupported by block device. Turning off DAX.");
  880. sbi->s_mount_opt &= ~EXT2_MOUNT_DAX;
  881. }
  882. }
  883. /* If the blocksize doesn't match, re-read the thing.. */
  884. if (sb->s_blocksize != blocksize) {
  885. brelse(bh);
  886. if (!sb_set_blocksize(sb, blocksize)) {
  887. ext2_msg(sb, KERN_ERR,
  888. "error: bad blocksize %d", blocksize);
  889. goto failed_sbi;
  890. }
  891. logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize;
  892. offset = (sb_block*BLOCK_SIZE) % blocksize;
  893. bh = sb_bread(sb, logic_sb_block);
  894. if(!bh) {
  895. ext2_msg(sb, KERN_ERR, "error: couldn't read"
  896. "superblock on 2nd try");
  897. goto failed_sbi;
  898. }
  899. es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
  900. sbi->s_es = es;
  901. if (es->s_magic != cpu_to_le16(EXT2_SUPER_MAGIC)) {
  902. ext2_msg(sb, KERN_ERR, "error: magic mismatch");
  903. goto failed_mount;
  904. }
  905. }
  906. sb->s_maxbytes = ext2_max_size(sb->s_blocksize_bits);
  907. sb->s_max_links = EXT2_LINK_MAX;
  908. if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV) {
  909. sbi->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE;
  910. sbi->s_first_ino = EXT2_GOOD_OLD_FIRST_INO;
  911. } else {
  912. sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
  913. sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
  914. if ((sbi->s_inode_size < EXT2_GOOD_OLD_INODE_SIZE) ||
  915. !is_power_of_2(sbi->s_inode_size) ||
  916. (sbi->s_inode_size > blocksize)) {
  917. ext2_msg(sb, KERN_ERR,
  918. "error: unsupported inode size: %d",
  919. sbi->s_inode_size);
  920. goto failed_mount;
  921. }
  922. }
  923. sbi->s_frag_size = EXT2_MIN_FRAG_SIZE <<
  924. le32_to_cpu(es->s_log_frag_size);
  925. if (sbi->s_frag_size == 0)
  926. goto cantfind_ext2;
  927. sbi->s_frags_per_block = sb->s_blocksize / sbi->s_frag_size;
  928. sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
  929. sbi->s_frags_per_group = le32_to_cpu(es->s_frags_per_group);
  930. sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
  931. if (EXT2_INODE_SIZE(sb) == 0)
  932. goto cantfind_ext2;
  933. sbi->s_inodes_per_block = sb->s_blocksize / EXT2_INODE_SIZE(sb);
  934. if (sbi->s_inodes_per_block == 0 || sbi->s_inodes_per_group == 0)
  935. goto cantfind_ext2;
  936. sbi->s_itb_per_group = sbi->s_inodes_per_group /
  937. sbi->s_inodes_per_block;
  938. sbi->s_desc_per_block = sb->s_blocksize /
  939. sizeof (struct ext2_group_desc);
  940. sbi->s_sbh = bh;
  941. sbi->s_mount_state = le16_to_cpu(es->s_state);
  942. sbi->s_addr_per_block_bits =
  943. ilog2 (EXT2_ADDR_PER_BLOCK(sb));
  944. sbi->s_desc_per_block_bits =
  945. ilog2 (EXT2_DESC_PER_BLOCK(sb));
  946. if (sb->s_magic != EXT2_SUPER_MAGIC)
  947. goto cantfind_ext2;
  948. if (sb->s_blocksize != bh->b_size) {
  949. if (!silent)
  950. ext2_msg(sb, KERN_ERR, "error: unsupported blocksize");
  951. goto failed_mount;
  952. }
  953. if (sb->s_blocksize != sbi->s_frag_size) {
  954. ext2_msg(sb, KERN_ERR,
  955. "error: fragsize %lu != blocksize %lu"
  956. "(not supported yet)",
  957. sbi->s_frag_size, sb->s_blocksize);
  958. goto failed_mount;
  959. }
  960. if (sbi->s_blocks_per_group > sb->s_blocksize * 8) {
  961. ext2_msg(sb, KERN_ERR,
  962. "error: #blocks per group too big: %lu",
  963. sbi->s_blocks_per_group);
  964. goto failed_mount;
  965. }
  966. if (sbi->s_frags_per_group > sb->s_blocksize * 8) {
  967. ext2_msg(sb, KERN_ERR,
  968. "error: #fragments per group too big: %lu",
  969. sbi->s_frags_per_group);
  970. goto failed_mount;
  971. }
  972. if (sbi->s_inodes_per_group > sb->s_blocksize * 8) {
  973. ext2_msg(sb, KERN_ERR,
  974. "error: #inodes per group too big: %lu",
  975. sbi->s_inodes_per_group);
  976. goto failed_mount;
  977. }
  978. if (EXT2_BLOCKS_PER_GROUP(sb) == 0)
  979. goto cantfind_ext2;
  980. sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) -
  981. le32_to_cpu(es->s_first_data_block) - 1)
  982. / EXT2_BLOCKS_PER_GROUP(sb)) + 1;
  983. db_count = (sbi->s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
  984. EXT2_DESC_PER_BLOCK(sb);
  985. sbi->s_group_desc = kmalloc_array (db_count,
  986. sizeof(struct buffer_head *),
  987. GFP_KERNEL);
  988. if (sbi->s_group_desc == NULL) {
  989. ext2_msg(sb, KERN_ERR, "error: not enough memory");
  990. goto failed_mount;
  991. }
  992. bgl_lock_init(sbi->s_blockgroup_lock);
  993. sbi->s_debts = kcalloc(sbi->s_groups_count, sizeof(*sbi->s_debts), GFP_KERNEL);
  994. if (!sbi->s_debts) {
  995. ext2_msg(sb, KERN_ERR, "error: not enough memory");
  996. goto failed_mount_group_desc;
  997. }
  998. for (i = 0; i < db_count; i++) {
  999. block = descriptor_loc(sb, logic_sb_block, i);
  1000. sbi->s_group_desc[i] = sb_bread(sb, block);
  1001. if (!sbi->s_group_desc[i]) {
  1002. for (j = 0; j < i; j++)
  1003. brelse (sbi->s_group_desc[j]);
  1004. ext2_msg(sb, KERN_ERR,
  1005. "error: unable to read group descriptors");
  1006. goto failed_mount_group_desc;
  1007. }
  1008. }
  1009. if (!ext2_check_descriptors (sb)) {
  1010. ext2_msg(sb, KERN_ERR, "group descriptors corrupted");
  1011. goto failed_mount2;
  1012. }
  1013. sbi->s_gdb_count = db_count;
  1014. get_random_bytes(&sbi->s_next_generation, sizeof(u32));
  1015. spin_lock_init(&sbi->s_next_gen_lock);
  1016. /* per fileystem reservation list head & lock */
  1017. spin_lock_init(&sbi->s_rsv_window_lock);
  1018. sbi->s_rsv_window_root = RB_ROOT;
  1019. /*
  1020. * Add a single, static dummy reservation to the start of the
  1021. * reservation window list --- it gives us a placeholder for
  1022. * append-at-start-of-list which makes the allocation logic
  1023. * _much_ simpler.
  1024. */
  1025. sbi->s_rsv_window_head.rsv_start = EXT2_RESERVE_WINDOW_NOT_ALLOCATED;
  1026. sbi->s_rsv_window_head.rsv_end = EXT2_RESERVE_WINDOW_NOT_ALLOCATED;
  1027. sbi->s_rsv_window_head.rsv_alloc_hit = 0;
  1028. sbi->s_rsv_window_head.rsv_goal_size = 0;
  1029. ext2_rsv_window_add(sb, &sbi->s_rsv_window_head);
  1030. err = percpu_counter_init(&sbi->s_freeblocks_counter,
  1031. ext2_count_free_blocks(sb), GFP_KERNEL);
  1032. if (!err) {
  1033. err = percpu_counter_init(&sbi->s_freeinodes_counter,
  1034. ext2_count_free_inodes(sb), GFP_KERNEL);
  1035. }
  1036. if (!err) {
  1037. err = percpu_counter_init(&sbi->s_dirs_counter,
  1038. ext2_count_dirs(sb), GFP_KERNEL);
  1039. }
  1040. if (err) {
  1041. ext2_msg(sb, KERN_ERR, "error: insufficient memory");
  1042. goto failed_mount3;
  1043. }
  1044. #ifdef CONFIG_EXT2_FS_XATTR
  1045. sbi->s_ea_block_cache = ext2_xattr_create_cache();
  1046. if (!sbi->s_ea_block_cache) {
  1047. ext2_msg(sb, KERN_ERR, "Failed to create ea_block_cache");
  1048. goto failed_mount3;
  1049. }
  1050. #endif
  1051. /*
  1052. * set up enough so that it can read an inode
  1053. */
  1054. sb->s_op = &ext2_sops;
  1055. sb->s_export_op = &ext2_export_ops;
  1056. sb->s_xattr = ext2_xattr_handlers;
  1057. #ifdef CONFIG_QUOTA
  1058. sb->dq_op = &dquot_operations;
  1059. sb->s_qcop = &ext2_quotactl_ops;
  1060. sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
  1061. #endif
  1062. root = ext2_iget(sb, EXT2_ROOT_INO);
  1063. if (IS_ERR(root)) {
  1064. ret = PTR_ERR(root);
  1065. goto failed_mount3;
  1066. }
  1067. if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
  1068. iput(root);
  1069. ext2_msg(sb, KERN_ERR, "error: corrupt root inode, run e2fsck");
  1070. goto failed_mount3;
  1071. }
  1072. sb->s_root = d_make_root(root);
  1073. if (!sb->s_root) {
  1074. ext2_msg(sb, KERN_ERR, "error: get root inode failed");
  1075. ret = -ENOMEM;
  1076. goto failed_mount3;
  1077. }
  1078. if (EXT2_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL))
  1079. ext2_msg(sb, KERN_WARNING,
  1080. "warning: mounting ext3 filesystem as ext2");
  1081. if (ext2_setup_super (sb, es, sb_rdonly(sb)))
  1082. sb->s_flags |= SB_RDONLY;
  1083. ext2_write_super(sb);
  1084. return 0;
  1085. cantfind_ext2:
  1086. if (!silent)
  1087. ext2_msg(sb, KERN_ERR,
  1088. "error: can't find an ext2 filesystem on dev %s.",
  1089. sb->s_id);
  1090. goto failed_mount;
  1091. failed_mount3:
  1092. if (sbi->s_ea_block_cache)
  1093. ext2_xattr_destroy_cache(sbi->s_ea_block_cache);
  1094. percpu_counter_destroy(&sbi->s_freeblocks_counter);
  1095. percpu_counter_destroy(&sbi->s_freeinodes_counter);
  1096. percpu_counter_destroy(&sbi->s_dirs_counter);
  1097. failed_mount2:
  1098. for (i = 0; i < db_count; i++)
  1099. brelse(sbi->s_group_desc[i]);
  1100. failed_mount_group_desc:
  1101. kfree(sbi->s_group_desc);
  1102. kfree(sbi->s_debts);
  1103. failed_mount:
  1104. brelse(bh);
  1105. failed_sbi:
  1106. sb->s_fs_info = NULL;
  1107. kfree(sbi->s_blockgroup_lock);
  1108. kfree(sbi);
  1109. failed:
  1110. fs_put_dax(dax_dev);
  1111. return ret;
  1112. }
  1113. static void ext2_clear_super_error(struct super_block *sb)
  1114. {
  1115. struct buffer_head *sbh = EXT2_SB(sb)->s_sbh;
  1116. if (buffer_write_io_error(sbh)) {
  1117. /*
  1118. * Oh, dear. A previous attempt to write the
  1119. * superblock failed. This could happen because the
  1120. * USB device was yanked out. Or it could happen to
  1121. * be a transient write error and maybe the block will
  1122. * be remapped. Nothing we can do but to retry the
  1123. * write and hope for the best.
  1124. */
  1125. ext2_msg(sb, KERN_ERR,
  1126. "previous I/O error to superblock detected");
  1127. clear_buffer_write_io_error(sbh);
  1128. set_buffer_uptodate(sbh);
  1129. }
  1130. }
  1131. void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es,
  1132. int wait)
  1133. {
  1134. ext2_clear_super_error(sb);
  1135. spin_lock(&EXT2_SB(sb)->s_lock);
  1136. es->s_free_blocks_count = cpu_to_le32(ext2_count_free_blocks(sb));
  1137. es->s_free_inodes_count = cpu_to_le32(ext2_count_free_inodes(sb));
  1138. es->s_wtime = cpu_to_le32(ktime_get_real_seconds());
  1139. /* unlock before we do IO */
  1140. spin_unlock(&EXT2_SB(sb)->s_lock);
  1141. mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
  1142. if (wait)
  1143. sync_dirty_buffer(EXT2_SB(sb)->s_sbh);
  1144. }
  1145. /*
  1146. * In the second extended file system, it is not necessary to
  1147. * write the super block since we use a mapping of the
  1148. * disk super block in a buffer.
  1149. *
  1150. * However, this function is still used to set the fs valid
  1151. * flags to 0. We need to set this flag to 0 since the fs
  1152. * may have been checked while mounted and e2fsck may have
  1153. * set s_state to EXT2_VALID_FS after some corrections.
  1154. */
  1155. static int ext2_sync_fs(struct super_block *sb, int wait)
  1156. {
  1157. struct ext2_sb_info *sbi = EXT2_SB(sb);
  1158. struct ext2_super_block *es = EXT2_SB(sb)->s_es;
  1159. /*
  1160. * Write quota structures to quota file, sync_blockdev() will write
  1161. * them to disk later
  1162. */
  1163. dquot_writeback_dquots(sb, -1);
  1164. spin_lock(&sbi->s_lock);
  1165. if (es->s_state & cpu_to_le16(EXT2_VALID_FS)) {
  1166. ext2_debug("setting valid to 0\n");
  1167. es->s_state &= cpu_to_le16(~EXT2_VALID_FS);
  1168. }
  1169. spin_unlock(&sbi->s_lock);
  1170. ext2_sync_super(sb, es, wait);
  1171. return 0;
  1172. }
  1173. static int ext2_freeze(struct super_block *sb)
  1174. {
  1175. struct ext2_sb_info *sbi = EXT2_SB(sb);
  1176. /*
  1177. * Open but unlinked files present? Keep EXT2_VALID_FS flag cleared
  1178. * because we have unattached inodes and thus filesystem is not fully
  1179. * consistent.
  1180. */
  1181. if (atomic_long_read(&sb->s_remove_count)) {
  1182. ext2_sync_fs(sb, 1);
  1183. return 0;
  1184. }
  1185. /* Set EXT2_FS_VALID flag */
  1186. spin_lock(&sbi->s_lock);
  1187. sbi->s_es->s_state = cpu_to_le16(sbi->s_mount_state);
  1188. spin_unlock(&sbi->s_lock);
  1189. ext2_sync_super(sb, sbi->s_es, 1);
  1190. return 0;
  1191. }
  1192. static int ext2_unfreeze(struct super_block *sb)
  1193. {
  1194. /* Just write sb to clear EXT2_VALID_FS flag */
  1195. ext2_write_super(sb);
  1196. return 0;
  1197. }
  1198. static void ext2_write_super(struct super_block *sb)
  1199. {
  1200. if (!sb_rdonly(sb))
  1201. ext2_sync_fs(sb, 1);
  1202. }
  1203. static int ext2_remount (struct super_block * sb, int * flags, char * data)
  1204. {
  1205. struct ext2_sb_info * sbi = EXT2_SB(sb);
  1206. struct ext2_super_block * es;
  1207. struct ext2_mount_options new_opts;
  1208. int err;
  1209. sync_filesystem(sb);
  1210. spin_lock(&sbi->s_lock);
  1211. new_opts.s_mount_opt = sbi->s_mount_opt;
  1212. new_opts.s_resuid = sbi->s_resuid;
  1213. new_opts.s_resgid = sbi->s_resgid;
  1214. spin_unlock(&sbi->s_lock);
  1215. if (!parse_options(data, sb, &new_opts))
  1216. return -EINVAL;
  1217. spin_lock(&sbi->s_lock);
  1218. es = sbi->s_es;
  1219. if ((sbi->s_mount_opt ^ new_opts.s_mount_opt) & EXT2_MOUNT_DAX) {
  1220. ext2_msg(sb, KERN_WARNING, "warning: refusing change of "
  1221. "dax flag with busy inodes while remounting");
  1222. new_opts.s_mount_opt ^= EXT2_MOUNT_DAX;
  1223. }
  1224. if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
  1225. goto out_set;
  1226. if (*flags & SB_RDONLY) {
  1227. if (le16_to_cpu(es->s_state) & EXT2_VALID_FS ||
  1228. !(sbi->s_mount_state & EXT2_VALID_FS))
  1229. goto out_set;
  1230. /*
  1231. * OK, we are remounting a valid rw partition rdonly, so set
  1232. * the rdonly flag and then mark the partition as valid again.
  1233. */
  1234. es->s_state = cpu_to_le16(sbi->s_mount_state);
  1235. es->s_mtime = cpu_to_le32(ktime_get_real_seconds());
  1236. spin_unlock(&sbi->s_lock);
  1237. err = dquot_suspend(sb, -1);
  1238. if (err < 0)
  1239. return err;
  1240. ext2_sync_super(sb, es, 1);
  1241. } else {
  1242. __le32 ret = EXT2_HAS_RO_COMPAT_FEATURE(sb,
  1243. ~EXT2_FEATURE_RO_COMPAT_SUPP);
  1244. if (ret) {
  1245. spin_unlock(&sbi->s_lock);
  1246. ext2_msg(sb, KERN_WARNING,
  1247. "warning: couldn't remount RDWR because of "
  1248. "unsupported optional features (%x).",
  1249. le32_to_cpu(ret));
  1250. return -EROFS;
  1251. }
  1252. /*
  1253. * Mounting a RDONLY partition read-write, so reread and
  1254. * store the current valid flag. (It may have been changed
  1255. * by e2fsck since we originally mounted the partition.)
  1256. */
  1257. sbi->s_mount_state = le16_to_cpu(es->s_state);
  1258. if (!ext2_setup_super (sb, es, 0))
  1259. sb->s_flags &= ~SB_RDONLY;
  1260. spin_unlock(&sbi->s_lock);
  1261. ext2_write_super(sb);
  1262. dquot_resume(sb, -1);
  1263. }
  1264. spin_lock(&sbi->s_lock);
  1265. out_set:
  1266. sbi->s_mount_opt = new_opts.s_mount_opt;
  1267. sbi->s_resuid = new_opts.s_resuid;
  1268. sbi->s_resgid = new_opts.s_resgid;
  1269. sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
  1270. ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? SB_POSIXACL : 0);
  1271. spin_unlock(&sbi->s_lock);
  1272. return 0;
  1273. }
  1274. static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf)
  1275. {
  1276. struct super_block *sb = dentry->d_sb;
  1277. struct ext2_sb_info *sbi = EXT2_SB(sb);
  1278. struct ext2_super_block *es = sbi->s_es;
  1279. u64 fsid;
  1280. spin_lock(&sbi->s_lock);
  1281. if (test_opt (sb, MINIX_DF))
  1282. sbi->s_overhead_last = 0;
  1283. else if (sbi->s_blocks_last != le32_to_cpu(es->s_blocks_count)) {
  1284. unsigned long i, overhead = 0;
  1285. smp_rmb();
  1286. /*
  1287. * Compute the overhead (FS structures). This is constant
  1288. * for a given filesystem unless the number of block groups
  1289. * changes so we cache the previous value until it does.
  1290. */
  1291. /*
  1292. * All of the blocks before first_data_block are
  1293. * overhead
  1294. */
  1295. overhead = le32_to_cpu(es->s_first_data_block);
  1296. /*
  1297. * Add the overhead attributed to the superblock and
  1298. * block group descriptors. If the sparse superblocks
  1299. * feature is turned on, then not all groups have this.
  1300. */
  1301. for (i = 0; i < sbi->s_groups_count; i++)
  1302. overhead += ext2_bg_has_super(sb, i) +
  1303. ext2_bg_num_gdb(sb, i);
  1304. /*
  1305. * Every block group has an inode bitmap, a block
  1306. * bitmap, and an inode table.
  1307. */
  1308. overhead += (sbi->s_groups_count *
  1309. (2 + sbi->s_itb_per_group));
  1310. sbi->s_overhead_last = overhead;
  1311. smp_wmb();
  1312. sbi->s_blocks_last = le32_to_cpu(es->s_blocks_count);
  1313. }
  1314. buf->f_type = EXT2_SUPER_MAGIC;
  1315. buf->f_bsize = sb->s_blocksize;
  1316. buf->f_blocks = le32_to_cpu(es->s_blocks_count) - sbi->s_overhead_last;
  1317. buf->f_bfree = ext2_count_free_blocks(sb);
  1318. es->s_free_blocks_count = cpu_to_le32(buf->f_bfree);
  1319. buf->f_bavail = buf->f_bfree - le32_to_cpu(es->s_r_blocks_count);
  1320. if (buf->f_bfree < le32_to_cpu(es->s_r_blocks_count))
  1321. buf->f_bavail = 0;
  1322. buf->f_files = le32_to_cpu(es->s_inodes_count);
  1323. buf->f_ffree = ext2_count_free_inodes(sb);
  1324. es->s_free_inodes_count = cpu_to_le32(buf->f_ffree);
  1325. buf->f_namelen = EXT2_NAME_LEN;
  1326. fsid = le64_to_cpup((void *)es->s_uuid) ^
  1327. le64_to_cpup((void *)es->s_uuid + sizeof(u64));
  1328. buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL;
  1329. buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL;
  1330. spin_unlock(&sbi->s_lock);
  1331. return 0;
  1332. }
  1333. static struct dentry *ext2_mount(struct file_system_type *fs_type,
  1334. int flags, const char *dev_name, void *data)
  1335. {
  1336. return mount_bdev(fs_type, flags, dev_name, data, ext2_fill_super);
  1337. }
  1338. #ifdef CONFIG_QUOTA
  1339. /* Read data from quotafile - avoid pagecache and such because we cannot afford
  1340. * acquiring the locks... As quota files are never truncated and quota code
  1341. * itself serializes the operations (and no one else should touch the files)
  1342. * we don't have to be afraid of races */
  1343. static ssize_t ext2_quota_read(struct super_block *sb, int type, char *data,
  1344. size_t len, loff_t off)
  1345. {
  1346. struct inode *inode = sb_dqopt(sb)->files[type];
  1347. sector_t blk = off >> EXT2_BLOCK_SIZE_BITS(sb);
  1348. int err = 0;
  1349. int offset = off & (sb->s_blocksize - 1);
  1350. int tocopy;
  1351. size_t toread;
  1352. struct buffer_head tmp_bh;
  1353. struct buffer_head *bh;
  1354. loff_t i_size = i_size_read(inode);
  1355. if (off > i_size)
  1356. return 0;
  1357. if (off+len > i_size)
  1358. len = i_size-off;
  1359. toread = len;
  1360. while (toread > 0) {
  1361. tocopy = sb->s_blocksize - offset < toread ?
  1362. sb->s_blocksize - offset : toread;
  1363. tmp_bh.b_state = 0;
  1364. tmp_bh.b_size = sb->s_blocksize;
  1365. err = ext2_get_block(inode, blk, &tmp_bh, 0);
  1366. if (err < 0)
  1367. return err;
  1368. if (!buffer_mapped(&tmp_bh)) /* A hole? */
  1369. memset(data, 0, tocopy);
  1370. else {
  1371. bh = sb_bread(sb, tmp_bh.b_blocknr);
  1372. if (!bh)
  1373. return -EIO;
  1374. memcpy(data, bh->b_data+offset, tocopy);
  1375. brelse(bh);
  1376. }
  1377. offset = 0;
  1378. toread -= tocopy;
  1379. data += tocopy;
  1380. blk++;
  1381. }
  1382. return len;
  1383. }
  1384. /* Write to quotafile */
  1385. static ssize_t ext2_quota_write(struct super_block *sb, int type,
  1386. const char *data, size_t len, loff_t off)
  1387. {
  1388. struct inode *inode = sb_dqopt(sb)->files[type];
  1389. sector_t blk = off >> EXT2_BLOCK_SIZE_BITS(sb);
  1390. int err = 0;
  1391. int offset = off & (sb->s_blocksize - 1);
  1392. int tocopy;
  1393. size_t towrite = len;
  1394. struct buffer_head tmp_bh;
  1395. struct buffer_head *bh;
  1396. while (towrite > 0) {
  1397. tocopy = sb->s_blocksize - offset < towrite ?
  1398. sb->s_blocksize - offset : towrite;
  1399. tmp_bh.b_state = 0;
  1400. tmp_bh.b_size = sb->s_blocksize;
  1401. err = ext2_get_block(inode, blk, &tmp_bh, 1);
  1402. if (err < 0)
  1403. goto out;
  1404. if (offset || tocopy != EXT2_BLOCK_SIZE(sb))
  1405. bh = sb_bread(sb, tmp_bh.b_blocknr);
  1406. else
  1407. bh = sb_getblk(sb, tmp_bh.b_blocknr);
  1408. if (unlikely(!bh)) {
  1409. err = -EIO;
  1410. goto out;
  1411. }
  1412. lock_buffer(bh);
  1413. memcpy(bh->b_data+offset, data, tocopy);
  1414. flush_dcache_page(bh->b_page);
  1415. set_buffer_uptodate(bh);
  1416. mark_buffer_dirty(bh);
  1417. unlock_buffer(bh);
  1418. brelse(bh);
  1419. offset = 0;
  1420. towrite -= tocopy;
  1421. data += tocopy;
  1422. blk++;
  1423. }
  1424. out:
  1425. if (len == towrite)
  1426. return err;
  1427. if (inode->i_size < off+len-towrite)
  1428. i_size_write(inode, off+len-towrite);
  1429. inode_inc_iversion(inode);
  1430. inode->i_mtime = inode->i_ctime = current_time(inode);
  1431. mark_inode_dirty(inode);
  1432. return len - towrite;
  1433. }
  1434. static int ext2_quota_on(struct super_block *sb, int type, int format_id,
  1435. const struct path *path)
  1436. {
  1437. int err;
  1438. struct inode *inode;
  1439. err = dquot_quota_on(sb, type, format_id, path);
  1440. if (err)
  1441. return err;
  1442. inode = d_inode(path->dentry);
  1443. inode_lock(inode);
  1444. EXT2_I(inode)->i_flags |= EXT2_NOATIME_FL | EXT2_IMMUTABLE_FL;
  1445. inode_set_flags(inode, S_NOATIME | S_IMMUTABLE,
  1446. S_NOATIME | S_IMMUTABLE);
  1447. inode_unlock(inode);
  1448. mark_inode_dirty(inode);
  1449. return 0;
  1450. }
  1451. static int ext2_quota_off(struct super_block *sb, int type)
  1452. {
  1453. struct inode *inode = sb_dqopt(sb)->files[type];
  1454. int err;
  1455. if (!inode || !igrab(inode))
  1456. goto out;
  1457. err = dquot_quota_off(sb, type);
  1458. if (err)
  1459. goto out_put;
  1460. inode_lock(inode);
  1461. EXT2_I(inode)->i_flags &= ~(EXT2_NOATIME_FL | EXT2_IMMUTABLE_FL);
  1462. inode_set_flags(inode, 0, S_NOATIME | S_IMMUTABLE);
  1463. inode_unlock(inode);
  1464. mark_inode_dirty(inode);
  1465. out_put:
  1466. iput(inode);
  1467. return err;
  1468. out:
  1469. return dquot_quota_off(sb, type);
  1470. }
  1471. #endif
  1472. static struct file_system_type ext2_fs_type = {
  1473. .owner = THIS_MODULE,
  1474. .name = "ext2",
  1475. .mount = ext2_mount,
  1476. .kill_sb = kill_block_super,
  1477. .fs_flags = FS_REQUIRES_DEV,
  1478. };
  1479. MODULE_ALIAS_FS("ext2");
  1480. static int __init init_ext2_fs(void)
  1481. {
  1482. int err;
  1483. err = init_inodecache();
  1484. if (err)
  1485. return err;
  1486. err = register_filesystem(&ext2_fs_type);
  1487. if (err)
  1488. goto out;
  1489. return 0;
  1490. out:
  1491. destroy_inodecache();
  1492. return err;
  1493. }
  1494. static void __exit exit_ext2_fs(void)
  1495. {
  1496. unregister_filesystem(&ext2_fs_type);
  1497. destroy_inodecache();
  1498. }
  1499. MODULE_AUTHOR("Remy Card and others");
  1500. MODULE_DESCRIPTION("Second Extended Filesystem");
  1501. MODULE_LICENSE("GPL");
  1502. module_init(init_ext2_fs)
  1503. module_exit(exit_ext2_fs)