diff options
author | Theodore Ts'o <tytso@mit.edu> | 2004-12-23 13:55:34 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2004-12-23 13:55:34 -0500 |
commit | 1d667534e93e78eedbf2efcef6d7844041675f26 (patch) | |
tree | 175be53bfa3bec8b7fe1af1a9e9def44db0a2550 | |
parent | 35238dd1a5585d042e5f0d478211e9fdfb4873e1 (diff) | |
download | e2fsprogs-1d667534e93e78eedbf2efcef6d7844041675f26.tar.gz |
ext2fs.h (BMAP_SET), bmap.c (ext2fs_bmap): Add support for new
flag, BMAP_SET, which allows the caller to set a
particular logical->physical block mapping.
-rw-r--r-- | lib/ext2fs/ChangeLog | 6 | ||||
-rw-r--r-- | lib/ext2fs/bmap.c | 61 | ||||
-rw-r--r-- | lib/ext2fs/ext2_err.et.in | 3 | ||||
-rw-r--r-- | lib/ext2fs/ext2fs.h | 3 |
4 files changed, 58 insertions, 15 deletions
diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 2df731a2..f2ce518d 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,5 +1,11 @@ 2004-12-23 Theodore Ts'o <tytso@mit.edu> + * ext2fs.h (BMAP_SET), bmap.c (ext2fs_bmap): Add support for new + flag, BMAP_SET, which allows the caller to set a + particular logical->physical block mapping. + + * ext2_err.et.in (EXT2_ET_SET_BMAP_NO_IND): New error code + * initialize.c (calc_reserved_gdt_blocks): #ifdef out all debugging printf statements. diff --git a/lib/ext2fs/bmap.c b/lib/ext2fs/bmap.c index 45053dc1..e8400447 100644 --- a/lib/ext2fs/bmap.c +++ b/lib/ext2fs/bmap.c @@ -29,8 +29,6 @@ extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino, char *block_buf, int bmap_flags, blk_t block, blk_t *phys_blk); -#define BMAP_ALLOC 1 - #define inode_bmap(inode, nr) ((inode)->i_block[(nr)]) static _BMAP_INLINE_ errcode_t block_ind_bmap(ext2_filsys fs, int flags, @@ -42,6 +40,8 @@ static _BMAP_INLINE_ errcode_t block_ind_bmap(ext2_filsys fs, int flags, blk_t b; if (!ind) { + if (flags & BMAP_SET) + return EXT2_ET_SET_BMAP_NO_IND; *ret_blk = 0; return 0; } @@ -49,6 +49,17 @@ static _BMAP_INLINE_ errcode_t block_ind_bmap(ext2_filsys fs, int flags, if (retval) return retval; + if (flags & BMAP_SET) { + b = *ret_blk; +#ifdef EXT2FS_ENABLE_SWAPFS + if ((fs->flags & EXT2_FLAG_SWAP_BYTES) || + (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)) + b = ext2fs_swab32(b); +#endif + ((blk_t *) block_buf)[nr] = b; + return io_channel_write_blk(fs->io, ind, 1, block_buf); + } + b = ((blk_t *) block_buf)[nr]; #ifdef EXT2FS_ENABLE_SWAPFS @@ -94,8 +105,8 @@ static _BMAP_INLINE_ errcode_t block_dind_bmap(ext2_filsys fs, int flags, addr_per_block = (blk_t) fs->blocksize >> 2; - retval = block_ind_bmap(fs, flags, dind, block_buf, blocks_alloc, - nr / addr_per_block, &b); + retval = block_ind_bmap(fs, flags & ~BMAP_SET, dind, block_buf, + blocks_alloc, nr / addr_per_block, &b); if (retval) return retval; retval = block_ind_bmap(fs, flags, b, block_buf, blocks_alloc, @@ -114,8 +125,8 @@ static _BMAP_INLINE_ errcode_t block_tind_bmap(ext2_filsys fs, int flags, addr_per_block = (blk_t) fs->blocksize >> 2; - retval = block_dind_bmap(fs, flags, tind, block_buf, blocks_alloc, - nr / addr_per_block, &b); + retval = block_dind_bmap(fs, flags & ~BMAP_SET, tind, block_buf, + blocks_alloc, nr / addr_per_block, &b); if (retval) return retval; retval = block_ind_bmap(fs, flags, b, block_buf, blocks_alloc, @@ -132,9 +143,10 @@ errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, blk_t b; char *buf = 0; errcode_t retval = 0; - int blocks_alloc = 0; + int blocks_alloc = 0, inode_dirty = 0; - *phys_blk = 0; + if (!(bmap_flags & BMAP_SET)) + *phys_blk = 0; /* Read inode structure if necessary */ if (!inode) { @@ -153,6 +165,18 @@ errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, } if (block < EXT2_NDIR_BLOCKS) { + if (bmap_flags & BMAP_SET) { + b = *phys_blk; +#ifdef EXT2FS_ENABLE_SWAPFS + if ((fs->flags & EXT2_FLAG_SWAP_BYTES) || + (fs->flags & EXT2_FLAG_SWAP_BYTES_READ)) + b = ext2fs_swab32(b); +#endif + inode_bmap(inode, block) = b; + inode_dirty++; + goto done; + } + *phys_blk = inode_bmap(inode, block); b = block ? inode_bmap(inode, block-1) : 0; @@ -172,8 +196,11 @@ errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, if (block < addr_per_block) { b = inode_bmap(inode, EXT2_IND_BLOCK); if (!b) { - if (!(bmap_flags & BMAP_ALLOC)) - goto done; + if (!(bmap_flags & BMAP_ALLOC)) { + if (bmap_flags & BMAP_SET) + retval = EXT2_ET_SET_BMAP_NO_IND; + goto done; + } b = inode_bmap(inode, EXT2_IND_BLOCK-1); retval = ext2fs_alloc_block(fs, b, block_buf, &b); @@ -192,8 +219,11 @@ errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, if (block < addr_per_block * addr_per_block) { b = inode_bmap(inode, EXT2_DIND_BLOCK); if (!b) { - if (!(bmap_flags & BMAP_ALLOC)) - goto done; + if (!(bmap_flags & BMAP_ALLOC)) { + if (bmap_flags & BMAP_SET) + retval = EXT2_ET_SET_BMAP_NO_IND; + goto done; + } b = inode_bmap(inode, EXT2_IND_BLOCK); retval = ext2fs_alloc_block(fs, b, block_buf, &b); @@ -211,8 +241,11 @@ errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, block -= addr_per_block * addr_per_block; b = inode_bmap(inode, EXT2_TIND_BLOCK); if (!b) { - if (!(bmap_flags & BMAP_ALLOC)) + if (!(bmap_flags & BMAP_ALLOC)) { + if (bmap_flags & BMAP_SET) + retval = EXT2_ET_SET_BMAP_NO_IND; goto done; + } b = inode_bmap(inode, EXT2_DIND_BLOCK); retval = ext2fs_alloc_block(fs, b, block_buf, &b); @@ -226,7 +259,7 @@ errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, done: if (buf) ext2fs_free_mem(&buf); - if ((retval == 0) && blocks_alloc) { + if ((retval == 0) && (blocks_alloc || inode_dirty)) { inode->i_blocks += (blocks_alloc * fs->blocksize) / 512; retval = ext2fs_write_inode(fs, ino, inode); } diff --git a/lib/ext2fs/ext2_err.et.in b/lib/ext2fs/ext2_err.et.in index 5314c6c5..907b475a 100644 --- a/lib/ext2fs/ext2_err.et.in +++ b/lib/ext2fs/ext2_err.et.in @@ -293,5 +293,8 @@ ec EXT2_ET_RES_GDT_BLOCKS, ec EXT2_ET_RESIZE_INODE_CORRUPT, "Resize inode is corrupt" +ec EXT2_ET_SET_BMAP_NO_IND, + "Missing indirect block not present" + end diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 8d358b49..55bc5473 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -402,7 +402,8 @@ typedef struct ext2_icount *ext2_icount_t; /* * Flags for ext2fs_bmap */ -#define BMAP_ALLOC 1 +#define BMAP_ALLOC 0x0001 +#define BMAP_SET 0x0002 /* * Flags for imager.c functions |