Whamcloud - gitweb
libext2fs: allocate clusters to files in expand_dir.c and mkjournal.c
authorTheodore Ts'o <tytso@mit.edu>
Fri, 10 Jun 2011 22:54:53 +0000 (18:54 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 10 Jun 2011 22:54:53 +0000 (18:54 -0400)
Teach ext2fs_expand_dir() and ext2fs_add_journal_inode() about
allocating blocks when clustered allocation is enabled.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/expanddir.c
lib/ext2fs/mkjournal.c

index 7673a3b..47af3a5 100644 (file)
@@ -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,
index 242c537..de4d51c 100644 (file)
@@ -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--;