Whamcloud - gitweb
config: update config.{guess,sub}
[tools/e2fsprogs.git] / debugfs / logdump.c
index a1441b7..e286ae8 100644 (file)
@@ -1,14 +1,15 @@
 /*
  * logdump.c --- dump the contents of the journal out to a file
- * 
- * Authro: Stephen C. Tweedie, 2001  <sct@redhat.com>
+ *
+ * Author: Stephen C. Tweedie, 2001  <sct@redhat.com>
  * Copyright (C) 2001 Red Hat, Inc.
- * Based on portions  Copyright (C) 1994 Theodore Ts'o.  
+ * Based on portions  Copyright (C) 1994 Theodore Ts'o.
  *
- * This file may be redistributed under the terms of the GNU Public 
+ * This file may be redistributed under the terms of the GNU Public
  * License.
  */
 
+#include "config.h"
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <utime.h>
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
-#else 
+#else
 extern int optind;
 extern char *optarg;
 #endif
-#ifdef HAVE_OPTRESET
-extern int optreset;           /* defined by BSD, but not others */
-#endif
 
 #include "debugfs.h"
+#include "blkid/blkid.h"
 #include "jfs_user.h"
+#include <uuid/uuid.h>
 
 enum journal_location {JOURNAL_IS_INTERNAL, JOURNAL_IS_EXTERNAL};
 
-int            dump_all, dump_contents, dump_descriptors;
-unsigned int   block_to_dump, group_to_dump, bitmap_to_dump;
-unsigned int   inode_block_to_dump, inode_offset_to_dump, bitmap_to_dump;
-ext2_ino_t     inode_to_dump;
+#define ANY_BLOCK ((blk64_t) -1)
+
+static int             dump_all, dump_super, dump_old, 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 
+struct journal_source
 {
        enum journal_location where;
        int fd;
@@ -59,8 +61,9 @@ static void dump_revoke_block(FILE *, char *, journal_superblock_t *,
                                  unsigned int, int, tid_t);
 
 static void dump_metadata_block(FILE *, struct journal_source *,
-                               journal_superblock_t*, 
-                               unsigned int, unsigned int, int, tid_t);
+                               journal_superblock_t*,
+                               unsigned int, unsigned int, unsigned int,
+                               int, tid_t);
 
 static void do_hexdump (FILE *, char *, int);
 
@@ -69,45 +72,40 @@ static void do_hexdump (FILE *, char *, int);
                blocknr -= (be32_to_cpu((jsb)->s_maxlen) -      \
                            be32_to_cpu((jsb)->s_first));
 
