super.c (6a797d2737838906f2ea0a31686e87c3151e21ca) super.c (e2b911c53584a92266943f3b7f2cdbc19c1a4e80)
1/*
2 * linux/fs/ext4/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 *

--- 96 unchanged lines hidden (view full) ---

105};
106MODULE_ALIAS_FS("ext3");
107MODULE_ALIAS("ext3");
108#define IS_EXT3_SB(sb) ((sb)->s_bdev->bd_holder == &ext3_fs_type)
109
110static int ext4_verify_csum_type(struct super_block *sb,
111 struct ext4_super_block *es)
112{
1/*
2 * linux/fs/ext4/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 *

--- 96 unchanged lines hidden (view full) ---

105};
106MODULE_ALIAS_FS("ext3");
107MODULE_ALIAS("ext3");
108#define IS_EXT3_SB(sb) ((sb)->s_bdev->bd_holder == &ext3_fs_type)
109
110static int ext4_verify_csum_type(struct super_block *sb,
111 struct ext4_super_block *es)
112{
113 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
114 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
113 if (!ext4_has_feature_metadata_csum(sb))
115 return 1;
116
117 return es->s_checksum_type == EXT4_CRC32C_CHKSUM;
118}
119
120static __le32 ext4_superblock_csum(struct super_block *sb,
121 struct ext4_super_block *es)
122{

--- 682 unchanged lines hidden (view full) ---

805 ext4_es_unregister_shrinker(sbi);
806 del_timer_sync(&sbi->s_err_report);
807 ext4_release_system_zone(sb);
808 ext4_mb_release(sb);
809 ext4_ext_release(sb);
810 ext4_xattr_put_super(sb);
811
812 if (!(sb->s_flags & MS_RDONLY)) {
114 return 1;
115
116 return es->s_checksum_type == EXT4_CRC32C_CHKSUM;
117}
118
119static __le32 ext4_superblock_csum(struct super_block *sb,
120 struct ext4_super_block *es)
121{

--- 682 unchanged lines hidden (view full) ---

804 ext4_es_unregister_shrinker(sbi);
805 del_timer_sync(&sbi->s_err_report);
806 ext4_release_system_zone(sb);
807 ext4_mb_release(sb);
808 ext4_ext_release(sb);
809 ext4_xattr_put_super(sb);
810
811 if (!(sb->s_flags & MS_RDONLY)) {
813 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
812 ext4_clear_feature_journal_needs_recovery(sb);
814 es->s_state = cpu_to_le16(sbi->s_mount_state);
815 }
816 if (!(sb->s_flags & MS_RDONLY))
817 ext4_commit_super(sb, 1);
818
819 for (i = 0; i < sbi->s_gdb_count; i++)
820 brelse(sbi->s_group_desc[i]);
821 kvfree(sbi->s_group_desc);

--- 457 unchanged lines hidden (view full) ---

1279
1280 if (sb_any_quota_loaded(sb) &&
1281 !sbi->s_qf_names[qtype]) {
1282 ext4_msg(sb, KERN_ERR,
1283 "Cannot change journaled "
1284 "quota options when quota turned on");
1285 return -1;
1286 }
813 es->s_state = cpu_to_le16(sbi->s_mount_state);
814 }
815 if (!(sb->s_flags & MS_RDONLY))
816 ext4_commit_super(sb, 1);
817
818 for (i = 0; i < sbi->s_gdb_count; i++)
819 brelse(sbi->s_group_desc[i]);
820 kvfree(sbi->s_group_desc);

--- 457 unchanged lines hidden (view full) ---

1278
1279 if (sb_any_quota_loaded(sb) &&
1280 !sbi->s_qf_names[qtype]) {
1281 ext4_msg(sb, KERN_ERR,
1282 "Cannot change journaled "
1283 "quota options when quota turned on");
1284 return -1;
1285 }
1287 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA)) {
1286 if (ext4_has_feature_quota(sb)) {
1288 ext4_msg(sb, KERN_ERR, "Cannot set journaled quota options "
1289 "when QUOTA feature is enabled");
1290 return -1;
1291 }
1292 qname = match_strdup(args);
1293 if (!qname) {
1294 ext4_msg(sb, KERN_ERR,
1295 "Not enough memory for storing quotafile name");

--- 342 unchanged lines hidden (view full) ---

1638#ifdef CONFIG_QUOTA
1639 } else if (m->flags & MOPT_QFMT) {
1640 if (sb_any_quota_loaded(sb) &&
1641 sbi->s_jquota_fmt != m->mount_opt) {
1642 ext4_msg(sb, KERN_ERR, "Cannot change journaled "
1643 "quota options when quota turned on");
1644 return -1;
1645 }
1287 ext4_msg(sb, KERN_ERR, "Cannot set journaled quota options "
1288 "when QUOTA feature is enabled");
1289 return -1;
1290 }
1291 qname = match_strdup(args);
1292 if (!qname) {
1293 ext4_msg(sb, KERN_ERR,
1294 "Not enough memory for storing quotafile name");

--- 342 unchanged lines hidden (view full) ---

1637#ifdef CONFIG_QUOTA
1638 } else if (m->flags & MOPT_QFMT) {
1639 if (sb_any_quota_loaded(sb) &&
1640 sbi->s_jquota_fmt != m->mount_opt) {
1641 ext4_msg(sb, KERN_ERR, "Cannot change journaled "
1642 "quota options when quota turned on");
1643 return -1;
1644 }
1646 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
1647 EXT4_FEATURE_RO_COMPAT_QUOTA)) {
1645 if (ext4_has_feature_quota(sb)) {
1648 ext4_msg(sb, KERN_ERR,
1649 "Cannot set journaled quota options "
1650 "when QUOTA feature is enabled");
1651 return -1;
1652 }
1653 sbi->s_jquota_fmt = m->mount_opt;
1654#endif
1655#ifndef CONFIG_FS_DAX

--- 42 unchanged lines hidden (view full) ---

1698 */
1699 args[0].to = args[0].from = NULL;
1700 token = match_token(p, tokens, args);
1701 if (handle_mount_opt(sb, p, token, args, journal_devnum,
1702 journal_ioprio, is_remount) < 0)
1703 return 0;
1704 }
1705#ifdef CONFIG_QUOTA
1646 ext4_msg(sb, KERN_ERR,
1647 "Cannot set journaled quota options "
1648 "when QUOTA feature is enabled");
1649 return -1;
1650 }
1651 sbi->s_jquota_fmt = m->mount_opt;
1652#endif
1653#ifndef CONFIG_FS_DAX

--- 42 unchanged lines hidden (view full) ---

1696 */
1697 args[0].to = args[0].from = NULL;
1698 token = match_token(p, tokens, args);
1699 if (handle_mount_opt(sb, p, token, args, journal_devnum,
1700 journal_ioprio, is_remount) < 0)
1701 return 0;
1702 }
1703#ifdef CONFIG_QUOTA
1706 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA) &&
1704 if (ext4_has_feature_quota(sb) &&
1707 (test_opt(sb, USRQUOTA) || test_opt(sb, GRPQUOTA))) {
1708 ext4_msg(sb, KERN_ERR, "Cannot set quota options when QUOTA "
1709 "feature is enabled");
1710 return 0;
1711 }
1712 if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) {
1713 if (test_opt(sb, USRQUOTA) && sbi->s_qf_names[USRQUOTA])
1714 clear_opt(sb, USRQUOTA);

--- 207 unchanged lines hidden (view full) ---

1922 if (!sbi->s_journal)
1923 es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
1924 if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
1925 es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
1926 le16_add_cpu(&es->s_mnt_count, 1);
1927 es->s_mtime = cpu_to_le32(get_seconds());
1928 ext4_update_dynamic_rev(sb);
1929 if (sbi->s_journal)
1705 (test_opt(sb, USRQUOTA) || test_opt(sb, GRPQUOTA))) {
1706 ext4_msg(sb, KERN_ERR, "Cannot set quota options when QUOTA "
1707 "feature is enabled");
1708 return 0;
1709 }
1710 if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) {
1711 if (test_opt(sb, USRQUOTA) && sbi->s_qf_names[USRQUOTA])
1712 clear_opt(sb, USRQUOTA);

--- 207 unchanged lines hidden (view full) ---

1920 if (!sbi->s_journal)
1921 es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
1922 if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
1923 es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
1924 le16_add_cpu(&es->s_mnt_count, 1);
1925 es->s_mtime = cpu_to_le32(get_seconds());
1926 ext4_update_dynamic_rev(sb);
1927 if (sbi->s_journal)
1930 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
1928 ext4_set_feature_journal_needs_recovery(sb);
1931
1932 ext4_commit_super(sb, 1);
1933done:
1934 if (test_opt(sb, DEBUG))
1935 printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, "
1936 "bpg=%lu, ipg=%lu, mo=%04x, mo2=%04x]\n",
1937 sb->s_blocksize,
1938 sbi->s_groups_count,

--- 66 unchanged lines hidden (view full) ---

2005 &sbi->s_flex_groups[flex_group].used_dirs);
2006 }
2007
2008 return 1;
2009failed:
2010 return 0;
2011}
2012
1929
1930 ext4_commit_super(sb, 1);
1931done:
1932 if (test_opt(sb, DEBUG))
1933 printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, "
1934 "bpg=%lu, ipg=%lu, mo=%04x, mo2=%04x]\n",
1935 sb->s_blocksize,
1936 sbi->s_groups_count,

--- 66 unchanged lines hidden (view full) ---

