Save journal backup after changing journal inode

master
Vitaliy Filippov 2014-01-11 21:31:12 +00:00
parent b0587d8eb4
commit f2e0275c7e
1 changed files with 16 additions and 0 deletions

16
bmove.c
View File

@ -24,6 +24,7 @@ struct process_block_struct {
char *buf;
int add_dir;
int flags;
int changes;
blk64_t last, last_new;
};
@ -50,6 +51,7 @@ static int process_block(ext2_filsys fs, blk64_t *block_nr,
if (pb->last == block-1) {
*block_nr = pb->last_new+1;
pb->last++;
pb->changes++;
return BLOCK_CHANGED;
}
return 0;
@ -86,6 +88,7 @@ static int process_block(ext2_filsys fs, blk64_t *block_nr,
ext2fs_block_alloc_stats2(fs, orig, -1);
ext2fs_block_alloc_stats2(fs, block, +1);
ret = BLOCK_CHANGED;
pb->changes++;
if (pb->flags & EXT2_BMOVE_DEBUG)
printf("ino=%u, blockcnt=%lld, %llu->%llu\n",
(unsigned) pb->ino, blockcnt,
@ -128,6 +131,7 @@ errcode_t ext2fs_move_blocks(ext2_filsys fs,
return retval;
pb.buf = block_buf + fs->blocksize * 3;
pb.last = -1;
pb.changes = 0;
/*
* If GET_DBLIST is set in the flags field, then we should
@ -163,6 +167,18 @@ errcode_t ext2fs_move_blocks(ext2_filsys fs,
if (pb.error)
return pb.error;
// Adjust journal backup after changing the journal inode
if (ino == EXT2_JOURNAL_INO && pb.changes) {
retval = ext2fs_read_inode(fs, ino, &inode);
if (retval)
return retval;
memcpy(fs->super->s_jnl_blocks, inode.i_block, EXT2_N_BLOCKS*4);
fs->super->s_jnl_blocks[15] = inode.i_size_high;
fs->super->s_jnl_blocks[16] = inode.i_size;
fs->super->s_jnl_backup_type = EXT3_JNL_BACKUP_BLOCKS;
ext2fs_mark_super_dirty(fs);
}
next:
retval = ext2fs_get_next_inode(scan, &ino, &inode);
if (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE)