diff options
author | Theodore Ts'o <tytso@mit.edu> | 2008-08-27 18:37:11 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2008-08-27 18:37:11 -0400 |
commit | 9033faf5257be85aab4baffa53e0bef96ab9c0f5 (patch) | |
tree | d42af5de50a5a979355af762ad75037f1325cedd | |
parent | 64987c052c235d60373995d36b5c01291c464b74 (diff) | |
download | e2fsprogs-9033faf5257be85aab4baffa53e0bef96ab9c0f5.tar.gz |
libext2fs: Fix ext2fs_bmap() to work with extents and BMAP_ALLOC
Fix bugs with extents support when allocating blocks.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r-- | lib/ext2fs/bmap.c | 7 | ||||
-rw-r--r-- | lib/ext2fs/extent.c | 5 |
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/ext2fs/bmap.c b/lib/ext2fs/bmap.c index e56a99ac..be7ccbc9 100644 --- a/lib/ext2fs/bmap.c +++ b/lib/ext2fs/bmap.c @@ -172,7 +172,7 @@ errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, if (retval) { /* If the extent is not found, return phys_blk = 0 */ if (retval == EXT2_ET_EXTENT_NOT_FOUND) - retval = 0; + goto got_block; goto done; } retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent); @@ -184,6 +184,7 @@ errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, if (ret_flags && extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT) *ret_flags |= BMAP_RET_UNINIT; } + got_block: if ((*phys_blk == 0) && (bmap_flags & BMAP_ALLOC)) { retval = ext2fs_alloc_block(fs, b, block_buf, &b); if (retval) @@ -192,6 +193,10 @@ errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, (blk64_t) b, 0); if (retval) goto done; + /* Update inode after setting extent */ + retval = ext2fs_read_inode(fs, ino, inode); + if (retval) + return retval; blocks_alloc++; *phys_blk = b; } diff --git a/lib/ext2fs/extent.c b/lib/ext2fs/extent.c index 9f76ccf7..a2cf679f 100644 --- a/lib/ext2fs/extent.c +++ b/lib/ext2fs/extent.c @@ -600,8 +600,11 @@ static errcode_t extent_goto(ext2_extent_handle_t handle, errcode_t retval; retval = ext2fs_extent_get(handle, EXT2_EXTENT_ROOT, &extent); - if (retval) + if (retval) { + if (retval == EXT2_ET_EXTENT_NO_NEXT) + retval = EXT2_ET_EXTENT_NOT_FOUND; return retval; + } if (leaf_level > handle->max_depth) { #ifdef DEBUG |