2003 &sbi->s_flex_groups[flex_group].used_dirs);
2004 }
2005
2006 return 1;
2007failed:
2008 return 0;
2009}
2010
2013static __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group,
2011static __le16 ext4_group_desc_csum(struct super_block *sb, __u32 block_group,
2014 struct ext4_group_desc *gdp)
2015{
2016 int offset;
2017 __u16 crc = 0;
2018 __le32 le_group = cpu_to_le32(block_group);
2012 struct ext4_group_desc *gdp)
2013{
2014 int offset;
2015 __u16 crc = 0;
2016 __le32 le_group = cpu_to_le32(block_group);
2017 struct ext4_sb_info *sbi = EXT4_SB(sb);
2019
2020 if (ext4_has_metadata_csum(sbi->s_sb)) {
2021 /* Use new metadata_csum algorithm */
2022 __le16 save_csum;
2023 __u32 csum32;
2024
2025 save_csum = gdp->bg_checksum;
2026 gdp->bg_checksum = 0;
2027 csum32 = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&le_group,
2028 sizeof(le_group));
2029 csum32 = ext4_chksum(sbi, csum32, (__u8 *)gdp,
2030 sbi->s_desc_size);
2031 gdp->bg_checksum = save_csum;
2032
2033 crc = csum32 & 0xFFFF;
2034 goto out;
2035 }
2036
2037 /* old crc16 code */
2018
2019 if (ext4_has_metadata_csum(sbi->s_sb)) {
2020 /* Use new metadata_csum algorithm */
2021 __le16 save_csum;
2022 __u32 csum32;
2023
2024 save_csum = gdp->bg_checksum;
2025 gdp->bg_checksum = 0;
2026 csum32 = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&le_group,
2027 sizeof(le_group));
2028 csum32 = ext4_chksum(sbi, csum32, (__u8 *)gdp,
2029 sbi->s_desc_size);
2030 gdp->bg_checksum = save_csum;
2031
2032 crc = csum32 & 0xFFFF;
2033 goto out;
2034 }
2035
2036 /* old crc16 code */
2038 if (!(sbi->s_es->s_feature_ro_compat &
2039 cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)))
2037 if (!ext4_has_feature_gdt_csum(sb))
2040 return 0;
2041
2042 offset = offsetof(struct ext4_group_desc, bg_checksum);
2043
2044 crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid));
2045 crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group));
2046 crc = crc16(crc, (__u8 *)gdp, offset);
2047 offset += sizeof(gdp->bg_checksum); /* skip checksum */
2048 /* for checksum of struct ext4_group_desc do the rest...*/
2038 return 0;
2039
2040 offset = offsetof(struct ext4_group_desc, bg_checksum);
2041
2042 crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid));
2043 crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group));
2044 crc = crc16(crc, (__u8 *)gdp, offset);
2045 offset += sizeof(gdp->bg_checksum); /* skip checksum */
2046 /* for checksum of struct ext4_group_desc do the rest...*/
2049 if ((sbi->s_es->s_feature_incompat &
2050 cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT)) &&
2047 if (ext4_has_feature_64bit(sb) &&
2051 offset < le16_to_cpu(sbi->s_es->s_desc_size))
2052 crc = crc16(crc, (__u8 *)gdp + offset,
2053 le16_to_cpu(sbi->s_es->s_desc_size) -
2054 offset);
2055
2056out:
2057 return cpu_to_le16(crc);
2058}
2059
2060int ext4_group_desc_csum_verify(struct super_block *sb, __u32 block_group,
2061 struct ext4_group_desc *gdp)
2062{
2063 if (ext4_has_group_desc_csum(sb) &&
2048 offset < le16_to_cpu(sbi->s_es->s_desc_size))
2049 crc = crc16(crc, (__u8 *)gdp + offset,
2050 le16_to_cpu(sbi->s_es->s_desc_size) -
2051 offset);
2052
2053out:
2054 return cpu_to_le16(crc);
2055}
2056
2057int ext4_group_desc_csum_verify(struct super_block *sb, __u32 block_group,
2058 struct ext4_group_desc *gdp)
2059{
2060 if (ext4_has_group_desc_csum(sb) &&
2064 (gdp->bg_checksum != ext4_group_desc_csum(EXT4_SB(sb),
2065 block_group, gdp)))
2061 (gdp->bg_checksum != ext4_group_desc_csum(sb, block_group, gdp)))
2066 return 0;
2067
2068 return 1;
2069}
2070
2071void ext4_group_desc_csum_set(struct super_block *sb, __u32 block_group,
2072 struct ext4_group_desc *gdp)
2073{
2074 if (!ext4_has_group_desc_csum(sb))
2075 return;
2062 return 0;
2063
2064 return 1;
2065}
2066
2067void ext4_group_desc_csum_set(struct super_block *sb, __u32 block_group,
2068 struct ext4_group_desc *gdp)
2069{
2070 if (!ext4_has_group_desc_csum(sb))
2071 return;
2076 gdp->bg_checksum = ext4_group_desc_csum(EXT4_SB(sb), block_group, gdp);
2072 gdp->bg_checksum = ext4_group_desc_csum(sb, block_group, gdp);
2077}
2078
2079/* Called at mount-time, super-block is locked */
2080static int ext4_check_descriptors(struct super_block *sb,
2081 ext4_group_t *first_not_zeroed)
2082{
2083 struct ext4_sb_info *sbi = EXT4_SB(sb);
2084 ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
2085 ext4_fsblk_t last_block;
2086 ext4_fsblk_t block_bitmap;
2087 ext4_fsblk_t inode_bitmap;
2088 ext4_fsblk_t inode_table;
2089 int flexbg_flag = 0;
2090 ext4_group_t i, grp = sbi->s_groups_count;
2091
2073}
2074
2075/* Called at mount-time, super-block is locked */
2076static int ext4_check_descriptors(struct super_block *sb,
2077 ext4_group_t *first_not_zeroed)
2078{
2079 struct ext4_sb_info *sbi = EXT4_SB(sb);
2080 ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
2081 ext4_fsblk_t last_block;
2082 ext4_fsblk_t block_bitmap;
2083 ext4_fsblk_t inode_bitmap;
2084 ext4_fsblk_t inode_table;
2085 int flexbg_flag = 0;
2086 ext4_group_t i, grp = sbi->s_groups_count;
2087
2092 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
2088 if (ext4_has_feature_flex_bg(sb))
2093 flexbg_flag = 1;
2094
2095 ext4_debug("Checking group descriptors");
2096
2097 for (i = 0; i < sbi->s_groups_count; i++) {
2098 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL);
2099
2100 if (i == sbi->s_groups_count - 1 || flexbg_flag)

--- 27 unchanged lines hidden (view full) ---

2128 "Inode table for group %u not in group "
2129 "(block %llu)!", i, inode_table);
2130 return 0;
2131 }
2132 ext4_lock_group(sb, i);
2133 if (!ext4_group_desc_csum_verify(sb, i, gdp)) {
2134 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
2135 "Checksum for group %u failed (%u!=%u)",
2089 flexbg_flag = 1;
2090
2091 ext4_debug("Checking group descriptors");
2092
2093 for (i = 0; i < sbi->s_groups_count; i++) {
2094 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL);
2095
2096 if (i == sbi->s_groups_count - 1 || flexbg_flag)

--- 27 unchanged lines hidden (view full) ---

2124 "Inode table for group %u not in group "
2125 "(block %llu)!", i, inode_table);
2126 return 0;
2127 }
2128 ext4_lock_group(sb, i);
2129 if (!ext4_group_desc_csum_verify(sb, i, gdp)) {
2130 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
2131 "Checksum for group %u failed (%u!=%u)",
2136 i, le16_to_cpu(ext4_group_desc_csum(sbi, i,
2132 i, le16_to_cpu(ext4_group_desc_csum(sb, i,
2137 gdp)), le16_to_cpu(gdp->bg_checksum));
2138 if (!(sb->s_flags & MS_RDONLY)) {
2139 ext4_unlock_group(sb, i);
2140 return 0;
2141 }
2142 }
2143 ext4_unlock_group(sb, i);
2144 if (!flexbg_flag)

--- 246 unchanged lines hidden (view full) ---

2391 ext4_fsblk_t logical_sb_block, int nr)
2392{
2393 struct ext4_sb_info *sbi = EXT4_SB(sb);
2394 ext4_group_t bg, first_meta_bg;
2395 int has_super = 0;
2396
2397 first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg);
2398
2133 gdp)), le16_to_cpu(gdp->bg_checksum));
2134 if (!(sb->s_flags & MS_RDONLY)) {
2135 ext4_unlock_group(sb, i);
2136 return 0;
2137 }
2138 }
2139 ext4_unlock_group(sb, i);
2140 if (!flexbg_flag)

--- 246 unchanged lines hidden (view full) ---

