super.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667
  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 = -ENOMEM;
  742. int blocksize = BLOCK_SIZE;
  743. int db_count;
  744. int i, j;
  745. __le32 features;
  746. int err;
  747. struct ext2_mount_options opts;
  748. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  749. if (!sbi)
  750. goto failed;
  751. sbi->s_blockgroup_lock =
  752. kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
  753. if (!sbi->s_blockgroup_lock) {
  754. kfree(sbi);
  755. goto failed;
  756. }
  757. sb->s_fs_info = sbi;
  758. sbi->s_sb_block = sb_block;
  759. sbi->s_daxdev = dax_dev;
  760. spin_lock_init(&sbi->s_lock);
  761. ret = -EINVAL;
  762. /*
  763. * See what the current blocksize for the device is, and
  764. * use that as the blocksize. Otherwise (or if the blocksize
  765. * is smaller than the default) use the default.
  766. * This is important for devices that have a hardware
  767. * sectorsize that is larger than the default.
  768. */
  769. blocksize = sb_min_blocksize(sb, BLOCK_SIZE);
  770. if (!blocksize) {
  771. ext2_msg(sb, KERN_ERR, "error: unable to set blocksize");
  772. goto failed_sbi;
  773. }
  774. /*
  775. * If the superblock doesn't start on a hardware sector boundary,
  776. * calculate the offset.
  777. */
  778. if (blocksize != BLOCK_SIZE) {
  779. logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize;
  780. offset = (sb_block*BLOCK_SIZE) % blocksize;
  781. } else {
  782. logic_sb_block = sb_block;
  783. }
  784. if (!(bh = sb_bread(sb, logic_sb_block))) {
  785. ext2_msg(sb, KERN_ERR, "error: unable to read superblock");
  786. goto failed_sbi;
  787. }
  788. /*
  789. * Note: s_es must be initialized as soon as possible because
  790. * some ext2 macro-instructions depend on its value
  791. */
  792. es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
  793. sbi->s_es = es;
  794. sb->s_magic = le16_to_cpu(es->s_magic);
  795. if (sb->s_magic != EXT2_SUPER_MAGIC)
  796. goto cantfind_ext2;
  797. /* 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. if (!bdev_dax_supported(sb->s_bdev, blocksize)) {
  859. ext2_msg(sb, KERN_ERR,
  860. "DAX unsupported by block device. Turning off DAX.");
  861. sbi->s_mount_opt &= ~EXT2_MOUNT_DAX;
  862. }
  863. }
  864. /* If the blocksize doesn't match, re-read the thing.. */
  865. if (sb->s_blocksize != blocksize) {
  866. brelse(bh);
  867. if (!sb_set_blocksize(sb, blocksize)) {
  868. ext2_msg(sb, KERN_ERR,
  869. "error: bad blocksize %d", blocksize);
  870. goto failed_sbi;
  871. }
  872. logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize;
  873. offset = (sb_block*BLOCK_SIZE) % blocksize;
  874. bh = sb_bread(sb, logic_sb_block);
  875. if(!bh) {
  876. ext2_msg(sb, KERN_ERR, "error: couldn't read"
  877. "superblock on 2nd try");
  878. goto failed_sbi;
  879. }
  880. es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
  881. sbi->s_es = es;
  882. if (es->s_magic != cpu_to_le16(EXT2_SUPER_MAGIC)) {
  883. ext2_msg(sb, KERN_ERR, "error: magic mismatch");
  884. goto failed_mount;
  885. }
  886. }
  887. sb->s_maxbytes = ext2_max_size(sb->s_blocksize_bits);
  888. sb->s_max_links = EXT2_LINK_MAX;
  889. if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV) {
  890. sbi->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE;
  891. sbi->s_first_ino = EXT2_GOOD_OLD_FIRST_INO;
  892. } else {
  893. sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
  894. sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
  895. if ((sbi->s_inode_size < EXT2_GOOD_OLD_INODE_SIZE) ||
  896. !is_power_of_2(sbi->s_inode_size) ||
  897. (sbi->s_inode_size > blocksize)) {
  898. ext2_msg(sb, KERN_ERR,
  899. "error: unsupported inode size: %d",
  900. sbi->s_inode_size);
  901. goto failed_mount;
  902. }
  903. }
  904. sbi->s_frag_size = EXT2_MIN_FRAG_SIZE <<
  905. le32_to_cpu(es->s_log_frag_size);
  906. if (sbi->s_frag_size == 0)
  907. goto cantfind_ext2;
  908. sbi->s_frags_per_block = sb->s_blocksize / sbi->s_frag_size;
  909. sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
  910. sbi->s_frags_per_group = le32_to_cpu(es->s_frags_per_group);
  911. sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
  912. if (EXT2_INODE_SIZE(sb) == 0)
  913. goto cantfind_ext2;
  914. sbi->s_inodes_per_block = sb->s_blocksize / EXT2_INODE_SIZE(sb);
  915. if (sbi->s_inodes_per_block == 0 || sbi->s_inodes_per_group == 0)
  916. goto cantfind_ext2;
  917. sbi->s_itb_per_group = sbi->s_inodes_per_group /
  918. sbi->s_inodes_per_block;
  919. sbi->s_desc_per_block = sb->s_blocksize /
  920. sizeof (struct ext2_group_desc);
  921. sbi->s_sbh = bh;
  922. sbi->s_mount_state = le16_to_cpu(es->s_state);
  923. sbi->s_addr_per_block_bits =
  924. ilog2 (EXT2_ADDR_PER_BLOCK(sb));
  925. sbi->s_desc_per_block_bits =
  926. ilog2 (EXT2_DESC_PER_BLOCK(sb));
  927. if (sb->s_magic != EXT2_SUPER_MAGIC)
  928. goto cantfind_ext2;
  929. if (sb->s_blocksize != bh->b_size) {
  930. if (!silent)
  931. ext2_msg(sb, KERN_ERR, "error: unsupported blocksize");
  932. goto failed_mount;
  933. }
  934. if (sb->s_blocksize != sbi->s_frag_size) {
  935. ext2_msg(sb, KERN_ERR,
  936. "error: fragsize %lu != blocksize %lu"
  937. "(not supported yet)",
  938. sbi->s_frag_size, sb->s_blocksize);
  939. goto failed_mount;
  940. }
  941. if (sbi->s_blocks_per_group > sb->s_blocksize * 8) {
  942. ext2_msg(sb, KERN_ERR,
  943. "error: #blocks per group too big: %lu",
  944. sbi->s_blocks_per_group);
  945. goto failed_mount;
  946. }
  947. if (sbi->s_frags_per_group > sb->s_blocksize * 8) {
  948. ext2_msg(sb, KERN_ERR,
  949. "error: #fragments per group too big: %lu",
  950. sbi->s_frags_per_group);
  951. goto failed_mount;
  952. }
  953. if (sbi->s_inodes_per_group > sb->s_blocksize * 8) {
  954. ext2_msg(sb, KERN_ERR,
  955. "error: #inodes per group too big: %lu",
  956. sbi->s_inodes_per_group);
  957. goto failed_mount;
  958. }
  959. if (EXT2_BLOCKS_PER_GROUP(sb) == 0)
  960. goto cantfind_ext2;
  961. sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) -
  962. le32_to_cpu(es->s_first_data_block) - 1)
  963. / EXT2_BLOCKS_PER_GROUP(sb)) + 1;
  964. db_count = (sbi->s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
  965. EXT2_DESC_PER_BLOCK(sb);
  966. sbi->s_group_desc = kmalloc_array (db_count,
  967. sizeof(struct buffer_head *),
  968. GFP_KERNEL);
  969. if (sbi->s_group_desc == NULL) {
  970. ext2_msg(sb, KERN_ERR, "error: not enough memory");
  971. goto failed_mount;
  972. }
  973. bgl_lock_init(sbi->s_blockgroup_lock);
  974. sbi->s_debts = kcalloc(sbi->s_groups_count, sizeof(*sbi->s_debts), GFP_KERNEL);
  975. if (!sbi->s_debts) {
  976. ext2_msg(sb, KERN_ERR, "error: not enough memory");
  977. goto failed_mount_group_desc;
  978. }
  979. for (i = 0; i < db_count; i++) {
  980. block = descriptor_loc(sb, logic_sb_block, i);
  981. sbi->s_group_desc[i] = sb_bread(sb, block);
  982. if (!sbi->s_group_desc[i]) {
  983. for (j = 0; j < i; j++)
  984. brelse (sbi->s_group_desc[j]);
  985. ext2_msg(sb, KERN_ERR,
  986. "error: unable to read group descriptors");
  987. goto failed_mount_group_desc;
  988. }
  989. }
  990. if (!ext2_check_descriptors (sb)) {
  991. ext2_msg(sb, KERN_ERR, "group descriptors corrupted");
  992. goto failed_mount2;
  993. }
  994. sbi->s_gdb_count = db_count;
  995. get_random_bytes(&sbi->s_next_generation, sizeof(u32));
  996. spin_lock_init(&sbi->s_next_gen_lock);
  997. /* per fileystem reservation list head & lock */
  998. spin_lock_init(&sbi->s_rsv_window_lock);
  999. sbi->s_rsv_window_root = RB_ROOT;
  1000. /*
  1001. * Add a single, static dummy reservation to the start of the
  1002. * reservation window list --- it gives us a placeholder for
  1003. * append-at-start-of-list which makes the allocation logic
  1004. * _much_ simpler.
  1005. */
  1006. sbi->s_rsv_window_head.rsv_start = EXT2_RESERVE_WINDOW_NOT_ALLOCATED;
  1007. sbi->s_rsv_window_head.rsv_end = EXT2_RESERVE_WINDOW_NOT_ALLOCATED;
  1008. sbi->s_rsv_window_head.rsv_alloc_hit = 0;
  1009. sbi->s_rsv_window_head.rsv_goal_size = 0;
  1010. ext2_rsv_window_add(sb, &sbi->s_rsv_window_head);
  1011. err = percpu_counter_init(&sbi->s_freeblocks_counter,
  1012. ext2_count_free_blocks(sb), GFP_KERNEL);
  1013. if (!err) {
  1014. err = percpu_counter_init(&sbi->s_freeinodes_counter,
  1015. ext2_count_free_inodes(sb), GFP_KERNEL);
  1016. }
  1017. if (!err) {
  1018. err = percpu_counter_init(&sbi->s_dirs_counter,
  1019. ext2_count_dirs(sb), GFP_KERNEL);
  1020. }
  1021. if (err) {
  1022. ext2_msg(sb, KERN_ERR, "error: insufficient memory");
  1023. goto failed_mount3;
  1024. }
  1025. #ifdef CONFIG_EXT2_FS_XATTR
  1026. sbi->s_ea_block_cache = ext2_xattr_create_cache();
  1027. if (!sbi->s_ea_block_cache) {
  1028. ext2_msg(sb, KERN_ERR, "Failed to create ea_block_cache");
  1029. goto failed_mount3;
  1030. }
  1031. #endif
  1032. /*
  1033. * set up enough so that it can read an inode
  1034. */
  1035. sb->s_op = &ext2_sops;
  1036. sb->s_export_op = &ext2_export_ops;
  1037. sb->s_xattr = ext2_xattr_handlers;
  1038. #ifdef CONFIG_QUOTA
  1039. sb->dq_op = &dquot_operations;
  1040. sb->s_qcop = &ext2_quotactl_ops;
  1041. sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
  1042. #endif
  1043. root = ext2_iget(sb, EXT2_ROOT_INO);
  1044. if (IS_ERR(root)) {
  1045. ret = PTR_ERR(root);
  1046. goto failed_mount3;
  1047. }
  1048. if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
  1049. iput(root);
  1050. ext2_msg(sb, KERN_ERR, "error: corrupt root inode, run e2fsck");
  1051. goto failed_mount3;
  1052. }
  1053. sb->s_root = d_make_root(root);
  1054. if (!sb->s_root) {
  1055. ext2_msg(sb, KERN_ERR, "error: get root inode failed");
  1056. ret = -ENOMEM;
  1057. goto failed_mount3;
  1058. }
  1059. if (EXT2_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL))
  1060. ext2_msg(sb, KERN_WARNING,
  1061. "warning: mounting ext3 filesystem as ext2");
  1062. if (ext2_setup_super (sb, es, sb_rdonly(sb)))
  1063. sb->s_flags |= SB_RDONLY;
  1064. ext2_write_super(sb);
  1065. return 0;
  1066. cantfind_ext2:
  1067. if (!silent)
  1068. ext2_msg(sb, KERN_ERR,
  1069. "error: can't find an ext2 filesystem on dev %s.",
  1070. sb->s_id);
  1071. goto failed_mount;
  1072. failed_mount3:
  1073. if (sbi->s_ea_block_cache)
  1074. ext2_xattr_destroy_cache(sbi->s_ea_block_cache);
  1075. percpu_counter_destroy(&sbi->s_freeblocks_counter);
  1076. percpu_counter_destroy(&sbi->s_freeinodes_counter);
  1077. percpu_counter_destroy(&sbi->s_dirs_counter);
  1078. failed_mount2:
  1079. for (i = 0; i < db_count; i++)
  1080. brelse(sbi->s_group_desc[i]);
  1081. failed_mount_group_desc:
  1082. kfree(sbi->s_group_desc);
  1083. kfree(sbi->s_debts);
  1084. failed_mount:
  1085. brelse(bh);
  1086. failed_sbi:
  1087. sb->s_fs_info = NULL;
  1088. kfree(sbi->s_blockgroup_lock);
  1089. kfree(sbi);
  1090. failed:
  1091. fs_put_dax(dax_dev);
  1092. return ret;
  1093. }
  1094. static void ext2_clear_super_error(struct super_block *sb)
  1095. {
  1096. struct buffer_head *sbh = EXT2_SB(sb)->s_sbh;
  1097. if (buffer_write_io_error(sbh)) {
  1098. /*
  1099. * Oh, dear. A previous attempt to write the
  1100. * superblock failed. This could happen because the
  1101. * USB device was yanked out. Or it could happen to
  1102. * be a transient write error and maybe the block will
  1103. * be remapped. Nothing we can do but to retry the
  1104. * write and hope for the best.
  1105. */
  1106. ext2_msg(sb, KERN_ERR,
  1107. "previous I/O error to superblock detected");
  1108. clear_buffer_write_io_error(sbh);
  1109. set_buffer_uptodate(sbh);
  1110. }
  1111. }
  1112. void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es,
  1113. int wait)
  1114. {
  1115. ext2_clear_super_error(sb);
  1116. spin_lock(&EXT2_SB(sb)->s_lock);
  1117. es->s_free_blocks_count = cpu_to_le32(ext2_count_free_blocks(sb));
  1118. es->s_free_inodes_count = cpu_to_le32(ext2_count_free_inodes(sb));
  1119. es->s_wtime = cpu_to_le32(get_seconds());
  1120. /* unlock before we do IO */
  1121. spin_unlock(&EXT2_SB(sb)->s_lock);
  1122. mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
  1123. if (wait)
  1124. sync_dirty_buffer(EXT2_SB(sb)->s_sbh);
  1125. }
  1126. /*
  1127. * In the second extended file system, it is not necessary to
  1128. * write the super block since we use a mapping of the
  1129. * disk super block in a buffer.
  1130. *
  1131. * However, this function is still used to set the fs valid
  1132. * flags to 0. We need to set this flag to 0 since the fs
  1133. * may have been checked while mounted and e2fsck may have
  1134. * set s_state to EXT2_VALID_FS after some corrections.
  1135. */
  1136. static int ext2_sync_fs(struct super_block *sb, int wait)
  1137. {
  1138. struct ext2_sb_info *sbi = EXT2_SB(sb);
  1139. struct ext2_super_block *es = EXT2_SB(sb)->s_es;
  1140. /*
  1141. * Write quota structures to quota file, sync_blockdev() will write
  1142. * them to disk later
  1143. */
  1144. dquot_writeback_dquots(sb, -1);
  1145. spin_lock(&sbi->s_lock);
  1146. if (es->s_state & cpu_to_le16(EXT2_VALID_FS)) {
  1147. ext2_debug("setting valid to 0\n");
  1148. es->s_state &= cpu_to_le16(~EXT2_VALID_FS);
  1149. }
  1150. spin_unlock(&sbi->s_lock);
  1151. ext2_sync_super(sb, es, wait);
  1152. return 0;
  1153. }
  1154. static int ext2_freeze(struct super_block *sb)
  1155. {
  1156. struct ext2_sb_info *sbi = EXT2_SB(sb);
  1157. /*
  1158. * Open but unlinked files present? Keep EXT2_VALID_FS flag cleared
  1159. * because we have unattached inodes and thus filesystem is not fully
  1160. * consistent.
  1161. */
  1162. if (atomic_long_read(&sb->s_remove_count)) {
  1163. ext2_sync_fs(sb, 1);
  1164. return 0;
  1165. }
  1166. /* Set EXT2_FS_VALID flag */
  1167. spin_lock(&sbi->s_lock);
  1168. sbi->s_es->s_state = cpu_to_le16(sbi->s_mount_state);
  1169. spin_unlock(&sbi->s_lock);
  1170. ext2_sync_super(sb, sbi->s_es, 1);
  1171. return 0;
  1172. }
  1173. static int ext2_unfreeze(struct super_block *sb)
  1174. {
  1175. /* Just write sb to clear EXT2_VALID_FS flag */
  1176. ext2_write_super(sb);
  1177. return 0;
  1178. }
  1179. static void ext2_write_super(struct super_block *sb)
  1180. {
  1181. if (!sb_rdonly(sb))
  1182. ext2_sync_fs(sb, 1);
  1183. }
  1184. static int ext2_remount (struct super_block * sb, int * flags, char * data)
  1185. {
  1186. struct ext2_sb_info * sbi = EXT2_SB(sb);
  1187. struct ext2_super_block * es;
  1188. struct ext2_mount_options new_opts;
  1189. int err;
  1190. sync_filesystem(sb);
  1191. spin_lock(&sbi->s_lock);
  1192. new_opts.s_mount_opt = sbi->s_mount_opt;
  1193. new_opts.s_resuid = sbi->s_resuid;
  1194. new_opts.s_resgid = sbi->s_resgid;
  1195. spin_unlock(&sbi->s_lock);
  1196. /*
  1197. * Allow the "check" option to be passed as a remount option.
  1198. */
  1199. if (!parse_options(data, sb, &new_opts))
  1200. return -EINVAL;
  1201. spin_lock(&sbi->s_lock);
  1202. es = sbi->s_es;
  1203. if ((sbi->s_mount_opt ^ new_opts.s_mount_opt) & EXT2_MOUNT_DAX) {
  1204. ext2_msg(sb, KERN_WARNING, "warning: refusing change of "
  1205. "dax flag with busy inodes while remounting");
  1206. new_opts.s_mount_opt ^= EXT2_MOUNT_DAX;
  1207. }
  1208. if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
  1209. goto out_set;
  1210. if (*flags & SB_RDONLY) {
  1211. if (le16_to_cpu(es->s_state) & EXT2_VALID_FS ||
  1212. !(sbi->s_mount_state & EXT2_VALID_FS))
  1213. goto out_set;
  1214. /*
  1215. * OK, we are remounting a valid rw partition rdonly, so set
  1216. * the rdonly flag and then mark the partition as valid again.
  1217. */
  1218. es->s_state = cpu_to_le16(sbi->s_mount_state);
  1219. es->s_mtime = cpu_to_le32(get_seconds());
  1220. spin_unlock(&sbi->s_lock);
  1221. err = dquot_suspend(sb, -1);
  1222. if (err < 0)
  1223. return err;
  1224. ext2_sync_super(sb, es, 1);
  1225. } else {
  1226. __le32 ret = EXT2_HAS_RO_COMPAT_FEATURE(sb,
  1227. ~EXT2_FEATURE_RO_COMPAT_SUPP);
  1228. if (ret) {
  1229. spin_unlock(&sbi->s_lock);
  1230. ext2_msg(sb, KERN_WARNING,
  1231. "warning: couldn't remount RDWR because of "
  1232. "unsupported optional features (%x).",
  1233. le32_to_cpu(ret));
  1234. return -EROFS;
  1235. }
  1236. /*
  1237. * Mounting a RDONLY partition read-write, so reread and
  1238. * store the current valid flag. (It may have been changed
  1239. * by e2fsck since we originally mounted the partition.)
  1240. */
  1241. sbi->s_mount_state = le16_to_cpu(es->s_state);
  1242. if (!ext2_setup_super (sb, es, 0))
  1243. sb->s_flags &= ~SB_RDONLY;
  1244. spin_unlock(&sbi->s_lock);
  1245. ext2_write_super(sb);
  1246. dquot_resume(sb, -1);
  1247. }
  1248. spin_lock(&sbi->s_lock);
  1249. out_set:
  1250. sbi->s_mount_opt = new_opts.s_mount_opt;
  1251. sbi->s_resuid = new_opts.s_resuid;
  1252. sbi->s_resgid = new_opts.s_resgid;
  1253. sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
  1254. ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? SB_POSIXACL : 0);
  1255. spin_unlock(&sbi->s_lock);
  1256. return 0;
  1257. }
  1258. static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf)
  1259. {
  1260. struct super_block *sb = dentry->d_sb;
  1261. struct ext2_sb_info *sbi = EXT2_SB(sb);
  1262. struct ext2_super_block *es = sbi->s_es;
  1263. u64 fsid;
  1264. spin_lock(&sbi->s_lock);
  1265. if (test_opt (sb, MINIX_DF))
  1266. sbi->s_overhead_last = 0;
  1267. else if (sbi->s_blocks_last != le32_to_cpu(es->s_blocks_count)) {
  1268. unsigned long i, overhead = 0;
  1269. smp_rmb();
  1270. /*
  1271. * Compute the overhead (FS structures). This is constant
  1272. * for a given filesystem unless the number of block groups
  1273. * changes so we cache the previous value until it does.
  1274. */
  1275. /*
  1276. * All of the blocks before first_data_block are
  1277. * overhead
  1278. */
  1279. overhead = le32_to_cpu(es->s_first_data_block);
  1280. /*
  1281. * Add the overhead attributed to the superblock and
  1282. * block group descriptors. If the sparse superblocks
  1283. * feature is turned on, then not all groups have this.
  1284. */
  1285. for (i = 0; i < sbi->s_groups_count; i++)
  1286. overhead += ext2_bg_has_super(sb, i) +
  1287. ext2_bg_num_gdb(sb, i);
  1288. /*
  1289. * Every block group has an inode bitmap, a block
  1290. * bitmap, and an inode table.
  1291. */
  1292. overhead += (sbi->s_groups_count *
  1293. (2 + sbi->s_itb_per_group));
  1294. sbi->s_overhead_last = overhead;
  1295. smp_wmb();
  1296. sbi->s_blocks_last = le32_to_cpu(es->s_blocks_count);
  1297. }
  1298. buf->f_type = EXT2_SUPER_MAGIC;
  1299. buf->f_bsize = sb->s_blocksize;
  1300. buf->f_blocks = le32_to_cpu(es->s_blocks_count) - sbi->s_overhead_last;
  1301. buf->f_bfree = ext2_count_free_blocks(sb);
  1302. es->s_free_blocks_count = cpu_to_le32(buf->f_bfree);
  1303. buf->f_bavail = buf->f_bfree - le32_to_cpu(es->s_r_blocks_count);
  1304. if (buf->f_bfree < le32_to_cpu(es->s_r_blocks_count))
  1305. buf->f_bavail = 0;
  1306. buf->f_files = le32_to_cpu(es->s_inodes_count);
  1307. buf->f_ffree = ext2_count_free_inodes(sb);
  1308. es->s_free_inodes_count = cpu_to_le32(buf->f_ffree);
  1309. buf->f_namelen = EXT2_NAME_LEN;
  1310. fsid = le64_to_cpup((void *)es->s_uuid) ^
  1311. le64_to_cpup((void *)es->s_uuid + sizeof(u64));
  1312. buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL;
  1313. buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL;
  1314. spin_unlock(&sbi->s_lock);
  1315. return 0;
  1316. }
  1317. static struct dentry *ext2_mount(struct file_system_type *fs_type,
  1318. int flags, const char *dev_name, void *data)
  1319. {
  1320. return mount_bdev(fs_type, flags, dev_name, data, ext2_fill_super);
  1321. }
  1322. #ifdef CONFIG_QUOTA
  1323. /* Read data from quotafile - avoid pagecache and such because we cannot afford
  1324. * acquiring the locks... As quota files are never truncated and quota code
  1325. * itself serializes the operations (and no one else should touch the files)
  1326. * we don't have to be afraid of races */
  1327. static ssize_t ext2_quota_read(struct super_block *sb, int type, char *data,
  1328. size_t len, loff_t off)
  1329. {
  1330. struct inode *inode = sb_dqopt(sb)->files[type];
  1331. sector_t blk = off >> EXT2_BLOCK_SIZE_BITS(sb);
  1332. int err = 0;
  1333. int offset = off & (sb->s_blocksize - 1);
  1334. int tocopy;
  1335. size_t toread;
  1336. struct buffer_head tmp_bh;
  1337. struct buffer_head *bh;
  1338. loff_t i_size = i_size_read(inode);
  1339. if (off > i_size)
  1340. return 0;
  1341. if (off+len > i_size)
  1342. len = i_size-off;
  1343. toread = len;
  1344. while (toread > 0) {
  1345. tocopy = sb->s_blocksize - offset < toread ?
  1346. sb->s_blocksize - offset : toread;
  1347. tmp_bh.b_state = 0;
  1348. tmp_bh.b_size = sb->s_blocksize;
  1349. err = ext2_get_block(inode, blk, &tmp_bh, 0);
  1350. if (err < 0)
  1351. return err;
  1352. if (!buffer_mapped(&tmp_bh)) /* A hole? */
  1353. memset(data, 0, tocopy);
  1354. else {
  1355. bh = sb_bread(sb, tmp_bh.b_blocknr);
  1356. if (!bh)
  1357. return -EIO;
  1358. memcpy(data, bh->b_data+offset, tocopy);
  1359. brelse(bh);
  1360. }
  1361. offset = 0;
  1362. toread -= tocopy;
  1363. data += tocopy;
  1364. blk++;
  1365. }
  1366. return len;
  1367. }
  1368. /* Write to quotafile */
  1369. static ssize_t ext2_quota_write(struct super_block *sb, int type,
  1370. const char *data, size_t len, loff_t off)
  1371. {
  1372. struct inode *inode = sb_dqopt(sb)->files[type];
  1373. sector_t blk = off >> EXT2_BLOCK_SIZE_BITS(sb);
  1374. int err = 0;
  1375. int offset = off & (sb->s_blocksize - 1);
  1376. int tocopy;
  1377. size_t towrite = len;
  1378. struct buffer_head tmp_bh;
  1379. struct buffer_head *bh;
  1380. while (towrite > 0) {
  1381. tocopy = sb->s_blocksize - offset < towrite ?
  1382. sb->s_blocksize - offset : towrite;
  1383. tmp_bh.b_state = 0;
  1384. tmp_bh.b_size = sb->s_blocksize;
  1385. err = ext2_get_block(inode, blk, &tmp_bh, 1);
  1386. if (err < 0)
  1387. goto out;
  1388. if (offset || tocopy != EXT2_BLOCK_SIZE(sb))
  1389. bh = sb_bread(sb, tmp_bh.b_blocknr);
  1390. else
  1391. bh = sb_getblk(sb, tmp_bh.b_blocknr);
  1392. if (unlikely(!bh)) {
  1393. err = -EIO;
  1394. goto out;
  1395. }
  1396. lock_buffer(bh);
  1397. memcpy(bh->b_data+offset, data, tocopy);
  1398. flush_dcache_page(bh->b_page);
  1399. set_buffer_uptodate(bh);
  1400. mark_buffer_dirty(bh);
  1401. unlock_buffer(bh);
  1402. brelse(bh);
  1403. offset = 0;
  1404. towrite -= tocopy;
  1405. data += tocopy;
  1406. blk++;
  1407. }
  1408. out:
  1409. if (len == towrite)
  1410. return err;
  1411. if (inode->i_size < off+len-towrite)
  1412. i_size_write(inode, off+len-towrite);
  1413. inode_inc_iversion(inode);
  1414. inode->i_mtime = inode->i_ctime = current_time(inode);
  1415. mark_inode_dirty(inode);
  1416. return len - towrite;
  1417. }
  1418. static int ext2_quota_on(struct super_block *sb, int type, int format_id,
  1419. const struct path *path)
  1420. {
  1421. int err;
  1422. struct inode *inode;
  1423. err = dquot_quota_on(sb, type, format_id, path);
  1424. if (err)
  1425. return err;
  1426. inode = d_inode(path->dentry);
  1427. inode_lock(inode);
  1428. EXT2_I(inode)->i_flags |= EXT2_NOATIME_FL | EXT2_IMMUTABLE_FL;
  1429. inode_set_flags(inode, S_NOATIME | S_IMMUTABLE,
  1430. S_NOATIME | S_IMMUTABLE);
  1431. inode_unlock(inode);
  1432. mark_inode_dirty(inode);
  1433. return 0;
  1434. }
  1435. static int ext2_quota_off(struct super_block *sb, int type)
  1436. {
  1437. struct inode *inode = sb_dqopt(sb)->files[type];
  1438. int err;
  1439. if (!inode || !igrab(inode))
  1440. goto out;
  1441. err = dquot_quota_off(sb, type);
  1442. if (err)
  1443. goto out_put;
  1444. inode_lock(inode);
  1445. EXT2_I(inode)->i_flags &= ~(EXT2_NOATIME_FL | EXT2_IMMUTABLE_FL);
  1446. inode_set_flags(inode, 0, S_NOATIME | S_IMMUTABLE);
  1447. inode_unlock(inode);
  1448. mark_inode_dirty(inode);
  1449. out_put:
  1450. iput(inode);
  1451. return err;
  1452. out:
  1453. return dquot_quota_off(sb, type);
  1454. }
  1455. #endif
  1456. static struct file_system_type ext2_fs_type = {
  1457. .owner = THIS_MODULE,
  1458. .name = "ext2",
  1459. .mount = ext2_mount,
  1460. .kill_sb = kill_block_super,
  1461. .fs_flags = FS_REQUIRES_DEV,
  1462. };
  1463. MODULE_ALIAS_FS("ext2");
  1464. static int __init init_ext2_fs(void)
  1465. {
  1466. int err;
  1467. err = init_inodecache();
  1468. if (err)
  1469. return err;
  1470. err = register_filesystem(&ext2_fs_type);
  1471. if (err)
  1472. goto out;
  1473. return 0;
  1474. out:
  1475. destroy_inodecache();
  1476. return err;
  1477. }
  1478. static void __exit exit_ext2_fs(void)
  1479. {
  1480. unregister_filesystem(&ext2_fs_type);
  1481. destroy_inodecache();
  1482. }
  1483. MODULE_AUTHOR("Remy Card and others");
  1484. MODULE_DESCRIPTION("Second Extended Filesystem");
  1485. MODULE_LICENSE("GPL");
  1486. module_init(init_ext2_fs)
  1487. module_exit(exit_ext2_fs)