From 4a2a9b70c89891a146bcb9cee3f29572ca2e1370 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 10 Jun 2011 18:54:53 -0400 Subject: [PATCH] libext2fs: allocate clusters to files in expand_dir.c and mkjournal.c Teach ext2fs_expand_dir() and ext2fs_add_journal_inode() about allocating blocks when clustered allocation is enabled. Signed-off-by: "Theodore Ts'o" --- lib/ext2fs/expanddir.c | 22 ++++++++++++++++------ lib/ext2fs/mkjournal.c | 14 ++++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/ext2fs/expanddir.c b/lib/ext2fs/expanddir.c index 7673a3b..47af3a5 100644 --- a/lib/ext2fs/expanddir.c +++ b/lib/ext2fs/expanddir.c @@ -21,6 +21,7 @@ struct expand_dir_struct { int done; int newblocks; + blk64_t goal; errcode_t err; }; @@ -33,18 +34,24 @@ static int expand_dir_proc(ext2_filsys fs, { struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data; blk64_t new_blk; - static blk64_t last_blk = 0; char *block; errcode_t retval; if (*blocknr) { - last_blk = *blocknr; + if (blockcnt >= 0) + es->goal = *blocknr; return 0; } - retval = ext2fs_new_block2(fs, last_blk, 0, &new_blk); - if (retval) { - es->err = retval; - return BLOCK_ABORT; + if (blockcnt && + (EXT2FS_B2C(fs, es->goal) == EXT2FS_B2C(fs, es->goal+1))) + new_blk = es->goal+1; + else { + es->goal &= ~EXT2FS_CLUSTER_MASK(fs); + retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk); + if (retval) { + es->err = retval; + return BLOCK_ABORT; + } } if (blockcnt > 0) { retval = ext2fs_new_dir_block(fs, 0, 0, &block); @@ -63,6 +70,8 @@ static int expand_dir_proc(ext2_filsys fs, memset(block, 0, fs->blocksize); retval = io_channel_write_blk64(fs->io, new_blk, 1, block); } + if (blockcnt >= 0) + es->goal = new_blk; if (retval) { es->err = retval; return BLOCK_ABORT; @@ -98,6 +107,7 @@ errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir) es.done = 0; es.err = 0; + es.goal = 0; es.newblocks = 0; retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_APPEND, diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c index 242c537..de4d51c 100644 --- a/lib/ext2fs/mkjournal.c +++ b/lib/ext2fs/mkjournal.c @@ -232,10 +232,16 @@ static int mkjournal_proc(ext2_filsys fs, es->goal = *blocknr; return 0; } - retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk); - if (retval) { - es->err = retval; - return BLOCK_ABORT; + if (blockcnt && + (EXT2FS_B2C(fs, es->goal) == EXT2FS_B2C(fs, es->goal+1))) + new_blk = es->goal+1; + else { + es->goal &= ~EXT2FS_CLUSTER_MASK(fs); + retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk); + if (retval) { + es->err = retval; + return BLOCK_ABORT; + } } if (blockcnt >= 0) es->num_blocks--; -- 1.8.3.1