2387 ext4_fsblk_t logical_sb_block, int nr)
2388{
2389 struct ext4_sb_info *sbi = EXT4_SB(sb);
2390 ext4_group_t bg, first_meta_bg;
2391 int has_super = 0;
2392
2393 first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg);
2394
2399 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_META_BG) ||
2400 nr < first_meta_bg)
2395 if (!ext4_has_feature_meta_bg(sb) || nr < first_meta_bg)
2401 return logical_sb_block + nr + 1;
2402 bg = sbi->s_desc_per_block * nr;
2403 if (ext4_bg_has_super(sb, bg))
2404 has_super = 1;
2405
2406 /*
2407 * If we have a meta_bg fs with 1k blocks, group 0's GDT is at
2408 * block 2, not 1. If s_first_data_block == 0 (bigalloc is enabled

--- 47 unchanged lines hidden (view full) ---

2456/*
2457 * Check whether this filesystem can be mounted based on
2458 * the features present and the RDONLY/RDWR mount requested.
2459 * Returns 1 if this filesystem can be mounted as requested,
2460 * 0 if it cannot be.
2461 */
2462static int ext4_feature_set_ok(struct super_block *sb, int readonly)
2463{
2396 return logical_sb_block + nr + 1;
2397 bg = sbi->s_desc_per_block * nr;
2398 if (ext4_bg_has_super(sb, bg))
2399 has_super = 1;
2400
2401 /*
2402 * If we have a meta_bg fs with 1k blocks, group 0's GDT is at
2403 * block 2, not 1. If s_first_data_block == 0 (bigalloc is enabled

--- 47 unchanged lines hidden (view full) ---

2451/*
2452 * Check whether this filesystem can be mounted based on
2453 * the features present and the RDONLY/RDWR mount requested.
2454 * Returns 1 if this filesystem can be mounted as requested,
2455 * 0 if it cannot be.
2456 */
2457static int ext4_feature_set_ok(struct super_block *sb, int readonly)
2458{
2464 if (EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP)) {
2459 if (ext4_has_unknown_ext4_incompat_features(sb)) {
2465 ext4_msg(sb, KERN_ERR,
2466 "Couldn't mount because of "
2467 "unsupported optional features (%x)",
2468 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) &
2469 ~EXT4_FEATURE_INCOMPAT_SUPP));
2470 return 0;
2471 }
2472
2473 if (readonly)
2474 return 1;
2475
2460 ext4_msg(sb, KERN_ERR,
2461 "Couldn't mount because of "
2462 "unsupported optional features (%x)",
2463 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) &
2464 ~EXT4_FEATURE_INCOMPAT_SUPP));
2465 return 0;
2466 }
2467
2468 if (readonly)
2469 return 1;
2470
2476 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_READONLY)) {
2471 if (ext4_has_feature_readonly(sb)) {
2477 ext4_msg(sb, KERN_INFO, "filesystem is read-only");
2478 sb->s_flags |= MS_RDONLY;
2479 return 1;
2480 }
2481
2482 /* Check that feature set is OK for a read-write mount */
2472 ext4_msg(sb, KERN_INFO, "filesystem is read-only");
2473 sb->s_flags |= MS_RDONLY;
2474 return 1;
2475 }
2476
2477 /* Check that feature set is OK for a read-write mount */
2483 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP)) {
2478 if (ext4_has_unknown_ext4_ro_compat_features(sb)) {
2484 ext4_msg(sb, KERN_ERR, "couldn't mount RDWR because of "
2485 "unsupported optional features (%x)",
2486 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) &
2487 ~EXT4_FEATURE_RO_COMPAT_SUPP));
2488 return 0;
2489 }
2490 /*
2491 * Large file size enabled file system can only be mounted
2492 * read-write on 32-bit systems if kernel is built with CONFIG_LBDAF
2493 */
2479 ext4_msg(sb, KERN_ERR, "couldn't mount RDWR because of "
2480 "unsupported optional features (%x)",
2481 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) &
2482 ~EXT4_FEATURE_RO_COMPAT_SUPP));
2483 return 0;
2484 }
2485 /*
2486 * Large file size enabled file system can only be mounted
2487 * read-write on 32-bit systems if kernel is built with CONFIG_LBDAF
2488 */
2494 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
2489 if (ext4_has_feature_huge_file(sb)) {
2495 if (sizeof(blkcnt_t) < sizeof(u64)) {
2496 ext4_msg(sb, KERN_ERR, "Filesystem with huge files "
2497 "cannot be mounted RDWR without "
2498 "CONFIG_LBDAF");
2499 return 0;
2500 }
2501 }
2490 if (sizeof(blkcnt_t) < sizeof(u64)) {
2491 ext4_msg(sb, KERN_ERR, "Filesystem with huge files "
2492 "cannot be mounted RDWR without "
2493 "CONFIG_LBDAF");
2494 return 0;
2495 }
2496 }
2502 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_BIGALLOC) &&
2503 !EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS)) {
2497 if (ext4_has_feature_bigalloc(sb) && !ext4_has_feature_extents(sb)) {
2504 ext4_msg(sb, KERN_ERR,
2505 "Can't support bigalloc feature without "
2506 "extents feature\n");
2507 return 0;
2508 }
2509
2510#ifndef CONFIG_QUOTA
2498 ext4_msg(sb, KERN_ERR,
2499 "Can't support bigalloc feature without "
2500 "extents feature\n");
2501 return 0;
2502 }
2503
2504#ifndef CONFIG_QUOTA
2511 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA) &&
2512 !readonly) {
2505 if (ext4_has_feature_quota(sb) && !readonly) {
2513 ext4_msg(sb, KERN_ERR,
2514 "Filesystem with quota feature cannot be mounted RDWR "
2515 "without CONFIG_QUOTA");
2516 return 0;
2517 }
2518#endif /* CONFIG_QUOTA */
2519 return 1;
2520}

--- 440 unchanged lines hidden (view full) ---

2961 char *buf)
2962{
2963 struct ext4_sb_info *sbi = EXT4_SB(sb);
2964 struct ext4_group_desc *gdp;
2965 ext4_fsblk_t first_block, last_block, b;
2966 ext4_group_t i, ngroups = ext4_get_groups_count(sb);
2967 int s, j, count = 0;
2968
2506 ext4_msg(sb, KERN_ERR,
2507 "Filesystem with quota feature cannot be mounted RDWR "
2508 "without CONFIG_QUOTA");
2509 return 0;
2510 }
2511#endif /* CONFIG_QUOTA */
2512 return 1;
2513}

--- 440 unchanged lines hidden (view full) ---

2954 char *buf)
2955{
2956 struct ext4_sb_info *sbi = EXT4_SB(sb);
2957 struct ext4_group_desc *gdp;
2958 ext4_fsblk_t first_block, last_block, b;
2959 ext4_group_t i, ngroups = ext4_get_groups_count(sb);
2960 int s, j, count = 0;
2961
2969 if (!EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_BIGALLOC))
2962 if (!ext4_has_feature_bigalloc(sb))
2970 return (ext4_bg_has_super(sb, grp) + ext4_bg_num_gdb(sb, grp) +
2971 sbi->s_itb_per_group + 2);
2972
2973 first_block = le32_to_cpu(sbi->s_es->s_first_data_block) +
2974 (grp * EXT4_BLOCKS_PER_GROUP(sb));
2975 last_block = first_block + EXT4_BLOCKS_PER_GROUP(sb) - 1;
2976 for (i = 0; i < ngroups; i++) {
2977 gdp = ext4_get_group_desc(sb, i, NULL);

--- 85 unchanged lines hidden (view full) ---

3063 struct ext4_sb_info *sbi = EXT4_SB(sb);
3064
3065 /*
3066 * There's no need to reserve anything when we aren't using extents.
3067 * The space estimates are exact, there are no unwritten extents,
3068 * hole punching doesn't need new metadata... This is needed especially
3069 * to keep ext2/3 backward compatibility.
3070 */
2963 return (ext4_bg_has_super(sb, grp) + ext4_bg_num_gdb(sb, grp) +
2964 sbi->s_itb_per_group + 2);
2965
2966 first_block = le32_to_cpu(sbi->s_es->s_first_data_block) +
2967 (grp * EXT4_BLOCKS_PER_GROUP(sb));
2968 last_block = first_block + EXT4_BLOCKS_PER_GROUP(sb) - 1;
2969 for (i = 0; i < ngroups; i++) {
2970 gdp = ext4_get_group_desc(sb, i, NULL);

--- 85 unchanged lines hidden (view full) ---

3056 struct ext4_sb_info *sbi = EXT4_SB(sb);
3057
3058 /*
3059 * There's no need to reserve anything when we aren't using extents.
3060 * The space estimates are exact, there are no unwritten extents,
3061 * hole punching doesn't need new metadata... This is needed especially
3062 * to keep ext2/3 backward compatibility.
3063 */
3071 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS))
3064 if (!ext4_has_feature_extents(sb))
3072 return;
3073 /*
3074 * By default we reserve 2% or 4096 clusters, whichever is smaller.
3075 * This should cover the situations where we can not afford to run
3076 * out of space like for example punch hole, or converting
3077 * unwritten extents in delalloc path. In most cases such
3078 * allocation would require 1, or 2 blocks, higher numbers are
3079 * very rare.

--- 82 unchanged lines hidden (view full) ---

3162 es = (struct ext4_super_block *) (bh->b_data + offset);
3163 sbi->s_es = es;
3164 sb->s_magic = le16_to_cpu(es->s_magic);
3165 if (sb->s_magic != EXT4_SUPER_MAGIC)
3166 goto cantfind_ext4;
3167 sbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written);
3168
3169 /* Warn if metadata_csum and gdt_csum are both set. */
3065 return;
3066 /*
3067 * By default we reserve 2% or 4096 clusters, whichever is smaller.
3068 * This should cover the situations where we can not afford to run
3069 * out of space like for example punch hole, or converting
3070 * unwritten extents in delalloc path. In most cases such
3071 * allocation would require 1, or 2 blocks, higher numbers are
3072 * very rare.

--- 82 unchanged lines hidden (view full) ---

3155 es = (struct ext4_super_block *) (bh->b_data + offset);
3156 sbi->s_es = es;
3157 sb->s_magic = le16_to_cpu(es->s_magic);
3158 if (sb->s_magic != EXT4_SUPER_MAGIC)
3159 goto cantfind_ext4;
3160 sbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written);
3161
3162 /* Warn if metadata_csum and gdt_csum are both set. */
3170 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
3171 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
3172 EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
3163 if (ext4_has_feature_metadata_csum(sb) &&
3164 ext4_has_feature_gdt_csum(sb))
3173 ext4_warning(sb, "metadata_csum and uninit_bg are "
3174 "redundant flags; please run fsck.");
3175
3176 /* Check for a known checksum algorithm */
3177 if (!ext4_verify_csum_type(sb, es)) {
3178 ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with "
3179 "unknown checksum algorithm.");
3180 silent = 1;
3181 goto cantfind_ext4;
3182 }
3183
3184 /* Load the checksum driver */
3165 ext4_warning(sb, "metadata_csum and uninit_bg are "
3166 "redundant flags; please run fsck.");
3167
3168 /* Check for a known checksum algorithm */
3169 if (!ext4_verify_csum_type(sb, es)) {
3170 ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with "
3171 "unknown checksum algorithm.");
3172 silent = 1;
3173 goto cantfind_ext4;
3174 }
3175
3176 /* Load the checksum driver */
3185 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
3186 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
3177 if (ext4_has_feature_metadata_csum(sb)) {
3187 sbi->s_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
3188 if (IS_ERR(sbi->s_chksum_driver)) {
3189 ext4_msg(sb, KERN_ERR, "Cannot load crc32c driver.");
3190 ret = PTR_ERR(sbi->s_chksum_driver);
3191 sbi->s_chksum_driver = NULL;
3192 goto failed_mount;
3193 }
3194 }
3195
3196 /* Check superblock checksum */
3197 if (!ext4_superblock_csum_verify(sb, es)) {
3198 ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with "
3199 "invalid superblock checksum. Run e2fsck?");
3200 silent = 1;
3201 ret = -EFSBADCRC;
3202 goto cantfind_ext4;
3203 }
3204
3205 /* Precompute checksum seed for all metadata */
3178 sbi->s_chksum_driver = crypto_alloc_shash("crc32c", 0, 0);
3179 if (IS_ERR(sbi->s_chksum_driver)) {
3180 ext4_msg(sb, KERN_ERR, "Cannot load crc32c driver.");
3181 ret = PTR_ERR(sbi->s_chksum_driver);
3182 sbi->s_chksum_driver = NULL;
3183 goto failed_mount;
3184 }
3185 }
3186
3187 /* Check superblock checksum */
3188 if (!ext4_superblock_csum_verify(sb, es)) {
3189 ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with "
3190 "invalid superblock checksum. Run e2fsck?");
3191 silent = 1;
3192 ret = -EFSBADCRC;
3193 goto cantfind_ext4;
3194 }
3195
3196 /* Precompute checksum seed for all metadata */
3206 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_CSUM_SEED))
3197 if (ext4_has_feature_csum_seed(sb))
3207 sbi->s_csum_seed = le32_to_cpu(es->s_checksum_seed);
3208 else if (ext4_has_metadata_csum(sb))
3209 sbi->s_csum_seed = ext4_chksum(sbi, ~0, es->s_uuid,
3210 sizeof(es->s_uuid));
3211
3212 /* Set defaults before we parse the mount options */
3213 def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
3214 set_opt(sb, INIT_INODE_TABLE);

