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. 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) <= get_seconds()))
  616. ext2_msg(sb, KERN_WARNING,
  617. "warning: checktime reached, "
  618. "running e2fsck is recommended");
  619. if (!le16_to_cpu(es->s_max_mnt_count))
  620. es->s_max_mnt_count = cpu_to_le16(EXT2_DFL_MAX_MNT_COUNT);
  621. le16_add_cpu(&es->s_mnt_count, 1);
  622. if (test_opt (sb, DEBUG))
  623. ext2_msg(sb, KERN_INFO, "%s, %s, bs=%lu, fs=%lu, gc=%lu, "
  624. "bpg=%lu, ipg=%lu, mo=%04lx]",
  625. EXT2FS_VERSION, EXT2FS_DATE, sb->s_blocksize,
  626. sbi->s_frag_size,
  627. sbi->s_groups_count,
  628. EXT2_BLOCKS_PER_GROUP(sb),
  629. EXT2_INODES_PER_GROUP(sb),
  630. sbi->s_mount_opt);
  631. return res;
  632. }
  633. static int ext2_check_descriptors(struct super_block *sb)
  634. {
  635. int i;
  636. struct ext2_sb_info *sbi = EXT2_SB(sb);
  637. ext2_debug ("Checking group descriptors");
  638. for (i = 0; i < sbi->s_groups_count; i++) {
  639. struct ext2_group_desc *gdp = ext2_get_group_desc(sb, i, NULL);
  640. ext2_fsblk_t first_block = ext2_group_first_block_no(sb, i);
  641. ext2_fsblk_t last_block;
  642. if (i == sbi->s_groups_count - 1)
  643. last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1;
  644. else
  645. last_block = first_block +
  646. (EXT2_BLOCKS_PER_GROUP(sb) - 1);
  647. if (le32_to_cpu(gdp->bg_block_bitmap) < first_block ||
  648. le32_to_cpu(gdp->bg_block_bitmap) > last_block)
  649. {
  650. ext2_error (sb, "ext2_check_descriptors",
  651. "Block bitmap for group %d"
  652. " not in group (block %lu)!",
  653. i, (unsigned long) le32_to_cpu(gdp->bg_block_bitmap));
  654. return 0;
  655. }
  656. if (le32_to_cpu(gdp->bg_inode_bitmap) < first_block ||
  657. le32_to_cpu(gdp->bg_inode_bitmap) > last_block)
  658. {
  659. ext2_error (sb, "ext2_check_descriptors",
  660. "Inode bitmap for group %d"
  661. " not in group (block %lu)!",
  662. i, (unsigned long) le32_to_cpu(gdp->bg_inode_bitmap));
  663. return 0;
  664. }
  665. if (le32_to_cpu(gdp->bg_inode_table) < first_block ||
  666. le32_to_cpu(gdp->bg_inode_table) + sbi->s_itb_per_group - 1 >
  667. last_block)
  668. {
  669. ext2_error (sb, "ext2_check_descriptors",
  670. "Inode table for group %d"
  671. " not in group (block %lu)!",
  672. i, (unsigned long) le32_to_cpu(gdp->bg_inode_table));
  673. return 0;
  674. }
  675. }
  676. return 1;
  677. }
  678. /*
  679. * Maximal file size. There is a direct, and {,double-,triple-}indirect
  680. * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks.
  681. * We need to be 1 filesystem block less than the 2^32 sector limit.
  682. */
  683. static loff_t ext2_max_size(int bits)
  684. {
  685. loff_t res = EXT2_NDIR_BLOCKS;
  686. int meta_blocks;
  687. loff_t upper_limit;
  688. /* This is calculated to be the largest file size for a
  689. * dense, file such that the total number of
  690. * sectors in the file, including data and all indirect blocks,
  691. * does not exceed 2^32 -1
  692. * __u32 i_blocks representing the total number of
  693. * 512 bytes blocks of the file
  694. */
  695. upper_limit = (1LL << 32) - 1;
  696. /* total blocks in file system block size */
  697. upper_limit >>= (bits - 9);
  698. /* indirect blocks */
  699. meta_blocks = 1;
  700. /* double indirect blocks */
  701. meta_blocks += 1 + (1LL << (bits-2));
  702. /* tripple indirect blocks */
  703. meta_blocks += 1 + (1LL << (bits-2)) + (1LL << (2*(bits-2)));
  704. upper_limit -= meta_blocks;
  705. upper_limit <<= bits;
  706. res += 1LL << (bits-2);
  707. res += 1LL << (2*(bits-2));
  708. res += 1LL << (3*(bits-2));
  709. res <<= bits;
  710. if (res > upper_limit)
  711. res = upper_limit;
  712. if (res > MAX_LFS_FILESIZE)
  713. res = MAX_LFS_FILESIZE;
  714. return res;
  715. }
  716. static unsigned long descriptor_loc(struct super_block *sb,
  717. unsigned long logic_sb_block,
  718. int nr)
  719. {
  720. struct ext2_sb_info *sbi = EXT2_SB(sb);
  721. unsigned long bg, first_meta_bg;
  722. int has_super = 0;
  723. first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg);
  724. if (!EXT2_HAS_INCOMPAT_FEATURE(sb, EXT2_FEATURE_INCOMPAT_META_BG) ||
  725. nr < first_meta_bg)
  726. return (logic_sb_block + nr + 1);
  727. bg = sbi->s_desc_per_block * nr;
  728. if (ext2_bg_has_super(sb, bg))
  729. has_super = 1;
  730. return ext2_group_first_block_no(sb, bg) + has_super;
  731. }
  732. static int ext2_fill_super(struct super_block *sb, void *data, int silent)
  733. {
  734. struct dax_device *dax_dev = fs_dax_get_by_bdev(sb->s_bdev);
  735. struct buffer_head * bh;
  736. struct ext2_sb_info * sbi;
  737. struct ext2_super_block * es;
  738. struct inode *root;
  739. unsigned long block;
  740. unsigned long sb_block = get_sb_block(&data);
  741. unsigned long logic_sb_block;
  742. unsigned long offset = 0;
  743. unsigned long def_mount_opts;
  744. long ret = -ENOMEM;
  745. int blocksize = BLOCK_SIZE;
  746. int db_count;
  747. int i, j;
  748. __le32 features;
  749. int err;
  750. struct ext2_mount_options opts;
  751. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  752. if (!sbi)
  753. goto failed;
  754. sbi->s_blockgroup_lock =
  755. kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
  756. if (!sbi->s_blockgroup_lock) {
  757. kfree(sbi);
  758. goto failed;
  759. }
  760. sb->s_fs_info = sbi;
  761. sbi->s_sb_block = sb_block;
  762. sbi->s_daxdev = dax_dev;
  763. spin_lock_init(&sbi->s_lock);
  764. ret = -EINVAL;
  765. /*
  766. * See what the current blocksize for the device is, and
  767. * use that as the blocksize. Otherwise (or if the blocksize
  768. * is smaller than the default) use the default.
  769. * This is important for devices that have a hardware
  770. * sectorsize that is larger than the default.
  771. */
  772. blocksize = sb_min_blocksize(sb, BLOCK_SIZE);
  773. if (!blocksize) {
  774. ext2_msg(sb, KERN_ERR, "error: unable to set blocksize");
  775. goto failed_sbi;
  776. }
  777. /*
  778. * If the superblock doesn't start on a hardware sector boundary,
  779. * calculate the offset.
  780. */
  781. if (blocksize != BLOCK_SIZE) {
  782. logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize;
  783. offset = (sb_block*BLOCK_SIZE) % blocksize;
  784. } else {
  785. logic_sb_block = sb_block;
  786. }
  787. if (!(bh = sb_bread(sb, logic_sb_block))) {
  788. ext2_msg(sb, KERN_ERR, "error: unable to read superblock");
  789. goto failed_sbi;
  790. }
  791. /*
  792. * Note: s_es must be initialized as soon as possible because
  793. * some ext2 macro-instructions depend on its value
  794. */
  795. es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
  796. sbi->s_es = es;
  797. sb->s_magic = le16_to_cpu(es->s_magic);
  798. if (sb->s_magic != EXT2_SUPER_MAGIC)
  799. goto cantfind_ext2;
  800. /* Set defaults before we parse the mount options */
  801. def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
  802. if (def_mount_opts & EXT2_DEFM_DEBUG)
  803. set_opt(opts.s_mount_opt, DEBUG);
  804. if (def_mount_opts & EXT2_DEFM_BSDGROUPS)
  805. set_opt(opts.s_mount_opt, GRPID);
  806. if (def_mount_opts & EXT2_DEFM_UID16)
  807. set_opt(opts.s_mount_opt, NO_UID32);
  808. #ifdef CONFIG_EXT2_FS_XATTR
  809. if (def_mount_opts & EXT2_DEFM_XATTR_USER)
  810. set_opt(opts.s_mount_opt, XATTR_USER);
  811. #endif
  812. #ifdef CONFIG_EXT2_FS_POSIX_ACL
  813. if (def_mount_opts & EXT2_DEFM_ACL)
  814. set_opt(opts.s_mount_opt, POSIX_ACL);
  815. #endif
  816. if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_PANIC)
  817. set_opt(opts.s_mount_opt, ERRORS_PANIC);
  818. else if (le16_to_cpu(sbi->s_es->s_errors) == EXT2_ERRORS_CONTINUE)
  819. set_opt(opts.s_mount_opt, ERRORS_CONT);
  820. else
  821. set_opt(opts.s_mount_opt, ERRORS_RO);
  822. opts.s_resuid = make_kuid(&init_user_ns, le16_to_cpu(es->s_def_resuid));
  823. opts.s_resgid = make_kgid(&init_user_ns, le16_to_cpu(es->s_def_resgid));
  824. set_opt(opts.s_mount_opt, RESERVATION);
  825. if (!parse_options((char *) data, sb, &opts))
  826. goto failed_mount;
  827. sbi->s_mount_opt = opts.s_mount_opt;
  828. sbi->s_resuid = opts.s_resuid;
  829. sbi->s_resgid = opts.s_resgid;
  830. sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
  831. ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
  832. SB_POSIXACL : 0);
  833. sb->s_iflags |= SB_I_CGROUPWB;
  834. if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV &&
  835. (EXT2_HAS_COMPAT_FEATURE(sb, ~0U) ||
  836. EXT2_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
  837. EXT2_HAS_INCOMPAT_FEATURE(sb, ~0U)))
  838. ext2_msg(sb, KERN_WARNING,
  839. "warning: feature flags set on rev 0 fs, "
  840. "running e2fsck is recommended");
  841. /*
  842. * Check feature flags regardless of the revision level, since we
  843. * previously didn't change the revision level when setting the flags,
  844. * so there is a chance incompat flags are set on a rev 0 filesystem.
  845. */
  846. features = EXT2_HAS_INCOMPAT_FEATURE(sb, ~EXT2_FEATURE_INCOMPAT_SUPP);
  847. if (features) {
  848. ext2_msg(sb, KERN_ERR, "error: couldn't mount because of "
  849. "unsupported optional features (%x)",
  850. le32_to_cpu(features));
  851. goto failed_mount;
  852. }
  853. if (!sb_rdonly(sb) && (features = EXT2_HAS_RO_COMPAT_FEATURE(sb, ~EXT2_FEATURE_RO_COMPAT_SUPP))){
  854. ext2_msg(sb, KERN_ERR, "error: couldn't mount RDWR because of "
  855. "unsupported optional features (%x)",
  856. le32_to_cpu(features));
  857. goto failed_mount;
  858. }
  859. blocksize = BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size);
  860. if (sbi->s_mount_opt & EXT2_MOUNT_DAX) {
  861. if (!bdev_dax_supported(sb->s_bdev, blocksize)) {
  862. ext2_msg(sb, KERN_ERR,
  863. "DAX unsupported by block device. Turning off DAX.");
  864. sbi->s_mount_opt &= ~EXT2_MOUNT_DAX;
  865. }
  866. }
  867. /* If the blocksize doesn't match, re-read the thing.. */
  868. if (sb->s_blocksize != blocksize) {
  869. brelse(bh);
  870. if (!sb_set_blocksize(sb, blocksize)) {
  871. ext2_msg(sb, KERN_ERR,
  872. "error: bad blocksize %d", blocksize);
  873. goto failed_sbi;
  874. }
  875. logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize;
  876. offset = (sb_block*BLOCK_SIZE) % blocksize;
  877. bh = sb_bread(sb, logic_sb_block);
  878. if(!bh) {
  879. ext2_msg(sb, KERN_ERR, "error: couldn't read"
  880. "superblock on 2nd try");
  881. goto failed_sbi;
  882. }
  883. es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
  884. sbi->s_es = es;
  885. if (es->s_magic != cpu_to_le16(EXT2_SUPER_MAGIC)) {
  886. ext2_msg(sb, KERN_ERR, "error: magic mismatch");
  887. goto failed_mount;
  888. }
  889. }
  890. sb->s_maxbytes = ext2_max_size(sb->s_blocksize_bits);
  891. sb->s_max_links = EXT2_LINK_MAX;
  892. if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV) {
  893. sbi->s_inode_size = EXT2_GOOD_OLD_INODE_SIZE;
  894. sbi->s_first_ino = EXT2_GOOD_OLD_FIRST_INO;
  895. } else {
  896. sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
  897. sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
  898. if ((sbi->s_inode_size < EXT2_GOOD_OLD_INODE_SIZE) ||
  899. !is_power_of_2(sbi->s_inode_size) ||
  900. (sbi->s_inode_size > blocksize)) {
  901. ext2_msg(sb, KERN_ERR,
  902. "error: unsupported inode size: %d",
  903. sbi->s_inode_size);
  904. goto failed_mount;
  905. }
  906. }
  907. sbi->s_frag_size = EXT2_MIN_FRAG_SIZE <<
  908. le32_to_cpu(es->s_log_frag_size);
  909. if (sbi->s_frag_size == 0)
  910. goto cantfind_ext2;
  911. sbi->s_frags_per_block = sb->s_blocksize / sbi->s_frag_size;
  912. sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
  913. sbi->s_frags_per_group = le32_to_cpu(es->s_frags_per_group);
  914. sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
  915. if (EXT2_INODE_SIZE(sb) == 0)
  916. goto cantfind_ext2;
  917. sbi->s_inodes_per_block = sb->s_blocksize / EXT2_INODE_SIZE(sb);
  918. if (sbi->s_inodes_per_block == 0 || sbi->s_inodes_per_group == 0)
  919. goto cantfind_ext2;
  920. sbi->s_itb_per_group = sbi->s_inodes_per_group /
  921. sbi->s_inodes_per_block;
  922. sbi->s_desc_per_block = sb->s_blocksize /
  923. sizeof (struct ext2_group_desc);
  924. sbi->s_sbh = bh;
  925. sbi->s_mount_state = le16_to_cpu(es->s_state);
  926. sbi->s_addr_per_block_bits =
  927. ilog2 (EXT2_ADDR_PER_BLOCK(sb));
  928. sbi->s_desc_per_block_bits =
  929. ilog2 (EXT2_DESC_PER_BLOCK(sb));
  930. if (sb->s_magic != EXT2_SUPER_MAGIC)
  931. goto cantfind_ext2;
  932. if (sb->s_blocksize != bh->b_size) {
  933. if (!silent)
  934. ext2_msg(sb, KERN_ERR, "error: unsupported blocksize");
  935. goto failed_mount;
  936. }
  937. if (sb->s_blocksize != sbi->s_frag_size) {
  938. ext2_msg(sb, KERN_ERR,
  939. "error: fragsize %lu != blocksize %lu"
  940. "(not supported yet)",
  941. sbi->s_frag_size, sb->s_blocksize);
  942. goto failed_mount;
  943. }
  944. if (sbi->s_blocks_per_group > sb->s_blocksize * 8) {
  945. ext2_msg(sb, KERN_ERR,
  946. "error: #blocks per group too big: %lu",
  947. sbi->s_blocks_per_group);
  948. goto failed_mount;
  949. }
  950. if (sbi->s_frags_per_group > sb->s_blocksize * 8) {
  951. ext2_msg(sb, KERN_ERR,
  952. "error: #fragments per group too big: %lu",
  953. sbi->s_frags_per_group);
  954. goto failed_mount;
  955. }
  956. if (sbi->s_inodes_per_group > sb->s_blocksize * 8) {
  957. ext2_msg(sb, KERN_ERR,
  958. "error: #inodes per group too big: %lu",
  959. sbi->s_inodes_per_group);
  960. goto failed_mount;
  961. }
  962. if (EXT2_BLOCKS_PER_GROUP(sb) == 0)
  963. goto cantfind_ext2;
  964. sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) -
  965. le32_to_cpu(es->s_first_data_block) - 1)
  966. / EXT2_BLOCKS_PER_GROUP(sb)) + 1;
  967. db_count = (sbi->s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
  968. EXT2_DESC_PER_BLOCK(sb);
  969. sbi->s_group_desc = kmalloc_array (db_count,
  970. sizeof(struct buffer_head *),
  971. GFP_KERNEL);
  972. if (sbi->s_group_desc == NULL) {
  973. ext2_msg(sb, KERN_ERR, "error: not enough memory");
  974. goto failed_mount;
  975. }
  976. bgl_lock_init(sbi->s_blockgroup_lock);
  977. sbi->s_debts = kcalloc(sbi->s_groups_count, sizeof(*sbi->s_debts), GFP_KERNEL);
  978. if (!sbi->s_debts) {
  979. ext2_msg(sb, KERN_ERR, "error: not enough memory");
  980. goto failed_mount_group_desc;
  981. }
  982. for (i = 0; i < db_count; i++) {
  983. block = descriptor_loc(sb, logic_sb_block, i);
  984. sbi->s_group_desc[i] = sb_bread(sb, block);
  985. if (!sbi->s_group_desc[i]) {
  986. for (j = 0; j < i; j++)
  987. brelse (sbi->s_group_desc[j]);
  988. ext2_msg(sb, KERN_ERR,
  989. "error: unable to read group descriptors");
  990. goto failed_mount_group_desc;
  991. }
  992. }
  993. if (!ext2_check_descriptors (sb)) {
  994. ext2_msg(sb, KERN_ERR, "group descriptors corrupted");
  995. goto failed_mount2;
  996. }
  997. sbi->s_gdb_count = db_count;
  998. get_random_bytes(&sbi->s_next_generation, sizeof(u32));
  999. spin_lock_init(&sbi->s_next_gen_lock);
  1000. /* per fileystem reservation list head & lock */
  1001. spin_lock_init(&sbi->s_rsv_window_lock);
  1002. sbi->s_rsv_window_root = RB_ROOT;
  1003. /*
  1004. * Add a single, static dummy reservation to the start of the
  1005. * reservation window list --- it gives us a placeholder for
  1006. * append-at-start-of-list which makes the allocation logic
  1007. * _much_ simpler.
  1008. */
  1009. sbi->s_rsv_window_head.rsv_start = EXT2_RESERVE_WINDOW_NOT_ALLOCATED;
  1010. sbi->s_rsv_window_head.rsv_end = EXT2_RESERVE_WINDOW_NOT_ALLOCATED;
  1011. sbi->s_rsv_window_head.rsv_alloc_hit = 0;
  1012. sbi->s_rsv_window_head.rsv_goal_size = 0;
  1013. ext2_rsv_window_add(sb, &sbi->s_rsv_window_head);
  1014. err = percpu_counter_init(&sbi->s_freeblocks_counter,
  1015. ext2_count_free_blocks(sb), GFP_KERNEL);
  1016. if (!err) {
  1017. err = percpu_counter_init(&sbi->s_freeinodes_counter,
  1018. ext2_count_free_inodes(sb), GFP_KERNEL);
  1019. }
  1020. if (!err) {
  1021. err = percpu_counter_init(&sbi->s_dirs_counter,
  1022. ext2_count_dirs(sb), GFP_KERNEL);
  1023. }
  1024. if (err) {
  1025. ext2_msg(sb, KERN_ERR, "error: insufficient memory");
  1026. goto failed_mount3;
  1027. }
  1028. #ifdef CONFIG_EXT2_FS_XATTR
  1029. sbi->s_ea_block_cache = ext2_xattr_create_cache();
  1030. if (!sbi->s_ea_block_cache) {
  1031. ext2_msg(sb, KERN_ERR, "Failed to create ea_block_cache");
  1032. goto failed_mount3;
  1033. }
  1034. #endif
  1035. /*
  1036. * set up enough so that it can read an inode
  1037. */
  1038. sb->s_op = &ext2_sops;
  1039. sb->s_export_op = &ext2_export_ops;
  1040. sb->s_xattr = ext2_xattr_handlers;
  1041. #ifdef CONFIG_QUOTA
  1042. sb->dq_op = &dquot_operations;
  1043. sb->s_qcop = &ext2_quotactl_ops;
  1044. sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
  1045. #endif
  1046. root = ext2_iget(sb, EXT2_ROOT_INO);
  1047. if (IS_ERR(root)) {
  1048. ret = PTR_ERR(root);
  1049. goto failed_mount3;
  1050. }
  1051. if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
  1052. iput(root);
  1053. ext2_msg(sb, KERN_ERR, "error: corrupt root inode, run e2fsck");
  1054. goto failed_mount3;
  1055. }
  1056. sb->s_root = d_make_root(root);
  1057. if (!sb->s_root) {
  1058. ext2_msg(sb, KERN_ERR, "error: get root inode failed");
  1059. ret = -ENOMEM;
  1060. goto failed_mount3;
  1061. }
  1062. if (EXT2_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL))
  1063. ext2_msg(sb, KERN_WARNING,
  1064. "warning: mounting ext3 filesystem as ext2");
  1065. if (ext2_setup_super (sb, es, sb_rdonly(sb)))
  1066. sb->s_flags |= SB_RDONLY;
  1067. ext2_write_super(sb);
  1068. return 0;
  1069. cantfind_ext2:
  1070. if (!silent)
  1071. ext2_msg(sb, KERN_ERR,
  1072. "error: can't find an ext2 filesystem on dev %s.",
  1073. sb->s_id);
  1074. goto failed_mount;
  1075. failed_mount3:
  1076. if (sbi->s_ea_block_cache)
  1077. ext2_xattr_destroy_cache(sbi->s_ea_block_cache);
  1078. percpu_counter_destroy(&sbi->s_freeblocks_counter);
  1079. percpu_counter_destroy(&sbi->s_freeinodes_counter);
  1080. percpu_counter_destroy(&sbi->s_dirs_counter);
  1081. failed_mount2:
  1082. for (i = 0; i < db_count; i++)
  1083. brelse(sbi->s_group_desc[i]);
  1084. failed_mount_group_desc:
  1085. kfree(sbi->s_group_desc);
  1086. kfree(sbi->s_debts);
  1087. failed_mount:
  1088. brelse(bh);
  1089. failed_sbi:
  1090. sb->s_fs_info = NULL;
  1091. kfree(sbi->s_blockgroup_lock);
  1092. kfree(sbi);
  1093. failed:
  1094. fs_put_dax(dax_dev);
  1095. return ret;
  1096. }
  1097. static void ext2_clear_super_error(struct super_block *sb)
  1098. {
  1099. struct buffer_head *sbh = EXT2_SB(sb)->s_sbh;
  1100. if (buffer_write_io_error(sbh)) {
  1101. /*
  1102. * Oh, dear. A previous attempt to write the
  1103. * superblock failed. This could happen because the
  1104. * USB device was yanked out. Or it could happen to
  1105. * be a transient write error and maybe the block will
  1106. * be remapped. Nothing we can do but to retry the
  1107. * write and hope for the best.
  1108. */
  1109. ext2_msg(sb, KERN_ERR,
  1110. "previous I/O error to superblock detected");
  1111. clear_buffer_write_io_error(sbh);
  1112. set_buffer_uptodate(sbh);
  1113. }
  1114. }
  1115. void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es,
  1116. int wait)
  1117. {
  1118. ext2_clear_super_error(sb);
  1119. spin_lock(&EXT2_SB(sb)->s_lock);
  1120. es->s_free_blocks_count = cpu_to_le32(ext2_count_free_blocks(sb));
  1121. es->s_free_inodes_count = cpu_to_le32(ext2_count_free_inodes(sb));
  1122. es->s_wtime = cpu_to_le32(get_seconds());
  1123. /* unlock before we do IO */
  1124. spin_unlock(&EXT2_SB(sb)->s_lock);
  1125. mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
  1126. if (wait)
  1127. sync_dirty_buffer(EXT2_SB(sb)->s_sbh);
  1128. }
  1129. /*
  1130. * In the second extended file system, it is not necessary to
  1131. * write the super block since we use a mapping of the
  1132. * disk super block in a buffer.
  1133. *
  1134. * However, this function is still used to set the fs valid
  1135. * flags to 0. We need to set this flag to 0 since the fs
  1136. * may have been checked while mounted and e2fsck may have
  1137. * set s_state to EXT2_VALID_FS after some corrections.
  1138. */
  1139. static int ext2_sync_fs(struct super_block *sb, int wait)
  1140. {
  1141. struct ext2_sb_info *sbi = EXT2_SB(sb);
  1142. struct ext2_super_block *es = EXT2_SB(sb)->s_es;
  1143. /*
  1144. * Write quota structures to quota file, sync_blockdev() will write
  1145. * them to disk later
  1146. */
  1147. dquot_writeback_dquots(sb, -1);
  1148. spin_lock(&sbi->s_lock);
  1149. if (es->s_state & cpu_to_le16(EXT2_VALID_FS)) {
  1150. ext2_debug("setting valid to 0\n");
  1151. es->s_state &= cpu_to_le16(~EXT2_VALID_FS);
  1152. }
  1153. spin_unlock(&sbi->s_lock);
  1154. ext2_sync_super(sb, es, wait);
  1155. return 0;
  1156. }
  1157. static int ext2_freeze(struct super_block *sb)
  1158. {
  1159. struct ext2_sb_info *sbi = EXT2_SB(sb);
  1160. /*
  1161. * Open but unlinked files present? Keep EXT2_VALID_FS flag cleared
  1162. * because we have unattached inodes and thus filesystem is not fully
  1163. * consistent.
  1164. */
  1165. if (atomic_long_read(&sb->s_remove_count)) {
  1166. ext2_sync_fs(sb, 1);
  1167. return 0;
  1168. }
  1169. /* Set EXT2_FS_VALID flag */
  1170. spin_lock(&sbi->s_lock);
  1171. sbi->s_es->s_state = cpu_to_le16(sbi->s_mount_state);
  1172. spin_unlock(&sbi->s_lock);
  1173. ext2_sync_super(sb, sbi->s_es, 1);
  1174. return 0;
  1175. }
  1176. static int ext2_unfreeze(struct super_block *sb)
  1177. {
  1178. /* Just write sb to clear EXT2_VALID_FS flag */
  1179. ext2_write_super(sb);
  1180. return 0;
  1181. }
  1182. static void ext2_write_super(struct super_block *sb)
  1183. {
  1184. if (!sb_rdonly(sb))
  1185. ext2_sync_fs(sb, 1);
  1186. }
  1187. static int ext2_remount (struct super_block * sb, int * flags, char * data)
  1188. {
  1189. struct ext2_sb_info * sbi = EXT2_SB(sb);
  1190. struct ext2_super_block * es;
  1191. struct ext2_mount_options new_opts;
  1192. int err;
  1193. sync_filesystem(sb);
  1194. spin_lock(&sbi->s_lock);
  1195. new_opts.s_mount_opt = sbi->s_mount_opt;
  1196. new_opts.s_resuid = sbi->s_resuid;
  1197. new_opts.s_resgid = sbi->s_resgid;
  1198. spin_unlock(&sbi->s_lock);
  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)