diff options
author | JP Abgrall <jpa@google.com> | 2014-03-06 13:50:20 -0800 |
---|---|---|
committer | JP Abgrall <jpa@google.com> | 2014-03-06 13:50:20 -0800 |
commit | 65f0aab98b20b5994a726ab90d355248bcddfffd (patch) | |
tree | 2b7c0cf831d8255e3b0d1bab367609100a7e0f18 /lib/ext2fs/alloc_tables.c | |
parent | 66b7b06812cc7ae835e0c0ed2656d1a27580c5ed (diff) | |
download | android_external_e2fsprogs-65f0aab98b20b5994a726ab90d355248bcddfffd.tar.gz android_external_e2fsprogs-65f0aab98b20b5994a726ab90d355248bcddfffd.tar.bz2 android_external_e2fsprogs-65f0aab98b20b5994a726ab90d355248bcddfffd.zip |
Revert changes that moved from 1.41.14 to 1.42.9
Revert "e2fsck: Don't use e2fsck_global_ctx unless HAVE_SIGNAL_H"
commit e80e74c41d85ff93f3d212ba6512340f48054a93.
Revert "Merge remote-tracking branch 'linaro/linaro-1.42.9' into aosp_master"
This reverts commit e97b2b6fc82f840e84dfc631b87f21be44ff2421, reversing
changes made to 7e2fb9d09c245eba70ee008b78007315e9c0f1df.
Revert "Prepare for upstream 1.42.9"
This reverts commit 7e2fb9d09c245eba70ee008b78007315e9c0f1df.
Bug: 13340735
Change-Id: If48b153a95ef5f69f7cdccb00e23524abff3c5a8
Signed-off-by: JP Abgrall <jpa@google.com>
Diffstat (limited to 'lib/ext2fs/alloc_tables.c')
-rw-r--r-- | lib/ext2fs/alloc_tables.c | 172 |
1 files changed, 79 insertions, 93 deletions
diff --git a/lib/ext2fs/alloc_tables.c b/lib/ext2fs/alloc_tables.c index 885d2b23..46465af4 100644 --- a/lib/ext2fs/alloc_tables.c +++ b/lib/ext2fs/alloc_tables.c @@ -26,7 +26,6 @@ #include "ext2_fs.h" #include "ext2fs.h" -#include "ext2fsP.h" /* * This routine searches for free blocks that can allocate a full @@ -34,46 +33,46 @@ * block number with a correct offset were the bitmaps and inode * tables can be allocated continously and in order. */ -static blk64_t flexbg_offset(ext2_filsys fs, dgrp_t group, blk64_t start_blk, - ext2fs_block_bitmap bmap, int rem_grp, - int elem_size) +static blk_t flexbg_offset(ext2_filsys fs, dgrp_t group, blk_t start_blk, + ext2fs_block_bitmap bmap, int offset, int size, + int elem_size) { - int flexbg, flexbg_size, size; - blk64_t last_blk, first_free = 0; + int flexbg, flexbg_size; + blk_t last_blk, first_free = 0; dgrp_t last_grp; flexbg_size = 1 << fs->super->s_log_groups_per_flex; flexbg = group / flexbg_size; - size = rem_grp * elem_size; if (size > (int) (fs->super->s_blocks_per_group / 8)) size = (int) fs->super->s_blocks_per_group / 8; + if (offset) + offset -= 1; + /* * Don't do a long search if the previous block * search is still valid. */ - if (start_blk && ext2fs_test_block_bitmap_range2(bmap, start_blk, - elem_size)) - return start_blk; + if (start_blk && group % flexbg_size) { + if (ext2fs_test_block_bitmap_range(bmap, start_blk + elem_size, + size)) + return start_blk + elem_size; + } - start_blk = ext2fs_group_first_block2(fs, flexbg_size * flexbg); + start_blk = ext2fs_group_first_block(fs, flexbg_size * flexbg); last_grp = group | (flexbg_size - 1); - if (last_grp > fs->group_desc_count-1) - last_grp = fs->group_desc_count-1; - last_blk = ext2fs_group_last_block2(fs, last_grp); + if (last_grp > fs->group_desc_count) + last_grp = fs->group_desc_count; + last_blk = ext2fs_group_last_block(fs, last_grp); /* Find the first available block */ - if (ext2fs_get_free_blocks2(fs, start_blk, last_blk, size, - bmap, &first_free) == 0) + if (ext2fs_get_free_blocks(fs, start_blk, last_blk, 1, bmap, + &first_free)) return first_free; - if (ext2fs_get_free_blocks2(fs, start_blk, last_blk, elem_size, - bmap, &first_free) == 0) - return first_free; - - if (ext2fs_get_free_blocks2(fs, 0, last_blk, elem_size, bmap, - &first_free) == 0) + if (ext2fs_get_free_blocks(fs, first_free + offset, last_blk, size, + bmap, &first_free)) return first_free; return first_free; @@ -82,14 +81,13 @@ static blk64_t flexbg_offset(ext2_filsys fs, dgrp_t group, blk64_t start_blk, errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, ext2fs_block_bitmap bmap) { - unsigned int j; errcode_t retval; - blk64_t group_blk, start_blk, last_blk, new_blk, blk; + blk_t group_blk, start_blk, last_blk, new_blk, blk; dgrp_t last_grp = 0; - int rem_grps = 0, flexbg_size = 0; + int j, rem_grps = 0, flexbg_size = 0; - group_blk = ext2fs_group_first_block2(fs, group); - last_blk = ext2fs_group_last_block2(fs, group); + group_blk = ext2fs_group_first_block(fs, group); + last_blk = ext2fs_group_last_block(fs, group); if (!bmap) bmap = fs->block_map; @@ -99,17 +97,17 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, fs->super->s_log_groups_per_flex) { flexbg_size = 1 << fs->super->s_log_groups_per_flex; last_grp = group | (flexbg_size - 1); - if (last_grp > fs->group_desc_count-1) - last_grp = fs->group_desc_count-1; - rem_grps = last_grp - group + 1; + rem_grps = last_grp - group; + if (last_grp > fs->group_desc_count) + last_grp = fs->group_desc_count; } /* * Allocate the block and inode bitmaps, if necessary */ if (fs->stride) { - retval = ext2fs_get_free_blocks2(fs, group_blk, last_blk, - 1, bmap, &start_blk); + retval = ext2fs_get_free_blocks(fs, group_blk, last_blk, + 1, bmap, &start_blk); if (retval) return retval; start_blk += fs->inode_blocks_per_group; @@ -121,61 +119,57 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, start_blk = group_blk; if (flexbg_size) { - blk64_t prev_block = 0; - - if (group % flexbg_size) - prev_block = ext2fs_block_bitmap_loc(fs, group - 1) + 1; + blk_t prev_block = 0; + if (group && fs->group_desc[group-1].bg_block_bitmap) + prev_block = fs->group_desc[group-1].bg_block_bitmap; start_blk = flexbg_offset(fs, group, prev_block, bmap, - rem_grps, 1); - last_blk = ext2fs_group_last_block2(fs, last_grp); + 0, rem_grps, 1); + last_blk = ext2fs_group_last_block(fs, last_grp); } - if (!ext2fs_block_bitmap_loc(fs, group)) { - retval = ext2fs_get_free_blocks2(fs, start_blk, last_blk, - 1, bmap, &new_blk); + if (!fs->group_desc[group].bg_block_bitmap) { + retval = ext2fs_get_free_blocks(fs, start_blk, last_blk, + 1, bmap, &new_blk); if (retval == EXT2_ET_BLOCK_ALLOC_FAIL) - retval = ext2fs_get_free_blocks2(fs, group_blk, + retval = ext2fs_get_free_blocks(fs, group_blk, last_blk, 1, bmap, &new_blk); if (retval) return retval; - ext2fs_mark_block_bitmap2(bmap, new_blk); - ext2fs_block_bitmap_loc_set(fs, group, new_blk); + ext2fs_mark_block_bitmap(bmap, new_blk); + fs->group_desc[group].bg_block_bitmap = new_blk; if (flexbg_size) { - dgrp_t gr = ext2fs_group_of_blk2(fs, new_blk); - ext2fs_bg_free_blocks_count_set(fs, gr, ext2fs_bg_free_blocks_count(fs, gr) - 1); - ext2fs_free_blocks_count_add(fs->super, -1); - ext2fs_bg_flags_clear(fs, gr, EXT2_BG_BLOCK_UNINIT); + dgrp_t gr = ext2fs_group_of_blk(fs, new_blk); + fs->group_desc[gr].bg_free_blocks_count--; + fs->super->s_free_blocks_count--; + fs->group_desc[gr].bg_flags &= ~EXT2_BG_BLOCK_UNINIT; ext2fs_group_desc_csum_set(fs, gr); } } if (flexbg_size) { - blk64_t prev_block = 0; - if (group % flexbg_size) - prev_block = ext2fs_inode_bitmap_loc(fs, group - 1) + 1; - else - prev_block = ext2fs_block_bitmap_loc(fs, group) + - flexbg_size; + blk_t prev_block = 0; + if (group && fs->group_desc[group-1].bg_inode_bitmap) + prev_block = fs->group_desc[group-1].bg_inode_bitmap; start_blk = flexbg_offset(fs, group, prev_block, bmap, - rem_grps, 1); - last_blk = ext2fs_group_last_block2(fs, last_grp); + flexbg_size, rem_grps, 1); + last_blk = ext2fs_group_last_block(fs, last_grp); } - if (!ext2fs_inode_bitmap_loc(fs, group)) { - retval = ext2fs_get_free_blocks2(fs, start_blk, last_blk, - 1, bmap, &new_blk); + if (!fs->group_desc[group].bg_inode_bitmap) { + retval = ext2fs_get_free_blocks(fs, start_blk, last_blk, + 1, bmap, &new_blk); if (retval == EXT2_ET_BLOCK_ALLOC_FAIL) - retval = ext2fs_get_free_blocks2(fs, group_blk, - last_blk, 1, bmap, &new_blk); + retval = ext2fs_get_free_blocks(fs, group_blk, + last_blk, 1, bmap, &new_blk); if (retval) return retval; - ext2fs_mark_block_bitmap2(bmap, new_blk); - ext2fs_inode_bitmap_loc_set(fs, group, new_blk); + ext2fs_mark_block_bitmap(bmap, new_blk); + fs->group_desc[group].bg_inode_bitmap = new_blk; if (flexbg_size) { - dgrp_t gr = ext2fs_group_of_blk2(fs, new_blk); - ext2fs_bg_free_blocks_count_set(fs, gr, ext2fs_bg_free_blocks_count(fs, gr) - 1); - ext2fs_free_blocks_count_add(fs->super, -1); - ext2fs_bg_flags_clear(fs, gr, EXT2_BG_BLOCK_UNINIT); + dgrp_t gr = ext2fs_group_of_blk(fs, new_blk); + fs->group_desc[gr].bg_free_blocks_count--; + fs->super->s_free_blocks_count--; + fs->group_desc[gr].bg_flags &= ~EXT2_BG_BLOCK_UNINIT; ext2fs_group_desc_csum_set(fs, gr); } } @@ -184,22 +178,21 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, * Allocate the inode table */ if (flexbg_size) { - blk64_t prev_block = 0; - - if (group % flexbg_size) - prev_block = ext2fs_inode_table_loc(fs, group - 1) + - fs->inode_blocks_per_group; - else - prev_block = ext2fs_inode_bitmap_loc(fs, group) + - flexbg_size; - + blk_t prev_block = 0; + if (group && fs->group_desc[group-1].bg_inode_table) + prev_block = fs->group_desc[group-1].bg_inode_table; + if (last_grp == fs->group_desc_count) + rem_grps = last_grp - group; group_blk = flexbg_offset(fs, group, prev_block, bmap, - rem_grps, fs->inode_blocks_per_group); - last_blk = ext2fs_group_last_block2(fs, last_grp); + flexbg_size * 2, + fs->inode_blocks_per_group * + rem_grps, + fs->inode_blocks_per_group); + last_blk = ext2fs_group_last_block(fs, last_grp); } - if (!ext2fs_inode_table_loc(fs, group)) { - retval = ext2fs_get_free_blocks2(fs, group_blk, last_blk, + if (!fs->group_desc[group].bg_inode_table) { + retval = ext2fs_get_free_blocks(fs, group_blk, last_blk, fs->inode_blocks_per_group, bmap, &new_blk); if (retval) @@ -207,17 +200,16 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, for (j=0, blk = new_blk; j < fs->inode_blocks_per_group; j++, blk++) { - ext2fs_mark_block_bitmap2(bmap, blk); + ext2fs_mark_block_bitmap(bmap, blk); if (flexbg_size) { - dgrp_t gr = ext2fs_group_of_blk2(fs, blk); - ext2fs_bg_free_blocks_count_set(fs, gr, ext2fs_bg_free_blocks_count(fs, gr) - 1); - ext2fs_free_blocks_count_add(fs->super, -1); - ext2fs_bg_flags_clear(fs, gr, - EXT2_BG_BLOCK_UNINIT); + dgrp_t gr = ext2fs_group_of_blk(fs, blk); + fs->group_desc[gr].bg_free_blocks_count--; + fs->super->s_free_blocks_count--; + fs->group_desc[gr].bg_flags &= ~EXT2_BG_BLOCK_UNINIT; ext2fs_group_desc_csum_set(fs, gr); } } - ext2fs_inode_table_loc_set(fs, group, new_blk); + fs->group_desc[group].bg_inode_table = new_blk; } ext2fs_group_desc_csum_set(fs, group); return 0; @@ -227,18 +219,12 @@ errcode_t ext2fs_allocate_tables(ext2_filsys fs) { errcode_t retval; dgrp_t i; - struct ext2fs_numeric_progress_struct progress; - - ext2fs_numeric_progress_init(fs, &progress, NULL, - fs->group_desc_count); for (i = 0; i < fs->group_desc_count; i++) { - ext2fs_numeric_progress_update(fs, &progress, i); retval = ext2fs_allocate_group_table(fs, i, fs->block_map); if (retval) return retval; } - ext2fs_numeric_progress_close(fs, &progress, NULL); return 0; } |