--- 88 unchanged lines hidden (view full) ---

3303 } else {
3304 sb->s_iflags |= SB_I_CGROUPWB;
3305 }
3306
3307 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3308 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3309
3310 if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV &&
3198 sbi->s_csum_seed = le32_to_cpu(es->s_checksum_seed);
3199 else if (ext4_has_metadata_csum(sb))
3200 sbi->s_csum_seed = ext4_chksum(sbi, ~0, es->s_uuid,
3201 sizeof(es->s_uuid));
3202
3203 /* Set defaults before we parse the mount options */
3204 def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
3205 set_opt(sb, INIT_INODE_TABLE);

--- 88 unchanged lines hidden (view full) ---

3294 } else {
3295 sb->s_iflags |= SB_I_CGROUPWB;
3296 }
3297
3298 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3299 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3300
3301 if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV &&
3311 (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) ||
3312 EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
3313 EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U)))
3302 (ext4_has_compat_features(sb) ||
3303 ext4_has_ro_compat_features(sb) ||
3304 ext4_has_incompat_features(sb)))
3314 ext4_msg(sb, KERN_WARNING,
3315 "feature flags set on rev 0 fs, "
3316 "running e2fsck is recommended");
3317
3318 if (es->s_creator_os == cpu_to_le32(EXT4_OS_HURD)) {
3319 set_opt2(sb, HURD_COMPAT);
3305 ext4_msg(sb, KERN_WARNING,
3306 "feature flags set on rev 0 fs, "
3307 "running e2fsck is recommended");
3308
3309 if (es->s_creator_os == cpu_to_le32(EXT4_OS_HURD)) {
3310 set_opt2(sb, HURD_COMPAT);
3320 if (EXT4_HAS_INCOMPAT_FEATURE(sb,
3321 EXT4_FEATURE_INCOMPAT_64BIT)) {
3311 if (ext4_has_feature_64bit(sb)) {
3322 ext4_msg(sb, KERN_ERR,
3323 "The Hurd can't support 64-bit file systems");
3324 goto failed_mount;
3325 }
3326 }
3327
3328 if (IS_EXT2_SB(sb)) {
3329 if (ext2_feature_set_ok(sb))

--- 41 unchanged lines hidden (view full) ---

3371 }
3372 if (!sb->s_bdev->bd_disk->fops->direct_access) {
3373 ext4_msg(sb, KERN_ERR,
3374 "error: device does not support dax");
3375 goto failed_mount;
3376 }
3377 }
3378
3312 ext4_msg(sb, KERN_ERR,
3313 "The Hurd can't support 64-bit file systems");
3314 goto failed_mount;
3315 }
3316 }
3317
3318 if (IS_EXT2_SB(sb)) {
3319 if (ext2_feature_set_ok(sb))

--- 41 unchanged lines hidden (view full) ---

3361 }
3362 if (!sb->s_bdev->bd_disk->fops->direct_access) {
3363 ext4_msg(sb, KERN_ERR,
3364 "error: device does not support dax");
3365 goto failed_mount;
3366 }
3367 }
3368
3379 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_ENCRYPT) &&
3380 es->s_encryption_level) {
3369 if (ext4_has_feature_encrypt(sb) && es->s_encryption_level) {
3381 ext4_msg(sb, KERN_ERR, "Unsupported encryption level %d",
3382 es->s_encryption_level);
3383 goto failed_mount;
3384 }
3385
3386 if (sb->s_blocksize != blocksize) {
3387 /* Validate the filesystem blocksize */
3388 if (!sb_set_blocksize(sb, blocksize)) {

--- 15 unchanged lines hidden (view full) ---

3404 sbi->s_es = es;
3405 if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) {
3406 ext4_msg(sb, KERN_ERR,
3407 "Magic mismatch, very weird!");
3408 goto failed_mount;
3409 }
3410 }
3411
3370 ext4_msg(sb, KERN_ERR, "Unsupported encryption level %d",
3371 es->s_encryption_level);
3372 goto failed_mount;
3373 }
3374
3375 if (sb->s_blocksize != blocksize) {
3376 /* Validate the filesystem blocksize */
3377 if (!sb_set_blocksize(sb, blocksize)) {

--- 15 unchanged lines hidden (view full) ---

3393 sbi->s_es = es;
3394 if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) {
3395 ext4_msg(sb, KERN_ERR,
3396 "Magic mismatch, very weird!");
3397 goto failed_mount;
3398 }
3399 }
3400
3412 has_huge_files = EXT4_HAS_RO_COMPAT_FEATURE(sb,
3413 EXT4_FEATURE_RO_COMPAT_HUGE_FILE);
3401 has_huge_files = ext4_has_feature_huge_file(sb);
3414 sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits,
3415 has_huge_files);
3416 sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files);
3417
3418 if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) {
3419 sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE;
3420 sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO;
3421 } else {

--- 7 unchanged lines hidden (view full) ---

3429 sbi->s_inode_size);
3430 goto failed_mount;
3431 }
3432 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE)
3433 sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2);
3434 }
3435
3436 sbi->s_desc_size = le16_to_cpu(es->s_desc_size);
3402 sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits,
3403 has_huge_files);
3404 sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files);
3405
3406 if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) {
3407 sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE;
3408 sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO;
3409 } else {

--- 7 unchanged lines hidden (view full) ---

3417 sbi->s_inode_size);
3418 goto failed_mount;
3419 }
3420 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE)
3421 sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2);
3422 }
3423
3424 sbi->s_desc_size = le16_to_cpu(es->s_desc_size);
3437 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) {
3425 if (ext4_has_feature_64bit(sb)) {
3438 if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT ||
3439 sbi->s_desc_size > EXT4_MAX_DESC_SIZE ||
3440 !is_power_of_2(sbi->s_desc_size)) {
3441 ext4_msg(sb, KERN_ERR,
3442 "unsupported descriptor size %lu",
3443 sbi->s_desc_size);
3444 goto failed_mount;
3445 }

--- 14 unchanged lines hidden (view full) ---

3460 sbi->s_sbh = bh;
3461 sbi->s_mount_state = le16_to_cpu(es->s_state);
3462 sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb));
3463 sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb));
3464
3465 for (i = 0; i < 4; i++)
3466 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
3467 sbi->s_def_hash_version = es->s_def_hash_version;
3426 if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT ||
3427 sbi->s_desc_size > EXT4_MAX_DESC_SIZE ||
3428 !is_power_of_2(sbi->s_desc_size)) {
3429 ext4_msg(sb, KERN_ERR,
3430 "unsupported descriptor size %lu",
3431 sbi->s_desc_size);
3432 goto failed_mount;
3433 }

--- 14 unchanged lines hidden (view full) ---

