[Ocfs2-tools-devel] [PATCH 1/3] fsck.ocfs2: Move to JBD2 header and structures.
Tao Ma
tao.ma at oracle.com
Sun Sep 7 19:46:55 PDT 2008
Joel Becker wrote:
> Change all defines and structures to JBD2 structures. This is backwards
> compatible with the JBD journals, and is capable of handling even the
> oldest ocfs2 filesystems.
>
> The only major functional change is to use journal_tag_size() instead of
> sizeof(journal_block_tag_t) when walking the descriptor block.
> fsck.ocfs2 and debugfs.ocfs2 are updated.
>
> Signed-off-by: Joel Becker <joel.becker at oracle.com>
> @@ -71,6 +71,7 @@ static void scan_journal(FILE *out, char *buf, int len,
> errcode_t read_journal(ocfs2_filesys *fs, uint64_t blkno, FILE *out)
> {
> char *buf = NULL;
> + char *jsb_buf = NULL;
> char *p;
> uint64_t blocknum;
> uint64_t len;
> @@ -81,6 +82,7 @@ errcode_t read_journal(ocfs2_filesys *fs, uint64_t blkno, FILE *out)
> int buflenbits;
> ocfs2_cached_inode *ci = NULL;
> errcode_t ret;
> + journal_superblock_t *jsb;
>
> ret = ocfs2_read_cached_inode(fs, blkno, &ci);
> if (ret) {
> @@ -88,6 +90,13 @@ errcode_t read_journal(ocfs2_filesys *fs, uint64_t blkno, FILE *out)
> goto bail;
> }
>
> + ret = ocfs2_malloc_block(fs->fs_io, &jsb_buf);
> + if (ret) {
> + com_err(gbls.cmd, ret,
> + "while allocating journal superblock buffer");
> + goto bail;
> + }
> +
> buflenbits = buflen >>
> OCFS2_RAW_SB(gbls.fs->fs_super)->s_blocksize_bits;
> ret = ocfs2_malloc_blocks(fs->fs_io, buflenbits, &buf);
> @@ -98,6 +107,7 @@ errcode_t read_journal(ocfs2_filesys *fs, uint64_t blkno, FILE *out)
>
> offset = 0;
> blocknum = 0;
> + jsb = (journal_superblock_t *)jsb_buf;
> while (1) {
> ret = ocfs2_file_read(ci, buf, buflen, offset, &got);
> if (ret) {
> @@ -112,13 +122,15 @@ errcode_t read_journal(ocfs2_filesys *fs, uint64_t blkno, FILE *out)
> len = got;
>
> if (offset == 0) {
> - dump_jbd_superblock(out, (journal_superblock_t *)buf);
> + dump_jbd_superblock(out, jsb);
> + memcpy(jsb_buf, buf, fs->fs_blocksize);
> + ocfs2_swap_journal_superblock(jsb);
you set jsb as jsb_buf above, but read the block in buf. So jsb will be
used uninitialized? You may need to move "memcpy" above the
dump_jbd_superblock if I read your code correctly.
> blocknum++;
> p += fs->fs_blocksize;
> len -= fs->fs_blocksize;
> }
>
> - scan_journal(out, p, len, &blocknum, &last_unknown);
> + scan_journal(out, jsb, p, len, &blocknum, &last_unknown);
>
> if (got < buflen)
> break;
> @@ -131,6 +143,8 @@ errcode_t read_journal(ocfs2_filesys *fs, uint64_t blkno, FILE *out)
> }
>
> bail:
> + if (jsb_buf)
> + ocfs2_free(&jsb_buf);
> if (buf)
> ocfs2_free(&buf);
> if (ci)
Regards,
Tao
More information about the Ocfs2-tools-devel
mailing list