-
-void do_logdump(int argc, char **argv)
+void do_logdump(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
+                   void *infop EXT2FS_ATTR((unused)))
 {
        int             c;
        int             retval;
        char            *out_fn;
        FILE            *out_file;
-       
+
        char            *inode_spec = NULL;
        char            *journal_fn = NULL;
        int             journal_fd = 0;
+       int             use_sb = 0;
        ext2_ino_t      journal_inum;
        struct ext2_inode journal_inode;
        ext2_file_t     journal_file;
-       
        char            *tmp;
-       
-       const char      *logdump_usage = ("Usage: logdump "
-                                         "[-ac] [-b<block>] [-i<inode>] "
-                                         "[-f<journal_file>] [output_file]");
-       
        struct journal_source journal_source;
+       struct ext2_super_block *es = NULL;
 
-       optind = 0;
-#ifdef HAVE_OPTRESET
-       optreset = 1;           /* Makes BSD getopt happy */
-#endif
-       journal_source.where = 0;
+       journal_source.where = JOURNAL_IS_INTERNAL;
        journal_source.fd = 0;
        journal_source.file = 0;
        dump_all = 0;
+       dump_old = 0;
        dump_contents = 0;
+       dump_super = 0;
        dump_descriptors = 1;
-       block_to_dump = -1;
+       block_to_dump = ANY_BLOCK;
        bitmap_to_dump = -1;
-       inode_block_to_dump = -1;
+       inode_block_to_dump = ANY_BLOCK;
        inode_to_dump = -1;
-       
-       while ((c = getopt (argc, argv, "ab:ci:f:")) != EOF) {
+
+       reset_getopt();
+       while ((c = getopt (argc, argv, "ab:ci:f:OsS")) != EOF) {
                switch (c) {
                case 'a':
                        dump_all++;
@@ -131,19 +129,29 @@ void do_logdump(int argc, char **argv)
                        inode_spec = optarg;
                        dump_descriptors = 0;
                        break;
+               case 'O':
+                       dump_old++;
+                       break;
+               case 's':
+                       use_sb++;
+                       break;
+               case 'S':
+                       dump_super++;
+                       break;
                default:
-                       com_err(argv[0], 0, logdump_usage);
-                       return;
+                       goto print_usage;
                }
        }
        if (optind != argc && optind != argc-1) {
-               com_err(argv[0], 0, logdump_usage);
-               return;
+               goto print_usage;
        }
 
+       if (current_fs)
+               es = current_fs->super;
+
        if (inode_spec) {
                int inode_group, group_offset, inodes_per_block;
-               
+
                if (check_fs_open(argv[0]))
                        return;
 
@@ -152,18 +160,18 @@ void do_logdump(int argc, char **argv)
                        return;
 
                inode_group = ((inode_to_dump - 1)
-                              / current_fs->super->s_inodes_per_group);
+                              / es->s_inodes_per_group);
                group_offset = ((inode_to_dump - 1)
-                               % current_fs->super->s_inodes_per_group);
-               inodes_per_block = (current_fs->blocksize 
+                               % es->s_inodes_per_group);
+               inodes_per_block = (current_fs->blocksize
                                    / sizeof(struct ext2_inode));
-               
-               inode_block_to_dump = 
-                       current_fs->group_desc[inode_group].bg_inode_table + 
+
+               inode_block_to_dump =
+                       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);
        }