3448 sbi->s_sbh = bh;
3449 sbi->s_mount_state = le16_to_cpu(es->s_state);
3450 sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb));
3451 sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb));
3452
3453 for (i = 0; i < 4; i++)
3454 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
3455 sbi->s_def_hash_version = es->s_def_hash_version;
3468 if (EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_DIR_INDEX)) {
3456 if (ext4_has_feature_dir_index(sb)) {
3469 i = le32_to_cpu(es->s_flags);
3470 if (i & EXT2_FLAGS_UNSIGNED_HASH)
3471 sbi->s_hash_unsigned = 3;
3472 else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) {
3473#ifdef __CHAR_UNSIGNED__
3474 if (!(sb->s_flags & MS_RDONLY))
3475 es->s_flags |=
3476 cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH);
3477 sbi->s_hash_unsigned = 3;
3478#else
3479 if (!(sb->s_flags & MS_RDONLY))
3480 es->s_flags |=
3481 cpu_to_le32(EXT2_FLAGS_SIGNED_HASH);
3482#endif
3483 }
3484 }
3485
3486 /* Handle clustersize */
3487 clustersize = BLOCK_SIZE << le32_to_cpu(es->s_log_cluster_size);
3457 i = le32_to_cpu(es->s_flags);
3458 if (i & EXT2_FLAGS_UNSIGNED_HASH)
3459 sbi->s_hash_unsigned = 3;
3460 else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) {
3461#ifdef __CHAR_UNSIGNED__
3462 if (!(sb->s_flags & MS_RDONLY))
3463 es->s_flags |=
3464 cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH);
3465 sbi->s_hash_unsigned = 3;
3466#else
3467 if (!(sb->s_flags & MS_RDONLY))
3468 es->s_flags |=
3469 cpu_to_le32(EXT2_FLAGS_SIGNED_HASH);
3470#endif
3471 }
3472 }
3473
3474 /* Handle clustersize */
3475 clustersize = BLOCK_SIZE << le32_to_cpu(es->s_log_cluster_size);
3488 has_bigalloc = EXT4_HAS_RO_COMPAT_FEATURE(sb,
3489 EXT4_FEATURE_RO_COMPAT_BIGALLOC);
3476 has_bigalloc = ext4_has_feature_bigalloc(sb);
3490 if (has_bigalloc) {
3491 if (clustersize < blocksize) {
3492 ext4_msg(sb, KERN_ERR,
3493 "cluster size (%d) smaller than "
3494 "block size (%d)", clustersize, blocksize);
3495 goto failed_mount;
3496 }
3497 sbi->s_cluster_bits = le32_to_cpu(es->s_log_cluster_size) -

--- 142 unchanged lines hidden (view full) ---

3640 /*
3641 * set up enough so that it can read an inode
3642 */
3643 sb->s_op = &ext4_sops;
3644 sb->s_export_op = &ext4_export_ops;
3645 sb->s_xattr = ext4_xattr_handlers;
3646#ifdef CONFIG_QUOTA
3647 sb->dq_op = &ext4_quota_operations;
3477 if (has_bigalloc) {
3478 if (clustersize < blocksize) {
3479 ext4_msg(sb, KERN_ERR,
3480 "cluster size (%d) smaller than "
3481 "block size (%d)", clustersize, blocksize);
3482 goto failed_mount;
3483 }
3484 sbi->s_cluster_bits = le32_to_cpu(es->s_log_cluster_size) -

--- 142 unchanged lines hidden (view full) ---

3627 /*
3628 * set up enough so that it can read an inode
3629 */
3630 sb->s_op = &ext4_sops;
3631 sb->s_export_op = &ext4_export_ops;
3632 sb->s_xattr = ext4_xattr_handlers;
3633#ifdef CONFIG_QUOTA
3634 sb->dq_op = &ext4_quota_operations;
3648 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA))
3635 if (ext4_has_feature_quota(sb))
3649 sb->s_qcop = &dquot_quotactl_sysfile_ops;
3650 else
3651 sb->s_qcop = &ext4_qctl_operations;
3652 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
3653#endif
3654 memcpy(sb->s_uuid, es->s_uuid, sizeof(es->s_uuid));
3655
3656 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
3657 mutex_init(&sbi->s_orphan_lock);
3658
3659 sb->s_root = NULL;
3660
3661 needs_recovery = (es->s_last_orphan != 0 ||
3636 sb->s_qcop = &dquot_quotactl_sysfile_ops;
3637 else
3638 sb->s_qcop = &ext4_qctl_operations;
3639 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
3640#endif
3641 memcpy(sb->s_uuid, es->s_uuid, sizeof(es->s_uuid));
3642
3643 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
3644 mutex_init(&sbi->s_orphan_lock);
3645
3646 sb->s_root = NULL;
3647
3648 needs_recovery = (es->s_last_orphan != 0 ||
3662 EXT4_HAS_INCOMPAT_FEATURE(sb,
3663 EXT4_FEATURE_INCOMPAT_RECOVER));
3649 ext4_has_feature_journal_needs_recovery(sb));
3664
3650
3665 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_MMP) &&
3666 !(sb->s_flags & MS_RDONLY))
3651 if (ext4_has_feature_mmp(sb) && !(sb->s_flags & MS_RDONLY))
3667 if (ext4_multi_mount_protect(sb, le64_to_cpu(es->s_mmp_block)))
3668 goto failed_mount3a;
3669
3670 /*
3671 * The first inode we look at is the journal inode. Don't try
3672 * root first: it may be modified in the journal!
3673 */
3652 if (ext4_multi_mount_protect(sb, le64_to_cpu(es->s_mmp_block)))
3653 goto failed_mount3a;
3654
3655 /*
3656 * The first inode we look at is the journal inode. Don't try
3657 * root first: it may be modified in the journal!
3658 */
3674 if (!test_opt(sb, NOLOAD) &&
3675 EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) {
3659 if (!test_opt(sb, NOLOAD) && ext4_has_feature_journal(sb)) {
3676 if (ext4_load_journal(sb, es, journal_devnum))
3677 goto failed_mount3a;
3678 } else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) &&
3660 if (ext4_load_journal(sb, es, journal_devnum))
3661 goto failed_mount3a;
3662 } else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) &&
3679 EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
3663 ext4_has_feature_journal_needs_recovery(sb)) {
3680 ext4_msg(sb, KERN_ERR, "required journal recovery "
3681 "suppressed and not mounted read-only");
3682 goto failed_mount_wq;
3683 } else {
3684 clear_opt(sb, DATA_FLAGS);
3685 sbi->s_journal = NULL;
3686 needs_recovery = 0;
3687 goto no_journal;
3688 }
3689
3664 ext4_msg(sb, KERN_ERR, "required journal recovery "
3665 "suppressed and not mounted read-only");
3666 goto failed_mount_wq;
3667 } else {
3668 clear_opt(sb, DATA_FLAGS);
3669 sbi->s_journal = NULL;
3670 needs_recovery = 0;
3671 goto no_journal;
3672 }
3673
3690 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT) &&
3674 if (ext4_has_feature_64bit(sb) &&
3691 !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,
3692 JBD2_FEATURE_INCOMPAT_64BIT)) {
3693 ext4_msg(sb, KERN_ERR, "Failed to set 64-bit journal feature");
3694 goto failed_mount_wq;
3695 }
3696
3697 if (!set_journal_csum_feature_set(sb)) {
3698 ext4_msg(sb, KERN_ERR, "Failed to set journal checksum "

--- 35 unchanged lines hidden (view full) ---

3734 if (ext4_mballoc_ready) {
3735 sbi->s_mb_cache = ext4_xattr_create_cache(sb->s_id);
3736 if (!sbi->s_mb_cache) {
3737 ext4_msg(sb, KERN_ERR, "Failed to create an mb_cache");
3738 goto failed_mount_wq;
3739 }
3740 }
3741
3675 !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,
3676 JBD2_FEATURE_INCOMPAT_64BIT)) {
3677 ext4_msg(sb, KERN_ERR, "Failed to set 64-bit journal feature");
3678 goto failed_mount_wq;
3679 }
3680
3681 if (!set_journal_csum_feature_set(sb)) {
3682 ext4_msg(sb, KERN_ERR, "Failed to set journal checksum "

--- 35 unchanged lines hidden (view full) ---

3718 if (ext4_mballoc_ready) {
3719 sbi->s_mb_cache = ext4_xattr_create_cache(sb->s_id);
3720 if (!sbi->s_mb_cache) {
3721 ext4_msg(sb, KERN_ERR, "Failed to create an mb_cache");
3722 goto failed_mount_wq;
3723 }
3724 }
3725
3742 if ((DUMMY_ENCRYPTION_ENABLED(sbi) ||
3743 EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_ENCRYPT)) &&
3726 if ((DUMMY_ENCRYPTION_ENABLED(sbi) || ext4_has_feature_encrypt(sb)) &&
3744 (blocksize != PAGE_CACHE_SIZE)) {
3745 ext4_msg(sb, KERN_ERR,
3746 "Unsupported blocksize for fs encryption");
3747 goto failed_mount_wq;
3748 }
3749
3727 (blocksize != PAGE_CACHE_SIZE)) {
3728 ext4_msg(sb, KERN_ERR,
3729 "Unsupported blocksize for fs encryption");
3730 goto failed_mount_wq;
3731 }
3732
3750 if (DUMMY_ENCRYPTION_ENABLED(sbi) &&
3751 !(sb->s_flags & MS_RDONLY) &&
3752 !EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_ENCRYPT)) {
3753 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_ENCRYPT);
3733 if (DUMMY_ENCRYPTION_ENABLED(sbi) && !(sb->s_flags & MS_RDONLY) &&
3734 !ext4_has_feature_encrypt(sb)) {
3735 ext4_set_feature_encrypt(sb);
3754 ext4_commit_super(sb, 1);
3755 }
3756
3757 /*
3758 * Get the # of file system overhead blocks from the
3759 * superblock if present.
3760 */
3761 if (es->s_overhead_clusters)

