Initializes an uninitialized block bitmap if given, and returns the * number of blocks free in the group. */
| 2754 | /* Initializes an uninitialized block bitmap if given, and returns the |
| 2755 | * number of blocks free in the group. */ |
| 2756 | unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh, |
| 2757 | ext4_group_t block_group, struct ext4_group_desc *gdp) |
| 2758 | { |
| 2759 | int bit, bit_max; |
| 2760 | unsigned free_blocks, group_blocks; |
| 2761 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
| 2762 | |
| 2763 | if (bh) { |
| 2764 | mark_buffer_dirty(bh); |
| 2765 | /* If checksum is bad mark all blocks used to prevent allocation |
| 2766 | * essentially implementing a per-group read-only flag. */ |
| 2767 | if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) { |
| 2768 | ext4_error(sb, __FUNCTION__, |
| 2769 | "Checksum bad for group %u", block_group); |
| 2770 | ext4_free_blks_set(sb, gdp, 0); |
| 2771 | ext4_free_inodes_set(sb, gdp, 0); |
| 2772 | ext4_itable_unused_set(sb, gdp, 0); |
| 2773 | memset(bh->b_data, 0xff, sb->s_blocksize); |
| 2774 | return 0; |
| 2775 | } |
| 2776 | memset(bh->b_data, 0, sb->s_blocksize); |
| 2777 | } |
| 2778 | |
| 2779 | /* Check for superblock and gdt backups in this group */ |
| 2780 | bit_max = ext3_bg_has_super(sb, block_group); |
| 2781 | |
| 2782 | if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_META_BG) || |
| 2783 | block_group < le32_to_cpu(sbi->s_es->s_first_meta_bg) * |
| 2784 | sbi->s_desc_per_block) { |
| 2785 | if (bit_max) { |
| 2786 | bit_max += ext4_bg_num_gdb(sb, block_group); |
| 2787 | bit_max += |
| 2788 | le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks); |
| 2789 | } |
| 2790 | } else { /* For META_BG_BLOCK_GROUPS */ |
| 2791 | bit_max += ext4_bg_num_gdb(sb, block_group); |
| 2792 | } |
| 2793 | |
| 2794 | if (block_group == sbi->s_groups_count - 1) { |
| 2795 | /* |
| 2796 | * Even though mke2fs always initialize first and last group |
| 2797 | * if some other tool enabled the EXT4_BG_BLOCK_UNINIT we need |
| 2798 | * to make sure we calculate the right free blocks |
| 2799 | */ |
| 2800 | group_blocks = (unsigned int)(ext3_blocks_count(sbi->s_es) - |
| 2801 | le32_to_cpu(sbi->s_es->s_first_data_block) - |
| 2802 | (EXT4_BLOCKS_PER_GROUP(sb) * (sbi->s_groups_count - 1))); |
| 2803 | } else { |
| 2804 | group_blocks = EXT4_BLOCKS_PER_GROUP(sb); |
| 2805 | } |
| 2806 | |
| 2807 | free_blocks = group_blocks - bit_max; |
| 2808 | |
| 2809 | if (bh) { |
| 2810 | ext4_fsblk_t start, tmp; |
| 2811 | int flex_bg = 0; |
| 2812 | |
| 2813 | for (bit = 0; bit < bit_max; bit++) |
no test coverage detected