| .. | .. |
|---|
| 303 | 303 | return desc; |
|---|
| 304 | 304 | } |
|---|
| 305 | 305 | |
|---|
| 306 | +static ext4_fsblk_t ext4_valid_block_bitmap_padding(struct super_block *sb, |
|---|
| 307 | + ext4_group_t block_group, |
|---|
| 308 | + struct buffer_head *bh) |
|---|
| 309 | +{ |
|---|
| 310 | + ext4_grpblk_t next_zero_bit; |
|---|
| 311 | + unsigned long bitmap_size = sb->s_blocksize * 8; |
|---|
| 312 | + unsigned int offset = num_clusters_in_group(sb, block_group); |
|---|
| 313 | + |
|---|
| 314 | + if (bitmap_size <= offset) |
|---|
| 315 | + return 0; |
|---|
| 316 | + |
|---|
| 317 | + next_zero_bit = ext4_find_next_zero_bit(bh->b_data, bitmap_size, offset); |
|---|
| 318 | + |
|---|
| 319 | + return (next_zero_bit < bitmap_size ? next_zero_bit : 0); |
|---|
| 320 | +} |
|---|
| 321 | + |
|---|
| 322 | +struct ext4_group_info *ext4_get_group_info(struct super_block *sb, |
|---|
| 323 | + ext4_group_t group) |
|---|
| 324 | +{ |
|---|
| 325 | + struct ext4_group_info **grp_info; |
|---|
| 326 | + long indexv, indexh; |
|---|
| 327 | + |
|---|
| 328 | + if (unlikely(group >= EXT4_SB(sb)->s_groups_count)) |
|---|
| 329 | + return NULL; |
|---|
| 330 | + indexv = group >> (EXT4_DESC_PER_BLOCK_BITS(sb)); |
|---|
| 331 | + indexh = group & ((EXT4_DESC_PER_BLOCK(sb)) - 1); |
|---|
| 332 | + grp_info = sbi_array_rcu_deref(EXT4_SB(sb), s_group_info, indexv); |
|---|
| 333 | + return grp_info[indexh]; |
|---|
| 334 | +} |
|---|
| 335 | + |
|---|
| 306 | 336 | /* |
|---|
| 307 | 337 | * Return the block number which was discovered to be invalid, or 0 if |
|---|
| 308 | 338 | * the block bitmap is valid. |
|---|
| .. | .. |
|---|
| 377 | 407 | |
|---|
| 378 | 408 | if (buffer_verified(bh)) |
|---|
| 379 | 409 | return 0; |
|---|
| 380 | | - if (EXT4_MB_GRP_BBITMAP_CORRUPT(grp)) |
|---|
| 410 | + if (!grp || EXT4_MB_GRP_BBITMAP_CORRUPT(grp)) |
|---|
| 381 | 411 | return -EFSCORRUPTED; |
|---|
| 382 | 412 | |
|---|
| 383 | 413 | ext4_lock_group(sb, block_group); |
|---|
| .. | .. |
|---|
| 399 | 429 | block_group, blk); |
|---|
| 400 | 430 | ext4_mark_group_bitmap_corrupted(sb, block_group, |
|---|
| 401 | 431 | EXT4_GROUP_INFO_BBITMAP_CORRUPT); |
|---|
| 432 | + return -EFSCORRUPTED; |
|---|
| 433 | + } |
|---|
| 434 | + blk = ext4_valid_block_bitmap_padding(sb, block_group, bh); |
|---|
| 435 | + if (unlikely(blk != 0)) { |
|---|
| 436 | + ext4_unlock_group(sb, block_group); |
|---|
| 437 | + ext4_error(sb, "bg %u: block %llu: padding at end of block bitmap is not set", |
|---|
| 438 | + block_group, blk); |
|---|
| 439 | + ext4_mark_group_bitmap_corrupted(sb, block_group, |
|---|
| 440 | + EXT4_GROUP_INFO_BBITMAP_CORRUPT); |
|---|
| 402 | 441 | return -EFSCORRUPTED; |
|---|
| 403 | 442 | } |
|---|
| 404 | 443 | set_buffer_verified(bh); |
|---|
| .. | .. |
|---|
| 864 | 903 | } |
|---|
| 865 | 904 | |
|---|
| 866 | 905 | /* |
|---|
| 867 | | - * This function returns the number of file system metadata clusters at |
|---|
| 906 | + * This function returns the number of file system metadata blocks at |
|---|
| 868 | 907 | * the beginning of a block group, including the reserved gdt blocks. |
|---|
| 869 | 908 | */ |
|---|
| 870 | | -static unsigned ext4_num_base_meta_clusters(struct super_block *sb, |
|---|
| 871 | | - ext4_group_t block_group) |
|---|
| 909 | +unsigned int ext4_num_base_meta_blocks(struct super_block *sb, |
|---|
| 910 | + ext4_group_t block_group) |
|---|
| 872 | 911 | { |
|---|
| 873 | 912 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
|---|
| 874 | 913 | unsigned num; |
|---|
| .. | .. |
|---|
| 886 | 925 | } else { /* For META_BG_BLOCK_GROUPS */ |
|---|
| 887 | 926 | num += ext4_bg_num_gdb(sb, block_group); |
|---|
| 888 | 927 | } |
|---|
| 889 | | - return EXT4_NUM_B2C(sbi, num); |
|---|
| 928 | + return num; |
|---|
| 890 | 929 | } |
|---|
| 930 | + |
|---|
| 931 | +static unsigned int ext4_num_base_meta_clusters(struct super_block *sb, |
|---|
| 932 | + ext4_group_t block_group) |
|---|
| 933 | +{ |
|---|
| 934 | + return EXT4_NUM_B2C(EXT4_SB(sb), ext4_num_base_meta_blocks(sb, block_group)); |
|---|
| 935 | +} |
|---|
| 936 | + |
|---|
| 891 | 937 | /** |
|---|
| 892 | 938 | * ext4_inode_to_goal_block - return a hint for block allocation |
|---|
| 893 | 939 | * @inode: inode for block allocation |
|---|