--- 42 unchanged lines hidden (view full) ---

3804
3805 if (ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY))
3806 sb->s_flags |= MS_RDONLY;
3807
3808 /* determine the minimum size of new large inodes, if present */
3809 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
3810 sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
3811 EXT4_GOOD_OLD_INODE_SIZE;
3736 ext4_commit_super(sb, 1);
3737 }
3738
3739 /*
3740 * Get the # of file system overhead blocks from the
3741 * superblock if present.
3742 */
3743 if (es->s_overhead_clusters)

--- 42 unchanged lines hidden (view full) ---

3786
3787 if (ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY))
3788 sb->s_flags |= MS_RDONLY;
3789
3790 /* determine the minimum size of new large inodes, if present */
3791 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
3792 sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
3793 EXT4_GOOD_OLD_INODE_SIZE;
3812 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
3813 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)) {
3794 if (ext4_has_feature_extra_isize(sb)) {
3814 if (sbi->s_want_extra_isize <
3815 le16_to_cpu(es->s_want_extra_isize))
3816 sbi->s_want_extra_isize =
3817 le16_to_cpu(es->s_want_extra_isize);
3818 if (sbi->s_want_extra_isize <
3819 le16_to_cpu(es->s_min_extra_isize))
3820 sbi->s_want_extra_isize =
3821 le16_to_cpu(es->s_min_extra_isize);

--- 42 unchanged lines hidden (view full) ---

3864 if (!err)
3865 err = percpu_counter_init(&sbi->s_dirtyclusters_counter, 0,
3866 GFP_KERNEL);
3867 if (err) {
3868 ext4_msg(sb, KERN_ERR, "insufficient memory");
3869 goto failed_mount6;
3870 }
3871
3795 if (sbi->s_want_extra_isize <
3796 le16_to_cpu(es->s_want_extra_isize))
3797 sbi->s_want_extra_isize =
3798 le16_to_cpu(es->s_want_extra_isize);
3799 if (sbi->s_want_extra_isize <
3800 le16_to_cpu(es->s_min_extra_isize))
3801 sbi->s_want_extra_isize =
3802 le16_to_cpu(es->s_min_extra_isize);

--- 42 unchanged lines hidden (view full) ---

3845 if (!err)
3846 err = percpu_counter_init(&sbi->s_dirtyclusters_counter, 0,
3847 GFP_KERNEL);
3848 if (err) {
3849 ext4_msg(sb, KERN_ERR, "insufficient memory");
3850 goto failed_mount6;
3851 }
3852
3872 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
3853 if (ext4_has_feature_flex_bg(sb))
3873 if (!ext4_fill_flex_info(sb)) {
3874 ext4_msg(sb, KERN_ERR,
3875 "unable to initialize "
3876 "flex_bg meta info!");
3877 goto failed_mount6;
3878 }
3879
3880 err = ext4_register_li_request(sb, first_not_zeroed);
3881 if (err)
3882 goto failed_mount6;
3883
3884 err = ext4_register_sysfs(sb);
3885 if (err)
3886 goto failed_mount7;
3887
3888#ifdef CONFIG_QUOTA
3889 /* Enable quota usage during mount. */
3854 if (!ext4_fill_flex_info(sb)) {
3855 ext4_msg(sb, KERN_ERR,
3856 "unable to initialize "
3857 "flex_bg meta info!");
3858 goto failed_mount6;
3859 }
3860
3861 err = ext4_register_li_request(sb, first_not_zeroed);
3862 if (err)
3863 goto failed_mount6;
3864
3865 err = ext4_register_sysfs(sb);
3866 if (err)
3867 goto failed_mount7;
3868
3869#ifdef CONFIG_QUOTA
3870 /* Enable quota usage during mount. */
3890 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA) &&
3891 !(sb->s_flags & MS_RDONLY)) {
3871 if (ext4_has_feature_quota(sb) && !(sb->s_flags & MS_RDONLY)) {
3892 err = ext4_enable_quotas(sb);
3893 if (err)
3894 goto failed_mount8;
3895 }
3896#endif /* CONFIG_QUOTA */
3897
3898 EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
3899 ext4_orphan_cleanup(sb, es);

--- 124 unchanged lines hidden (view full) ---

4024}
4025
4026static journal_t *ext4_get_journal(struct super_block *sb,
4027 unsigned int journal_inum)
4028{
4029 struct inode *journal_inode;
4030 journal_t *journal;
4031
3872 err = ext4_enable_quotas(sb);
3873 if (err)
3874 goto failed_mount8;
3875 }
3876#endif /* CONFIG_QUOTA */
3877
3878 EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
3879 ext4_orphan_cleanup(sb, es);

--- 124 unchanged lines hidden (view full) ---

