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

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

208 memset(bh->b_data, 0, sb->s_blocksize);
209
210 bit_max = ext4_num_base_meta_clusters(sb, block_group);
211 for (bit = 0; bit < bit_max; bit++)
212 ext4_set_bit(bit, bh->b_data);
213
214 start = ext4_group_first_block_no(sb, block_group);
215
1/*
2 * linux/fs/ext4/balloc.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 *

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

208 memset(bh->b_data, 0, sb->s_blocksize);
209
210 bit_max = ext4_num_base_meta_clusters(sb, block_group);
211 for (bit = 0; bit < bit_max; bit++)
212 ext4_set_bit(bit, bh->b_data);
213
214 start = ext4_group_first_block_no(sb, block_group);
215
216 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
216 if (ext4_has_feature_flex_bg(sb))
217 flex_bg = 1;
218
219 /* Set bits for block and inode bitmaps, and inode table */
220 tmp = ext4_block_bitmap(sb, gdp);
221 if (!flex_bg || ext4_block_in_group(sb, tmp, block_group))
222 ext4_set_bit(EXT4_B2C(sbi, tmp - start), bh->b_data);
223
224 tmp = ext4_inode_bitmap(sb, gdp);

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

317 struct buffer_head *bh)
318{
319 struct ext4_sb_info *sbi = EXT4_SB(sb);
320 ext4_grpblk_t offset;
321 ext4_grpblk_t next_zero_bit;
322 ext4_fsblk_t blk;
323 ext4_fsblk_t group_first_block;
324
217 flex_bg = 1;
218
219 /* Set bits for block and inode bitmaps, and inode table */
220 tmp = ext4_block_bitmap(sb, gdp);
221 if (!flex_bg || ext4_block_in_group(sb, tmp, block_group))
222 ext4_set_bit(EXT4_B2C(sbi, tmp - start), bh->b_data);
223
224 tmp = ext4_inode_bitmap(sb, gdp);

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

317 struct buffer_head *bh)
318{
319 struct ext4_sb_info *sbi = EXT4_SB(sb);
320 ext4_grpblk_t offset;
321 ext4_grpblk_t next_zero_bit;
322 ext4_fsblk_t blk;
323 ext4_fsblk_t group_first_block;
324
325 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
325 if (ext4_has_feature_flex_bg(sb)) {
326 /* with FLEX_BG, the inode/block bitmaps and itable
327 * blocks may not be in the group at all
328 * so the bitmap validation will be skipped for those groups
329 * or it has to also read the block group where the bitmaps
330 * are located to verify they are set.
331 */
332 return 0;
333 }

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

735 * in this group. Currently this will be only 0 or 1.
736 */
737int ext4_bg_has_super(struct super_block *sb, ext4_group_t group)
738{
739 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
740
741 if (group == 0)
742 return 1;
326 /* with FLEX_BG, the inode/block bitmaps and itable
327 * blocks may not be in the group at all
328 * so the bitmap validation will be skipped for those groups
329 * or it has to also read the block group where the bitmaps
330 * are located to verify they are set.
331 */
332 return 0;
333 }

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

735 * in this group. Currently this will be only 0 or 1.
736 */
737int ext4_bg_has_super(struct super_block *sb, ext4_group_t group)
738{
739 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
740
741 if (group == 0)
742 return 1;
743 if (EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_SPARSE_SUPER2)) {
743 if (ext4_has_feature_sparse_super2(sb)) {
744 if (group == le32_to_cpu(es->s_backup_bgs[0]) ||
745 group == le32_to_cpu(es->s_backup_bgs[1]))
746 return 1;
747 return 0;
748 }
744 if (group == le32_to_cpu(es->s_backup_bgs[0]) ||
745 group == le32_to_cpu(es->s_backup_bgs[1]))
746 return 1;
747 return 0;
748 }
749 if ((group <= 1) || !EXT4_HAS_RO_COMPAT_FEATURE(sb,
750 EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER))
749 if ((group <= 1) || !ext4_has_feature_sparse_super(sb))
751 return 1;
752 if (!(group & 1))
753 return 0;
754 if (test_root(group, 3) || (test_root(group, 5)) ||
755 test_root(group, 7))
756 return 1;
757
758 return 0;

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

771}
772
773static unsigned long ext4_bg_num_gdb_nometa(struct super_block *sb,
774 ext4_group_t group)
775{
776 if (!ext4_bg_has_super(sb, group))
777 return 0;
778
750 return 1;
751 if (!(group & 1))
752 return 0;
753 if (test_root(group, 3) || (test_root(group, 5)) ||
754 test_root(group, 7))
755 return 1;
756
757 return 0;

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

770}
771
772static unsigned long ext4_bg_num_gdb_nometa(struct super_block *sb,
773 ext4_group_t group)
774{
775 if (!ext4_bg_has_super(sb, group))
776 return 0;
777
779 if (EXT4_HAS_INCOMPAT_FEATURE(sb,EXT4_FEATURE_INCOMPAT_META_BG))
778 if (ext4_has_feature_meta_bg(sb))
780 return le32_to_cpu(EXT4_SB(sb)->s_es->s_first_meta_bg);
781 else
782 return EXT4_SB(sb)->s_gdb_count;
783}
784
785/**
786 * ext4_bg_num_gdb - number of blocks used by the group table in group
787 * @sb: superblock for filesystem

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

792 * different number of descriptor blocks in each group.
793 */
794unsigned long ext4_bg_num_gdb(struct super_block *sb, ext4_group_t group)
795{
796 unsigned long first_meta_bg =
797 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_meta_bg);
798 unsigned long metagroup = group / EXT4_DESC_PER_BLOCK(sb);
799
779 return le32_to_cpu(EXT4_SB(sb)->s_es->s_first_meta_bg);
780 else
781 return EXT4_SB(sb)->s_gdb_count;
782}
783
784/**
785 * ext4_bg_num_gdb - number of blocks used by the group table in group
786 * @sb: superblock for filesystem

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

791 * different number of descriptor blocks in each group.
792 */
793unsigned long ext4_bg_num_gdb(struct super_block *sb, ext4_group_t group)
794{
795 unsigned long first_meta_bg =
796 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_meta_bg);
797 unsigned long metagroup = group / EXT4_DESC_PER_BLOCK(sb);
798
800 if (!EXT4_HAS_INCOMPAT_FEATURE(sb,EXT4_FEATURE_INCOMPAT_META_BG) ||
801 metagroup < first_meta_bg)
799 if (!ext4_has_feature_meta_bg(sb) || metagroup < first_meta_bg)
802 return ext4_bg_num_gdb_nometa(sb, group);
803
804 return ext4_bg_num_gdb_meta(sb,group);
805
806}
807
808/*
809 * This function returns the number of file system metadata clusters at
810 * the beginning of a block group, including the reserved gdt blocks.
811 */
812static unsigned ext4_num_base_meta_clusters(struct super_block *sb,
813 ext4_group_t block_group)
814{
815 struct ext4_sb_info *sbi = EXT4_SB(sb);
816 unsigned num;
817
818 /* Check for superblock and gdt backups in this group */
819 num = ext4_bg_has_super(sb, block_group);
820
800 return ext4_bg_num_gdb_nometa(sb, group);
801
802 return ext4_bg_num_gdb_meta(sb,group);
803
804}
805
806/*
807 * This function returns the number of file system metadata clusters at
808 * the beginning of a block group, including the reserved gdt blocks.
809 */
810static unsigned ext4_num_base_meta_clusters(struct super_block *sb,
811 ext4_group_t block_group)
812{
813 struct ext4_sb_info *sbi = EXT4_SB(sb);
814 unsigned num;
815
816 /* Check for superblock and gdt backups in this group */
817 num = ext4_bg_has_super(sb, block_group);
818
821 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_META_BG) ||
819 if (!ext4_has_feature_meta_bg(sb) ||
822 block_group < le32_to_cpu(sbi->s_es->s_first_meta_bg) *
823 sbi->s_desc_per_block) {
824 if (num) {
825 num += ext4_bg_num_gdb(sb, block_group);
826 num += le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks);
827 }
828 } else { /* For META_BG_BLOCK_GROUPS */
829 num += ext4_bg_num_gdb(sb, block_group);

--- 51 unchanged lines hidden ---
820 block_group < le32_to_cpu(sbi->s_es->s_first_meta_bg) *
821 sbi->s_desc_per_block) {
822 if (num) {
823 num += ext4_bg_num_gdb(sb, block_group);
824 num += le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks);
825 }
826 } else { /* For META_BG_BLOCK_GROUPS */
827 num += ext4_bg_num_gdb(sb, block_group);

--- 51 unchanged lines hidden ---