ref: 6079bff96f2beb1343fe3664b4781b8a258bee6b
parent: e0720c64b73449e31a960d09e2f06cfce3b2bdeb
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Sat Nov 28 15:27:54 EST 2015
ext4_journal: initial journal replay support part 2.
--- a/lwext4/ext4_journal.c
+++ b/lwext4/ext4_journal.c
@@ -343,6 +343,7 @@
uint32_t *this_block = arg->this_block;
struct revoke_entry *revoke_entry;
struct ext4_block journal_block, ext4_block;
+ struct ext4_fs *fs = jbd_fs->inode_ref.fs;
ext4_dbg(DEBUG_JBD,
"Replaying block in block_tag: %" PRIu64 "\n",
block);
@@ -356,18 +357,37 @@
if (r != EOK)
return;
- r = ext4_block_get_noread(jbd_fs->bdev, &ext4_block, block);
- if (r != EOK) {
- jbd_block_set(jbd_fs, &journal_block);
- return;
- }
+ if (block) {
+ r = ext4_block_get_noread(fs->bdev, &ext4_block, block);
+ if (r != EOK) {
+ jbd_block_set(jbd_fs, &journal_block);
+ return;
+ }
- memcpy(ext4_block.data,
- journal_block.data,
- jbd_get32(&jbd_fs->sb, blocksize));
+ memcpy(ext4_block.data,
+ journal_block.data,
+ jbd_get32(&jbd_fs->sb, blocksize));
- ext4_block.dirty = true;
- ext4_block_set(jbd_fs->bdev, &ext4_block);
+ ext4_block.dirty = true;
+ ext4_block_set(fs->bdev, &ext4_block);
+ } else {
+ uint16_t mount_count, state;
+ mount_count = ext4_get16(&fs->sb, mount_count);
+ state = ext4_get16(&fs->sb, state);
+ memcpy(&fs->sb,
+ journal_block.data,
+ EXT4_SUPERBLOCK_SIZE);
+
+ /* Mark system as mounted */
+ ext4_set16(&fs->sb, state, state);
+ r = ext4_sb_write(fs->bdev, &fs->sb);
+ if (r != EOK)
+ return;
+
+ /*Update mount count*/
+ ext4_set16(&fs->sb, mount_count, mount_count);
+ }
+
jbd_block_set(jbd_fs, &journal_block);
return;