4004}
4005
4006static journal_t *ext4_get_journal(struct super_block *sb,
4007 unsigned int journal_inum)
4008{
4009 struct inode *journal_inode;
4010 journal_t *journal;
4011
4032 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
4012 BUG_ON(!ext4_has_feature_journal(sb));
4033
4034 /* First, test for the existence of a valid inode on disk. Bad
4035 * things happen if we iget() an unused inode, as the subsequent
4036 * iput() will try to delete it. */
4037
4038 journal_inode = ext4_iget(sb, journal_inum);
4039 if (IS_ERR(journal_inode)) {
4040 ext4_msg(sb, KERN_ERR, "no journal found");

--- 33 unchanged lines hidden (view full) ---

4074 ext4_fsblk_t start;
4075 ext4_fsblk_t len;
4076 int hblock, blocksize;
4077 ext4_fsblk_t sb_block;
4078 unsigned long offset;
4079 struct ext4_super_block *es;
4080 struct block_device *bdev;
4081
4013
4014 /* First, test for the existence of a valid inode on disk. Bad
4015 * things happen if we iget() an unused inode, as the subsequent
4016 * iput() will try to delete it. */
4017
4018 journal_inode = ext4_iget(sb, journal_inum);
4019 if (IS_ERR(journal_inode)) {
4020 ext4_msg(sb, KERN_ERR, "no journal found");

--- 33 unchanged lines hidden (view full) ---

4054 ext4_fsblk_t start;
4055 ext4_fsblk_t len;
4056 int hblock, blocksize;
4057 ext4_fsblk_t sb_block;
4058 unsigned long offset;
4059 struct ext4_super_block *es;
4060 struct block_device *bdev;
4061
4082 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
4062 BUG_ON(!ext4_has_feature_journal(sb));
4083
4084 bdev = ext4_blkdev_get(j_dev, sb);
4085 if (bdev == NULL)
4086 return NULL;
4087
4088 blocksize = sb->s_blocksize;
4089 hblock = bdev_logical_block_size(bdev);
4090 if (blocksize < hblock) {

--- 75 unchanged lines hidden (view full) ---

4166 unsigned long journal_devnum)
4167{
4168 journal_t *journal;
4169 unsigned int journal_inum = le32_to_cpu(es->s_journal_inum);
4170 dev_t journal_dev;
4171 int err = 0;
4172 int really_read_only;
4173
4063
4064 bdev = ext4_blkdev_get(j_dev, sb);
4065 if (bdev == NULL)
4066 return NULL;
4067
4068 blocksize = sb->s_blocksize;
4069 hblock = bdev_logical_block_size(bdev);
4070 if (blocksize < hblock) {

--- 75 unchanged lines hidden (view full) ---

4146 unsigned long journal_devnum)
4147{
4148 journal_t *journal;
4149 unsigned int journal_inum = le32_to_cpu(es->s_journal_inum);
4150 dev_t journal_dev;
4151 int err = 0;
4152 int really_read_only;
4153
4174 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
4154 BUG_ON(!ext4_has_feature_journal(sb));
4175
4176 if (journal_devnum &&
4177 journal_devnum != le32_to_cpu(es->s_journal_dev)) {
4178 ext4_msg(sb, KERN_INFO, "external journal device major/minor "
4179 "numbers have changed");
4180 journal_dev = new_decode_dev(journal_devnum);
4181 } else
4182 journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev));
4183
4184 really_read_only = bdev_read_only(sb->s_bdev);
4185
4186 /*
4187 * Are we loading a blank journal or performing recovery after a
4188 * crash? For recovery, we need to check in advance whether we
4189 * can get read-write access to the device.
4190 */
4155
4156 if (journal_devnum &&
4157 journal_devnum != le32_to_cpu(es->s_journal_dev)) {
4158 ext4_msg(sb, KERN_INFO, "external journal device major/minor "
4159 "numbers have changed");
4160 journal_dev = new_decode_dev(journal_devnum);
4161 } else
4162 journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev));
4163
4164 really_read_only = bdev_read_only(sb->s_bdev);
4165
4166 /*
4167 * Are we loading a blank journal or performing recovery after a
4168 * crash? For recovery, we need to check in advance whether we
4169 * can get read-write access to the device.
4170 */
4191 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
4171 if (ext4_has_feature_journal_needs_recovery(sb)) {
4192 if (sb->s_flags & MS_RDONLY) {
4193 ext4_msg(sb, KERN_INFO, "INFO: recovery "
4194 "required on readonly filesystem");
4195 if (really_read_only) {
4196 ext4_msg(sb, KERN_ERR, "write access "
4197 "unavailable, cannot proceed");
4198 return -EROFS;
4199 }

--- 14 unchanged lines hidden (view full) ---

4214 } else {
4215 if (!(journal = ext4_get_dev_journal(sb, journal_dev)))
4216 return -EINVAL;
4217 }
4218
4219 if (!(journal->j_flags & JBD2_BARRIER))
4220 ext4_msg(sb, KERN_INFO, "barriers disabled");
4221
4172 if (sb->s_flags & MS_RDONLY) {
4173 ext4_msg(sb, KERN_INFO, "INFO: recovery "
4174 "required on readonly filesystem");
4175 if (really_read_only) {
4176 ext4_msg(sb, KERN_ERR, "write access "
4177 "unavailable, cannot proceed");
4178 return -EROFS;
4179 }

--- 14 unchanged lines hidden (view full) ---

4194 } else {
4195 if (!(journal = ext4_get_dev_journal(sb, journal_dev)))
4196 return -EINVAL;
4197 }
4198
4199 if (!(journal->j_flags & JBD2_BARRIER))
4200 ext4_msg(sb, KERN_INFO, "barriers disabled");
4201
4222 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER))
4202 if (!ext4_has_feature_journal_needs_recovery(sb))
4223 err = jbd2_journal_wipe(journal, !really_read_only);
4224 if (!err) {
4225 char *save = kmalloc(EXT4_S_ERR_LEN, GFP_KERNEL);
4226 if (save)
4227 memcpy(save, ((char *) es) +
4228 EXT4_S_ERR_START, EXT4_S_ERR_LEN);
4229 err = jbd2_journal_load(journal);
4230 if (save)

--- 97 unchanged lines hidden (view full) ---

4328 * remounting) the filesystem readonly, then we will end up with a
4329 * consistent fs on disk. Record that fact.
4330 */
4331static void ext4_mark_recovery_complete(struct super_block *sb,
4332 struct ext4_super_block *es)
4333{
4334 journal_t *journal = EXT4_SB(sb)->s_journal;
4335
4203 err = jbd2_journal_wipe(journal, !really_read_only);
4204 if (!err) {
4205 char *save = kmalloc(EXT4_S_ERR_LEN, GFP_KERNEL);
4206 if (save)
4207 memcpy(save, ((char *) es) +
4208 EXT4_S_ERR_START, EXT4_S_ERR_LEN);
4209 err = jbd2_journal_load(journal);
4210 if (save)

--- 97 unchanged lines hidden (view full) ---

4308 * remounting) the filesystem readonly, then we will end up with a
4309 * consistent fs on disk. Record that fact.
4310 */
4311static void ext4_mark_recovery_complete(struct super_block *sb,
4312 struct ext4_super_block *es)
4313{
4314 journal_t *journal = EXT4_SB(sb)->s_journal;
4315
4336 if (!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) {
4316 if (!ext4_has_feature_journal(sb)) {
4337 BUG_ON(journal != NULL);
4338 return;
4339 }
4340 jbd2_journal_lock_updates(journal);
4341 if (jbd2_journal_flush(journal) < 0)
4342 goto out;
4343
4317 BUG_ON(journal != NULL);
4318 return;
4319 }
4320 jbd2_journal_lock_updates(journal);
4321 if (jbd2_journal_flush(journal) < 0)
4322 goto out;
4323
4344 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) &&
4324 if (ext4_has_feature_journal_needs_recovery(sb) &&
4345 sb->s_flags & MS_RDONLY) {
4325 sb->s_flags & MS_RDONLY) {
4346 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
4326 ext4_clear_feature_journal_needs_recovery(sb);
4347 ext4_commit_super(sb, 1);
4348 }
4349
4350out:
4351 jbd2_journal_unlock_updates(journal);
4352}
4353
4354/*
4355 * If we are mounting (or read-write remounting) a filesystem whose journal
4356 * has recorded an error from a previous lifetime, move that error to the
4357 * main filesystem now.
4358 */
4359static void ext4_clear_journal_err(struct super_block *sb,
4360 struct ext4_super_block *es)
4361{
4362 journal_t *journal;
4363 int j_errno;
4364 const char *errstr;
4365
4327 ext4_commit_super(sb, 1);
4328 }
4329
4330out:
4331 jbd2_journal_unlock_updates(journal);
4332}
4333
4334/*
4335 * If we are mounting (or read-write remounting) a filesystem whose journal
4336 * has recorded an error from a previous lifetime, move that error to the
4337 * main filesystem now.
4338 */
4339static void ext4_clear_journal_err(struct super_block *sb,
4340 struct ext4_super_block *es)
4341{
4342 journal_t *journal;
4343 int j_errno;
4344 const char *errstr;
4345
4366 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
4346 BUG_ON(!ext4_has_feature_journal(sb));
4367
4368 journal = EXT4_SB(sb)->s_journal;
4369
4370 /*
4371 * Now check for any error status which may have been recorded in the
4372 * journal by a prior ext4_error() or ext4_abort()
4373 */
4374

--- 98 unchanged lines hidden (view full) ---

4473 * Don't clear the needs_recovery flag if we failed to
4474 * flush the journal.
4475 */
4476 error = jbd2_journal_flush(journal);
4477 if (error < 0)
4478 goto out;
4479
4480 /* Journal blocked and flushed, clear needs_recovery flag. */
4347
4348 journal = EXT4_SB(sb)->s_journal;
4349
4350 /*
4351 * Now check for any error status which may have been recorded in the
4352 * journal by a prior ext4_error() or ext4_abort()
4353 */
4354

--- 98 unchanged lines hidden (view full) ---

4453 * Don't clear the needs_recovery flag if we failed to
4454 * flush the journal.
4455 */
4456 error = jbd2_journal_flush(journal);
4457 if (error < 0)
4458 goto out;
4459
4460 /* Journal blocked and flushed, clear needs_recovery flag. */
4481 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
4461 ext4_clear_feature_journal_needs_recovery(sb);
4482 }
4483
4484 error = ext4_commit_super(sb, 1);
4485out:
4486 if (journal)
4487 /* we rely on upper layer to stop further updates */
4488 jbd2_journal_unlock_updates(journal);
4489 return error;

--- 5 unchanged lines hidden (view full) ---

4495 */
4496static int ext4_unfreeze(struct super_block *sb)
4497{
4498 if (sb->s_flags & MS_RDONLY)
4499 return 0;
4500
4501 if (EXT4_SB(sb)->s_journal) {
4502 /* Reset the needs_recovery flag before the fs is unlocked. */
4462 }
4463
4464 error = ext4_commit_super(sb, 1);
4465out:
4466 if (journal)
4467 /* we rely on upper layer to stop further updates */
4468 jbd2_journal_unlock_updates(journal);
4469 return error;

--- 5 unchanged lines hidden (view full) ---

4475 */
4476static int ext4_unfreeze(struct super_block *sb)
4477{
4478 if (sb->s_flags & MS_RDONLY)
4479 return 0;
4480
4481 if (EXT4_SB(sb)->s_journal) {
4482 /* Reset the needs_recovery flag before the fs is unlocked. */
4503 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
4483 ext4_set_feature_journal_needs_recovery(sb);
4504 }
4505
4506 ext4_commit_super(sb, 1);
4507 return 0;
4508}
4509
4510/*
4511 * Structure to save mount options for ext4_remount's benefit

--- 136 unchanged lines hidden (view full) ---

4648 if (!(es->s_state & cpu_to_le16(EXT4_VALID_FS)) &&
4649 (sbi->s_mount_state & EXT4_VALID_FS))
4650 es->s_state = cpu_to_le16(sbi->s_mount_state);
4651
4652 if (sbi->s_journal)
4653 ext4_mark_recovery_complete(sb, es);
4654 } else {
4655 /* Make sure we can mount this feature set readwrite */
4484 }
4485
4486 ext4_commit_super(sb, 1);
4487 return 0;
4488}
4489
4490/*
4491 * Structure to save mount options for ext4_remount's benefit

--- 136 unchanged lines hidden (view full) ---

4628 if (!(es->s_state & cpu_to_le16(EXT4_VALID_FS)) &&
4629 (sbi->s_mount_state & EXT4_VALID_FS))
4630 es->s_state = cpu_to_le16(sbi->s_mount_state);
4631
4632 if (sbi->s_journal)
4633 ext4_mark_recovery_complete(sb, es);
4634 } else {
4635 /* Make sure we can mount this feature set readwrite */
4656 if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
4657 EXT4_FEATURE_RO_COMPAT_READONLY) ||
4636 if (ext4_has_feature_readonly(sb) ||
4658 !ext4_feature_set_ok(sb, 0)) {
4659 err = -EROFS;
4660 goto restore_opts;
4661 }
4662 /*
4663 * Make sure the group descriptor checksums
4664 * are sane. If they aren't, refuse to remount r/w.
4665 */
4666 for (g = 0; g < sbi->s_groups_count; g++) {
4667 struct ext4_group_desc *gdp =
4668 ext4_get_group_desc(sb, g, NULL);
4669
4670 if (!ext4_group_desc_csum_verify(sb, g, gdp)) {
4671 ext4_msg(sb, KERN_ERR,
4672 "ext4_remount: Checksum for group %u failed (%u!=%u)",
4637 !ext4_feature_set_ok(sb, 0)) {
4638 err = -EROFS;
4639 goto restore_opts;
4640 }
4641 /*
4642 * Make sure the group descriptor checksums
4643 * are sane. If they aren't, refuse to remount r/w.
4644 */
4645 for (g = 0; g < sbi->s_groups_count; g++) {
4646 struct ext4_group_desc *gdp =
4647 ext4_get_group_desc(sb, g, NULL);
4648
4649 if (!ext4_group_desc_csum_verify(sb, g, gdp)) {
4650 ext4_msg(sb, KERN_ERR,
4651 "ext4_remount: Checksum for group %u failed (%u!=%u)",
4673 g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)),
4652 g, le16_to_cpu(ext4_group_desc_csum(sb, g, gdp)),
4674 le16_to_cpu(gdp->bg_checksum));
4675 err = -EFSBADCRC;
4676 goto restore_opts;
4677 }
4678 }
4679
4680 /*
4681 * If we have an unprocessed orphan list hanging

--- 15 unchanged lines hidden (view full) ---

4697 * been changed by e2fsck since we originally mounted
4698 * the partition.)
4699 */
4700 if (sbi->s_journal)
4701 ext4_clear_journal_err(sb, es);
4702 sbi->s_mount_state = le16_to_cpu(es->s_state);
4703 if (!ext4_setup_super(sb, es, 0))
4704 sb->s_flags &= ~MS_RDONLY;
4653 le16_to_cpu(gdp->bg_checksum));
4654 err = -EFSBADCRC;
4655 goto restore_opts;
4656 }
4657 }
4658
4659 /*
4660 * If we have an unprocessed orphan list hanging

--- 15 unchanged lines hidden (view full) ---

4676 * been changed by e2fsck since we originally mounted
4677 * the partition.)
4678 */
4679 if (sbi->s_journal)
4680 ext4_clear_journal_err(sb, es);
4681 sbi->s_mount_state = le16_to_cpu(es->s_state);
4682 if (!ext4_setup_super(sb, es, 0))
4683 sb->s_flags &= ~MS_RDONLY;
4705 if (EXT4_HAS_INCOMPAT_FEATURE(sb,
4706 EXT4_FEATURE_INCOMPAT_MMP))
4684 if (ext4_has_feature_mmp(sb))
4707 if (ext4_multi_mount_protect(sb,
4708 le64_to_cpu(es->s_mmp_block))) {
4709 err = -EROFS;
4710 goto restore_opts;
4711 }
4712 enable_quota = 1;
4713 }
4714 }

