+static int create_journal_inode(struct ext4_fs *fs,
+ struct ext4_mkfs_info *info)
+{
+ int ret;
+ struct ext4_inode_ref inode_ref;
+ uint64_t blocks_count;
+
+ if (!info->journal)
+ return EOK;
+
+ ret = ext4_fs_get_inode_ref(fs, EXT4_JOURNAL_INO, &inode_ref);
+ if (ret != EOK)
+ return ret;
+
+ struct ext4_inode *inode = inode_ref.inode;
+
+ ext4_inode_set_mode(&fs->sb, inode, EXT4_INODE_MODE_FILE | 0600);
+ ext4_inode_set_links_cnt(inode, 1);
+
+ blocks_count = ext4_inode_get_blocks_count(&fs->sb, inode);
+
+ while (blocks_count++ < info->journal_blocks)
+ {
+ ext4_fsblk_t fblock;
+ ext4_lblk_t iblock;
+ struct ext4_block blk;
+
+ ret = ext4_fs_append_inode_dblk(&inode_ref, &fblock, &iblock);
+ if (ret != EOK)
+ goto Finish;
+
+ if (iblock != 0)
+ continue;
+
+ ret = ext4_block_get(fs->bdev, &blk, fblock);
+ if (ret != EOK)
+ goto Finish;
+
+
+ struct jbd_sb * jbd_sb = (struct jbd_sb * )blk.data;
+ memset(jbd_sb, 0, sizeof(struct jbd_sb));
+
+ jbd_sb->header.magic = to_be32(JBD_MAGIC_NUMBER);
+ jbd_sb->header.blocktype = to_be32(JBD_SUPERBLOCK_V2);
+ jbd_sb->blocksize = to_be32(info->block_size);
+ jbd_sb->maxlen = to_be32(info->journal_blocks);
+ jbd_sb->nr_users = to_be32(1);
+ jbd_sb->first = to_be32(1);
+ jbd_sb->sequence = to_be32(1);
+
+ ext4_bcache_set_dirty(blk.buf);
+ ret = ext4_block_set(fs->bdev, &blk);
+ if (ret != EOK)
+ goto Finish;
+ }
+
+ memcpy(fs->sb.journal_blocks, inode->blocks, sizeof(inode->blocks));
+
+ Finish:
+ ext4_fs_put_inode_ref(&inode_ref);
+
+ return ret;
+}
+