@@ -173,22 +181,22 @@ void do_logdump(int argc, char **argv)
        } else {
                out_fn = argv[optind];
                out_file = fopen(out_fn, "w");
-               if (!out_file < 0) {
+               if (!out_file) {
                        com_err(argv[0], errno, "while opening %s for logdump",
                                out_fn);
-                       return;
+                       goto errout;
                }
        }
 
-       if (block_to_dump != -1 && current_fs != NULL) {
-               group_to_dump = ((block_to_dump - 
-                                 current_fs->super->s_first_data_block)
-                                / current_fs->super->s_blocks_per_group);
-               bitmap_to_dump = current_fs->group_desc[group_to_dump].bg_block_bitmap;
+       if (block_to_dump != ANY_BLOCK && current_fs != NULL) {
+               group_to_dump = ((block_to_dump -
+                                 es->s_first_data_block)
+                                / es->s_blocks_per_group);
+               bitmap_to_dump = ext2fs_block_bitmap_loc(current_fs, group_to_dump);
        }
 
        if (!journal_fn && check_fs_open(argv[0]))
-               return;
+               goto errout;
 
        if (journal_fn) {
                /* Set up to read journal from a regular file somewhere */
@@ -196,45 +204,62 @@ void do_logdump(int argc, char **argv)
                if (journal_fd < 0) {
                        com_err(argv[0], errno, "while opening %s for logdump",
                                journal_fn);
-                       return;
+                       goto errout;
                }
-               
+
                journal_source.where = JOURNAL_IS_EXTERNAL;
                journal_source.fd = journal_fd;
-       } else if ((journal_inum = current_fs->super->s_journal_inum)) {
-               retval = ext2fs_read_inode(current_fs, journal_inum, 
-                                          &journal_inode);
-               if (retval) {
-                       com_err(argv[0], retval,
-                               "while reading inode %u", journal_inum);
-                       return;
+       } else if ((journal_inum = es->s_journal_inum)) {
+               if (use_sb) {
+                       if (es->s_jnl_backup_type != EXT3_JNL_BACKUP_BLOCKS) {
+                               com_err(argv[0], 0,
+                                       "no journal backup in super block\n");
+                               goto errout;
+                       }
+                       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;
+               } else {
+                       if (debugfs_read_inode(journal_inum, &journal_inode,
+                                              argv[0]))
+                               goto errout;
                }
 
-               retval = ext2fs_file_open(current_fs, journal_inum,
-                                         0, &journal_file);
+               retval = ext2fs_file_open2(current_fs, journal_inum,
+                                          &journal_inode, 0, &journal_file);
                if (retval) {
                        com_err(argv[0], retval, "while opening ext2 file");
-                       return;
+                       goto errout;
                }
                journal_source.where = JOURNAL_IS_INTERNAL;
                journal_source.file = journal_file;
-       } else if ((journal_fn =
-           ext2fs_find_block_device(current_fs->super->s_journal_dev))) {
+       } else {
+               char uuid[37];
+
+               uuid_unparse(es->s_journal_uuid, uuid);
+               journal_fn = blkid_get_devname(NULL, "UUID", uuid);
+               if (!journal_fn)
+                               journal_fn = blkid_devno_to_devname(es->s_journal_dev);
+               if (!journal_fn) {
+                       com_err(argv[0], 0, "filesystem has no journal");
+                       goto errout;
+               }
                journal_fd = open(journal_fn, O_RDONLY, 0);
                if (journal_fd < 0) {
                        com_err(argv[0], errno, "while opening %s for logdump",
                                journal_fn);
                        free(journal_fn);
-                       return;
+                       goto errout;
                }
                fprintf(out_file, "Using external journal found at %s\n",
                        journal_fn);
                free(journal_fn);
                journal_source.where = JOURNAL_IS_EXTERNAL;
                journal_source.fd = journal_fd;
-       } else {
-               com_err(argv[0], 0, "filesystem has no journal");
-               return;
        }
 
        dump_journal(argv[0], out_file, &journal_source);
@@ -244,49 +269,56 @@ void do_logdump(int argc, char **argv)
        else
                close(journal_fd);
 
-       if (out_file != stdout)
+errout:
+       if (out_file && (out_file != stdout))
                fclose(out_file);
 
        return;
+
+print_usage:
+       fprintf(stderr, "%s: Usage: logdump [-acsOS] [-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)
+static int read_journal_block(const char *cmd, struct journal_source *source,
+                             ext2_loff_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);
+               retval = ext2fs_file_llseek(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 != 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;
 }
 
@@ -308,55 +340,60 @@ static const char *type_to_name(int btype)
 }
 
 
-static void dump_journal(char *cmdname, FILE *out_file, 
+static void dump_journal(char *cmdname, FILE *out_file,
                         struct journal_source *source)
 {
        struct ext2_super_block *sb;
        char                    jsb_buffer[1024];
        char                    buf[8192];
        journal_superblock_t    *jsb;
-       int                     blocksize = 1024;
-       unsigned int            got;
+       unsigned int            blocksize = 1024;
        int                     retval;
        __u32                   magic, sequence, blocktype;
        journal_header_t        *header;
-       
        tid_t                   transaction;
        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;
 
        jsb = (journal_superblock_t *) buf;
        sb = (struct ext2_super_block *) (buf+1024);
-       if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC)) 
+#ifdef WORDS_BIGENDIAN
+       if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
                ext2fs_swap_super(sb);
-       
+#endif
+
        if ((be32_to_cpu(jsb->s_header.h_magic) != JFS_MAGIC_NUMBER) &&
            (sb->s_magic == EXT2_SUPER_MAGIC) &&
-           (sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) {
+           ext2fs_has_feature_journal_dev(sb)) {
                blocksize = EXT2_BLOCK_SIZE(sb);
                blocknr = (blocksize == 1024) ? 2 : 1;
-               uuid_unparse(&sb->s_uuid, jsb_buffer);
+               uuid_unparse(sb->s_uuid, jsb_buffer);
                fprintf(out_file, "Ext2 superblock header found.\n");
                if (dump_all) {
                        fprintf(out_file, "\tuuid=%s\n", jsb_buffer);
                        fprintf(out_file, "\tblocksize=%d\n", blocksize);
-                       fprintf(out_file, "\tjournal data size %ld\n",
-                               sb->s_blocks_count);
+                       fprintf(out_file, "\tjournal data size %lu\n",
+                               (unsigned long) ext2fs_blocks_count(sb));
                }
        }
-       
-       /* Next, read the journal superblock */
 
-       retval = read_journal_block(cmdname, source, blocknr*blocksize, 
-                                   jsb_buffer, 1024, &got);
+       /* Next, read the journal superblock */
+       retval = read_journal_block(cmdname, source,
+                                   ((ext2_loff_t) blocknr) * blocksize,
+                                   jsb_buffer, 1024);
        if (retval)
                return;
 
+       if (dump_super) {
+               e2p_list_journal_super(out_file, jsb_buffer,
+                                      current_fs->blocksize, 0);
+               fputc('\n', out_file);
+       }
+
        jsb = (journal_superblock_t *) jsb_buffer;
        if (be32_to_cpu(jsb->s_header.h_magic) != JFS_MAGIC_NUMBER) {
                fprintf(out_file,
@@ -370,46 +407,51 @@ static void dump_journal(char *cmdname, FILE *out_file,
        fprintf(out_file, "Journal starts at block %u, transaction %u\n",
                blocknr, transaction);
 
-       if (!blocknr)
+       if (!blocknr) {
                /* Empty journal, nothing to do. */
-               return;
-               
+               if (!dump_old)
+                       return;
+               else
+                       blocknr = 1;
+       }
+
        while (1) {
-               retval = read_journal_block(cmdname, source, 
-                                           blocknr*blocksize, buf,
-                                           blocksize, &got);
-               if (retval || got != blocksize)
+               retval = read_journal_block(cmdname, source,
+                               ((ext2_loff_t) blocknr) * blocksize,
+                               buf, blocksize);
+               if (retval)
                        return;
-       
+
                header = (journal_header_t *) buf;
 
                magic = be32_to_cpu(header->h_magic);
                sequence = be32_to_cpu(header->h_sequence);
                blocktype = be32_to_cpu(header->h_blocktype);
-               
+
                if (magic != JFS_MAGIC_NUMBER) {
                        fprintf (out_file, "No magic number at block %u: "
                                 "end of journal.\n", blocknr);
                        return;
                }
-               
+
                if (sequence != transaction) {
                        fprintf (out_file, "Found sequence %u (not %u) at "
-                                "block %u: end of journal.\n", 
+                                "block %u: end of journal.\n",
                                 sequence, transaction, blocknr);
-                       return;
+                       if (!dump_old)
+                               return;
                }
 
                if (dump_descriptors) {
                        fprintf (out_file, "Found expected sequence %u, "
                                 "type %u (%s) at block %u\n",
-                                sequence, blocktype, 
+                                sequence, blocktype,
                                 type_to_name(blocktype), blocknr);
                }
-               
+
                switch (blocktype) {
                case JFS_DESCRIPTOR_BLOCK:
-                       dump_descriptor_block(out_file, source, buf, jsb, 
+                       dump_descriptor_block(out_file, source, buf, jsb,
                                              &blocknr, blocksize,
                                              transaction);
                        continue;
@@ -419,10 +461,10 @@ static void dump_journal(char *cmdname, FILE *out_file,
                        blocknr++;
                        WRAP(jsb, blocknr);
                        continue;
-                       
+
                case JFS_REVOKE_BLOCK:
                        dump_revoke_block(out_file, buf, jsb,
-                                         blocknr, blocksize, 
+                                         blocknr, blocksize,
                                          transaction);
                        blocknr++;
                        WRAP(jsb, blocknr);
@@ -436,92 +478,123 @@ static void dump_journal(char *cmdname, FILE *out_file,
        }
 }
 
+static inline size_t journal_super_tag_bytes(journal_superblock_t *jsb)
+{
+       size_t sz;
+
+       if (JSB_HAS_INCOMPAT_FEATURE(jsb, JFS_FEATURE_INCOMPAT_CSUM_V3))
+               return sizeof(journal_block_tag3_t);
 
-static void dump_descriptor_block(FILE *out_file, 
-                                 struct journal_source *source, 
+       sz = sizeof(journal_block_tag_t);
+
+       if (JSB_HAS_INCOMPAT_FEATURE(jsb, JFS_FEATURE_INCOMPAT_CSUM_V2))
+               sz += sizeof(__u16);
+
+       if (JSB_HAS_INCOMPAT_FEATURE(jsb, JFS_FEATURE_INCOMPAT_64BIT))
+               return sz;
+
+       return sz - sizeof(__u32);
+}
+
+static void dump_descriptor_block(FILE *out_file,
+                                 struct journal_source *source,
                                  char *buf,
-                                 journal_superblock_t *jsb, 
+                                 journal_superblock_t *jsb,
                                  unsigned int *blockp, int blocksize,
                                  tid_t transaction)
 {
-       int                     offset;
+       int                     offset, tag_size, csum_size = 0;
        char                    *tagp;
        journal_block_tag_t     *tag;
        unsigned int            blocknr;
        __u32                   tag_block;
        __u32                   tag_flags;
-               
 
+       tag_size = journal_super_tag_bytes(jsb);
        offset = sizeof(journal_header_t);
        blocknr = *blockp;
 
-       if (dump_all) 
+       if (JSB_HAS_INCOMPAT_FEATURE(jsb, JFS_FEATURE_INCOMPAT_CSUM_V3) ||
+           JSB_HAS_INCOMPAT_FEATURE(jsb, JFS_FEATURE_INCOMPAT_CSUM_V2))
+               csum_size = sizeof(struct journal_block_tail);
+
+       if (dump_all)
                fprintf(out_file, "Dumping descriptor block, sequence %u, at "
                        "block %u:\n", transaction, blocknr);
-       
+
        ++blocknr;
        WRAP(jsb, blocknr);
-       
+
        do {
-               /* Work out the location of the current tag, and skip to 
+               /* Work out the location of the current tag, and skip to
                 * 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. */
-               if (offset > blocksize)
+               if (offset > blocksize - csum_size)
                        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, 
+               dump_metadata_block(out_file, source, jsb,
+                                   blocknr, tag_block, tag_flags, blocksize,
                                    transaction);
 
                ++blocknr;
                WRAP(jsb, blocknr);
-               
+
        } while (!(tag_flags & JFS_FLAG_LAST_TAG));
-       
+
        *blockp = blocknr;
 }
 
 
 static void dump_revoke_block(FILE *out_file, char *buf,
-                                 journal_superblock_t *jsb, 
-                                 unsigned int blocknr, int blocksize,
-                                 tid_t transaction)
+                             journal_superblock_t *jsb EXT2FS_ATTR((unused)),
+                             unsigned int blocknr,
+                             int blocksize EXT2FS_ATTR((unused)),
+                             tid_t transaction)
 {
        int                     offset, max;
        journal_revoke_header_t *header;
-       unsigned int            *entry, rblock;
-       
-       if (dump_all) 
+       unsigned long long      rblock;
+       int                     tag_size = sizeof(__u32);
+
+       if (dump_all)
                fprintf(out_file, "Dumping revoke block, sequence %u, at "
                        "block %u:\n", transaction, blocknr);
-       
+
+       if (be32_to_cpu(jsb->s_feature_incompat) & JFS_FEATURE_INCOMPAT_64BIT)
+               tag_size = sizeof(__u64);
+
        header = (journal_revoke_header_t *) buf;
        offset = sizeof(journal_revoke_header_t);
        max = be32_to_cpu(header->r_count);
 
        while (offset < max) {
-               entry = (unsigned int *) (buf + offset);
-               rblock = be32_to_cpu(*entry);
+               if (tag_size == sizeof(__u32)) {
+                       __u32 *entry = (__u32 *) (buf + offset);
+                       rblock = be32_to_cpu(*entry);
+               } else {
+                       __u64 *entry = (__u64 *) (buf + offset);
+                       rblock = ext2fs_be64_to_cpu(*entry);
+               }
                if (dump_all || rblock == block_to_dump) {
-                       fprintf(out_file, "  Revoke FS block %u", rblock);
+                       fprintf(out_file, "  Revoke FS block %llu", rblock);
                        if (dump_all)
                                fprintf(out_file, "\n");
                        else
                                fprintf(out_file," at block %u, sequence %u\n",
                                        blocknr, transaction);
                }
-               offset += 4;
+               offset += tag_size;
        }
 }
 
@@ -530,7 +603,7 @@ static void show_extent(FILE *out_file, int start_extent, int end_extent,
                        __u32 first_block)
 {
        if (start_extent >= 0 && first_block != 0)
-               fprintf(out_file, "(%d+%u): %u ", 
+               fprintf(out_file, "(%d+%u): %u ",
                        start_extent, end_extent-start_extent, first_block);
 }
 
@@ -542,80 +615,81 @@ static void show_indirect(FILE *out_file, const char *name, __u32 where)
 
 
 static void dump_metadata_block(FILE *out_file, struct journal_source *source,
-                               journal_superblock_t *jsb,
-                               unsigned int log_blocknr, 
-                               unsigned int fs_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];
-       
+
        if (!(dump_all
              || (fs_blocknr == block_to_dump)
              || (fs_blocknr == inode_block_to_dump)
              || (fs_blocknr == bitmap_to_dump)))
                return;
-       
+
        fprintf(out_file, "  FS block %u logged at ", fs_blocknr);
-       if (!dump_all) 
+       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:
-        * 
+        *
         * If this block is a block
         * bitmap block, we need to give it special treatment so that we
         * can log any allocates and deallocates which affect the
-        * block_to_dump query block. 
-        * 
+        * block_to_dump query block.
+        *
         * If the block is an inode block for the inode being searched
         * for, then we need to dump the contents of that inode
-        * structure symbolically.  
+        * structure symbolically.
         */
-       
+
        if (!(dump_contents && dump_all)
            && fs_blocknr != block_to_dump
-           && fs_blocknr != bitmap_to_dump 
+           && fs_blocknr != bitmap_to_dump
            && fs_blocknr != inode_block_to_dump)
                return;
-       
-       retval = read_journal_block("logdump", source, 
-                                   blocksize * log_blocknr,
-                                   buf, blocksize, &got);
+
+       retval = read_journal_block("logdump", source,
+                                   ((ext2_loff_t) log_blocknr) * blocksize,
+                                   buf, blocksize);
        if (retval)
                return;
-       
+
        if (fs_blocknr == bitmap_to_dump) {
                struct ext2_super_block *super;
                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: "
-                       "block is %s)\n", 
+
+               fprintf(out_file, "    (block bitmap for block %llu: "
+                       "block is %s)\n",
                        block_to_dump,
                        ext2fs_test_bit(offset, buf) ? "SET" : "CLEAR");
        }
-       
+
        if (fs_blocknr == inode_block_to_dump) {
                struct ext2_inode *inode;
                int first, prev, this, start_extent, i;
-               
+
                fprintf(out_file, "    (inode block for inode %u):\n",
                        inode_to_dump);
-               
+
                inode = (struct ext2_inode *) (buf + inode_offset_to_dump);
                internal_dump_inode(out_file, "    ", inode_to_dump, inode, 0);
-               
+
                /* Dump out the direct/indirect blocks here:
                 * internal_dump_inode can only dump them from the main
                 * on-disk inode, not from the journaled copy of the
                 * inode. */
-               
+
                fprintf (out_file, "    Blocks:  ");
                first = prev = start_extent = -1;
 
@@ -634,13 +708,13 @@ static void dump_metadata_block(FILE *out_file, struct journal_source *source,
                show_indirect(out_file, "IND", inode->i_block[i++]);
                show_indirect(out_file, "DIND", inode->i_block[i++]);
                show_indirect(out_file, "TIND", inode->i_block[i++]);
-               
+
                fprintf(out_file, "\n");
        }
 
        if (dump_contents)
                do_hexdump(out_file, buf, blocksize);
-       
+
 }
 
 static void do_hexdump (FILE *out_file, char *buf, int blocksize)
@@ -649,10 +723,10 @@ static void do_hexdump (FILE *out_file, char *buf, int blocksize)
        int *intp;
        char *charp;
        unsigned char c;
-       
+
        intp = (int *) buf;
        charp = (char *) buf;
-       
+
        for (i=0; i<blocksize; i+=16) {
                fprintf(out_file, "    %04x:  ", i);
                for (j=0; j<16; j+=4)