--- 16 unchanged lines hidden (view full) ---

4731
4732#ifdef CONFIG_QUOTA
4733 /* Release old quota file names */
4734 for (i = 0; i < EXT4_MAXQUOTAS; i++)
4735 kfree(old_opts.s_qf_names[i]);
4736 if (enable_quota) {
4737 if (sb_any_quota_suspended(sb))
4738 dquot_resume(sb, -1);
4685 if (ext4_multi_mount_protect(sb,
4686 le64_to_cpu(es->s_mmp_block))) {
4687 err = -EROFS;
4688 goto restore_opts;
4689 }
4690 enable_quota = 1;
4691 }
4692 }

--- 16 unchanged lines hidden (view full) ---

4709
4710#ifdef CONFIG_QUOTA
4711 /* Release old quota file names */
4712 for (i = 0; i < EXT4_MAXQUOTAS; i++)
4713 kfree(old_opts.s_qf_names[i]);
4714 if (enable_quota) {
4715 if (sb_any_quota_suspended(sb))
4716 dquot_resume(sb, -1);
4739 else if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
4740 EXT4_FEATURE_RO_COMPAT_QUOTA)) {
4717 else if (ext4_has_feature_quota(sb)) {
4741 err = ext4_enable_quotas(sb);
4742 if (err)
4743 goto restore_opts;
4744 }
4745 }
4746#endif
4747
4748 *flags = (*flags & ~MS_LAZYTIME) | (sb->s_flags & MS_LAZYTIME);

--- 127 unchanged lines hidden (view full) ---

4876}
4877
4878static int ext4_mark_dquot_dirty(struct dquot *dquot)
4879{
4880 struct super_block *sb = dquot->dq_sb;
4881 struct ext4_sb_info *sbi = EXT4_SB(sb);
4882
4883 /* Are we journaling quotas? */
4718 err = ext4_enable_quotas(sb);
4719 if (err)
4720 goto restore_opts;
4721 }
4722 }
4723#endif
4724
4725 *flags = (*flags & ~MS_LAZYTIME) | (sb->s_flags & MS_LAZYTIME);

--- 127 unchanged lines hidden (view full) ---

4853}
4854
4855static int ext4_mark_dquot_dirty(struct dquot *dquot)
4856{
4857 struct super_block *sb = dquot->dq_sb;
4858 struct ext4_sb_info *sbi = EXT4_SB(sb);
4859
4860 /* Are we journaling quotas? */
4884 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA) ||
4861 if (ext4_has_feature_quota(sb) ||
4885 sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) {
4886 dquot_mark_dquot_dirty(dquot);
4887 return ext4_write_dquot(dquot);
4888 } else {
4889 return dquot_mark_dquot_dirty(dquot);
4890 }
4891}
4892

--- 71 unchanged lines hidden (view full) ---

4964{
4965 int err;
4966 struct inode *qf_inode;
4967 unsigned long qf_inums[EXT4_MAXQUOTAS] = {
4968 le32_to_cpu(EXT4_SB(sb)->s_es->s_usr_quota_inum),
4969 le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum)
4970 };
4971
4862 sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) {
4863 dquot_mark_dquot_dirty(dquot);
4864 return ext4_write_dquot(dquot);
4865 } else {
4866 return dquot_mark_dquot_dirty(dquot);
4867 }
4868}
4869

--- 71 unchanged lines hidden (view full) ---

4941{
4942 int err;
4943 struct inode *qf_inode;
4944 unsigned long qf_inums[EXT4_MAXQUOTAS] = {
4945 le32_to_cpu(EXT4_SB(sb)->s_es->s_usr_quota_inum),
4946 le32_to_cpu(EXT4_SB(sb)->s_es->s_grp_quota_inum)
4947 };
4948
4972 BUG_ON(!EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_QUOTA));
4949 BUG_ON(!ext4_has_feature_quota(sb));
4973
4974 if (!qf_inums[type])
4975 return -EPERM;
4976
4977 qf_inode = ext4_iget(sb, qf_inums[type]);
4978 if (IS_ERR(qf_inode)) {
4979 ext4_error(sb, "Bad quota inode # %lu", qf_inums[type]);
4980 return PTR_ERR(qf_inode);

--- 177 unchanged lines hidden (view full) ---

5158
5159static inline void unregister_as_ext2(void)
5160{
5161 unregister_filesystem(&ext2_fs_type);
5162}
5163
5164static inline int ext2_feature_set_ok(struct super_block *sb)
5165{
4950
4951 if (!qf_inums[type])
4952 return -EPERM;
4953
4954 qf_inode = ext4_iget(sb, qf_inums[type]);
4955 if (IS_ERR(qf_inode)) {
4956 ext4_error(sb, "Bad quota inode # %lu", qf_inums[type]);
4957 return PTR_ERR(qf_inode);

--- 177 unchanged lines hidden (view full) ---

5135
5136static inline void unregister_as_ext2(void)
5137{
5138 unregister_filesystem(&ext2_fs_type);
5139}
5140
5141static inline int ext2_feature_set_ok(struct super_block *sb)
5142{
5166 if (EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT2_FEATURE_INCOMPAT_SUPP))
5143 if (ext4_has_unknown_ext2_incompat_features(sb))
5167 return 0;
5168 if (sb->s_flags & MS_RDONLY)
5169 return 1;
5144 return 0;
5145 if (sb->s_flags & MS_RDONLY)
5146 return 1;
5170 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT2_FEATURE_RO_COMPAT_SUPP))
5147 if (ext4_has_unknown_ext2_ro_compat_features(sb))
5171 return 0;
5172 return 1;
5173}
5174#else
5175static inline void register_as_ext2(void) { }
5176static inline void unregister_as_ext2(void) { }
5177static inline int ext2_feature_set_ok(struct super_block *sb) { return 0; }
5178#endif

--- 8 unchanged lines hidden (view full) ---

5187
5188static inline void unregister_as_ext3(void)
5189{
5190 unregister_filesystem(&ext3_fs_type);
5191}
5192
5193static inline int ext3_feature_set_ok(struct super_block *sb)
5194{
5148 return 0;
5149 return 1;
5150}
5151#else
5152static inline void register_as_ext2(void) { }
5153static inline void unregister_as_ext2(void) { }
5154static inline int ext2_feature_set_ok(struct super_block *sb) { return 0; }
5155#endif

--- 8 unchanged lines hidden (view full) ---

5164
5165static inline void unregister_as_ext3(void)
5166{
5167 unregister_filesystem(&ext3_fs_type);
5168}
5169
5170static inline int ext3_feature_set_ok(struct super_block *sb)
5171{
5195 if (EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT3_FEATURE_INCOMPAT_SUPP))
5172 if (ext4_has_unknown_ext3_incompat_features(sb))
5196 return 0;
5173 return 0;
5197 if (!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL))
5174 if (!ext4_has_feature_journal(sb))
5198 return 0;
5199 if (sb->s_flags & MS_RDONLY)
5200 return 1;
5175 return 0;
5176 if (sb->s_flags & MS_RDONLY)
5177 return 1;
5201 if (EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT3_FEATURE_RO_COMPAT_SUPP))
5178 if (ext4_has_unknown_ext3_ro_compat_features(sb))
5202 return 0;
5203 return 1;
5204}
5205
5206static struct file_system_type ext4_fs_type = {
5207 .owner = THIS_MODULE,
5208 .name = "ext4",
5209 .mount = ext4_mount,

--- 95 unchanged lines hidden ---
5179 return 0;
5180 return 1;
5181}
5182
5183static struct file_system_type ext4_fs_type = {
5184 .owner = THIS_MODULE,
5185 .name = "ext4",
5186 .mount = ext4_mount,

--- 95 unchanged lines hidden ---