Skip to content

Commit

Permalink
new block start from last allocated
Browse files Browse the repository at this point in the history
Signed-off-by: yuchen.cc <[email protected]>
  • Loading branch information
yuchen0cc authored and liulanzheng committed Apr 4, 2023
1 parent 25ad8a4 commit f250a59
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/ext2fs/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir,
* Stupid algorithm --- we now just search forward starting from the
* goal. Should put in a smarter one someday....
*/
blk64_t last_allocated = 0;
errcode_t ext2fs_new_block3(ext2_filsys fs, blk64_t goal,
ext2fs_block_bitmap map, blk64_t *ret,
struct blk_alloc_ctx *ctx)
Expand Down Expand Up @@ -185,6 +186,10 @@ errcode_t ext2fs_new_block3(ext2_filsys fs, blk64_t goal,
goal = fs->super->s_first_data_block;
goal &= ~EXT2FS_CLUSTER_MASK(fs);

if (goal == 0) {
goal = last_allocated;
}

retval = ext2fs_find_first_zero_block_bitmap2(map,
goal, ext2fs_blocks_count(fs->super) - 1, &b);
if ((retval == ENOENT) && (goal != fs->super->s_first_data_block))
Expand All @@ -198,6 +203,7 @@ errcode_t ext2fs_new_block3(ext2_filsys fs, blk64_t goal,

ext2fs_clear_block_uninit(fs, ext2fs_group_of_blk2(fs, b));
*ret = b;
last_allocated = b;
return 0;
}

Expand Down

0 comments on commit f250a59

Please sign in to comment.