* License.
*/
+#include "config.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
enum journal_location {JOURNAL_IS_INTERNAL, JOURNAL_IS_EXTERNAL};
-#define ANY_BLOCK ((blk_t) -1)
+#define ANY_BLOCK ((blk64_t) -1)
-int dump_all, dump_contents, dump_descriptors;
-blk_t block_to_dump, bitmap_to_dump, inode_block_to_dump;
-unsigned int group_to_dump, inode_offset_to_dump;
-ext2_ino_t inode_to_dump;
+static int dump_all, dump_contents, dump_descriptors;
+static blk64_t block_to_dump, bitmap_to_dump, inode_block_to_dump;
+static unsigned int group_to_dump, inode_offset_to_dump;
+static ext2_ino_t inode_to_dump;
struct journal_source
{
static void dump_metadata_block(FILE *, struct journal_source *,
journal_superblock_t*,
- unsigned int, unsigned int, int, tid_t);
+ unsigned int, unsigned int, unsigned int,
+ int, tid_t);
static void do_hexdump (FILE *, char *, int);
struct journal_source journal_source;
struct ext2_super_block *es = NULL;
- journal_source.where = 0;
+ journal_source.where = JOURNAL_IS_INTERNAL;
journal_source.fd = 0;
journal_source.file = 0;
dump_all = 0;
/ sizeof(struct ext2_inode));
inode_block_to_dump =
- current_fs->group_desc[inode_group].bg_inode_table +
+ ext2fs_inode_table_loc(current_fs, inode_group) +
(group_offset / inodes_per_block);
inode_offset_to_dump = ((group_offset % inodes_per_block)
* sizeof(struct ext2_inode));
- printf("Inode %u is at group %u, block %u, offset %u\n",
+ printf("Inode %u is at group %u, block %llu, offset %u\n",
inode_to_dump, inode_group,
inode_block_to_dump, inode_offset_to_dump);
}
group_to_dump = ((block_to_dump -
es->s_first_data_block)
/ es->s_blocks_per_group);
- bitmap_to_dump = current_fs->group_desc[group_to_dump].bg_block_bitmap;
+ bitmap_to_dump = ext2fs_block_bitmap_loc(current_fs, group_to_dump);
}
if (!journal_fn && check_fs_open(argv[0]))
memset(&journal_inode, 0, sizeof(struct ext2_inode));
memcpy(&journal_inode.i_block[0], es->s_jnl_blocks,
EXT2_N_BLOCKS*4);
+ journal_inode.i_size_high = es->s_jnl_blocks[15];
journal_inode.i_size = es->s_jnl_blocks[16];
journal_inode.i_links_count = 1;
journal_inode.i_mode = LINUX_S_IFREG | 0600;
close(journal_fd);
errout:
- if (out_file != stdout)
+ if (out_file && (out_file != stdout))
fclose(out_file);
return;
print_usage:
- fprintf(stderr, "%s: Usage: logdump [-ac] [-b<block>] [-i<inode>]\n\t"
+ fprintf(stderr, "%s: Usage: logdump [-acs] [-b<block>] [-i<filespec>]\n\t"
"[-f<journal_file>] [output_file]\n", argv[0]);
}
static int read_journal_block(const char *cmd, struct journal_source *source,
- off_t offset, char *buf, int size,
- unsigned int *got)
+ off_t offset, char *buf, unsigned int size)
{
int retval;
+ unsigned int got;
if (source->where == JOURNAL_IS_EXTERNAL) {
if (lseek(source->fd, offset, SEEK_SET) < 0) {
retval = errno;
- com_err(cmd, retval, "while seeking in reading journal");
- return retval;
+ goto seek_err;
}
retval = read(source->fd, buf, size);
- if (retval >= 0) {
- *got = retval;
- retval = 0;
- } else
+ if (retval < 0) {
retval = errno;
+ goto read_err;
+ }
+ got = retval;
+ retval = 0;
} else {
retval = ext2fs_file_lseek(source->file, offset,
EXT2_SEEK_SET, NULL);
if (retval) {
+ seek_err:
com_err(cmd, retval, "while seeking in reading journal");
return retval;
}
-
- retval = ext2fs_file_read(source->file, buf, size, got);
+ retval = ext2fs_file_read(source->file, buf, size, &got);
+ if (retval) {
+ read_err:
+ com_err(cmd, retval, "while reading journal");
+ return retval;
+ }
}
-
- if (retval)
- com_err(cmd, retval, "while while reading journal");
- else if (*got != (unsigned int) size) {
- com_err(cmd, 0, "short read (read %d, expected %d) while while reading journal", *got, size);
+ if (got != size) {
+ com_err(cmd, 0, "short read (read %u, expected %u) "
+ "while reading journal", got, size);
retval = -1;
}
-
return retval;
}
char buf[8192];
journal_superblock_t *jsb;
unsigned int blocksize = 1024;
- unsigned int got;
int retval;
__u32 magic, sequence, blocktype;
journal_header_t *header;
unsigned int blocknr = 0;
/* First, check to see if there's an ext2 superblock header */
- retval = read_journal_block(cmdname, source, 0,
- buf, 2048, &got);
+ retval = read_journal_block(cmdname, source, 0, buf, 2048);
if (retval)
return;
fprintf(out_file, "\tuuid=%s\n", jsb_buffer);
fprintf(out_file, "\tblocksize=%d\n", blocksize);
fprintf(out_file, "\tjournal data size %lu\n",
- (unsigned long) sb->s_blocks_count);
+ (unsigned long) ext2fs_blocks_count(sb));
}
}
/* Next, read the journal superblock */
retval = read_journal_block(cmdname, source, blocknr*blocksize,
- jsb_buffer, 1024, &got);
+ jsb_buffer, 1024);
if (retval)
return;
while (1) {
retval = read_journal_block(cmdname, source,
blocknr*blocksize, buf,
- blocksize, &got);
- if (retval || got != blocksize)
+ blocksize);
+ if (retval)
return;
header = (journal_header_t *) buf;
unsigned int *blockp, int blocksize,
tid_t transaction)
{
- int offset;
+ int offset, tag_size = JBD_TAG_SIZE32;
char *tagp;
journal_block_tag_t *tag;
unsigned int blocknr;
__u32 tag_block;
__u32 tag_flags;
+ if (be32_to_cpu(jsb->s_feature_incompat) & JFS_FEATURE_INCOMPAT_64BIT)
+ tag_size = JBD_TAG_SIZE64;
offset = sizeof(journal_header_t);
blocknr = *blockp;
* the next one... */
tagp = &buf[offset];
tag = (journal_block_tag_t *) tagp;
- offset += sizeof(journal_block_tag_t);
+ offset += tag_size;
/* ... and if we have gone too far, then we've reached the
end of this block. */
break;
tag_block = be32_to_cpu(tag->t_blocknr);
- tag_flags = be32_to_cpu(tag->t_flags);
+ tag_flags = be16_to_cpu(tag->t_flags);
if (!(tag_flags & JFS_FLAG_SAME_UUID))
offset += 16;
dump_metadata_block(out_file, source, jsb,
- blocknr, tag_block, blocksize,
+ blocknr, tag_block, tag_flags, blocksize,
transaction);
++blocknr;
journal_superblock_t *jsb EXT2FS_ATTR((unused)),
unsigned int log_blocknr,
unsigned int fs_blocknr,
+ unsigned int log_tag_flags,
int blocksize,
tid_t transaction)
{
- unsigned int got;
int retval;
char buf[8192];
fprintf(out_file, " FS block %u logged at ", fs_blocknr);
if (!dump_all)
fprintf(out_file, "sequence %u, ", transaction);
- fprintf(out_file, "journal block %u\n", log_blocknr);
+ fprintf(out_file, "journal block %u (flags 0x%x)\n", log_blocknr,
+ log_tag_flags);
/* There are two major special cases to parse:
*
retval = read_journal_block("logdump", source,
blocksize * log_blocknr,
- buf, blocksize, &got);
+ buf, blocksize);
if (retval)
return;
int offset;
super = current_fs->super;
- offset = ((fs_blocknr - super->s_first_data_block) %
+ offset = ((block_to_dump - super->s_first_data_block) %
super->s_blocks_per_group);
- fprintf(out_file, " (block bitmap for block %u: "
+ fprintf(out_file, " (block bitmap for block %llu: "
"block is %s)\n",
block_to_dump,
ext2fs_test_bit(offset, buf) ? "SET" : "CLEAR");