Whamcloud - gitweb
debugfs: cleanup gcc -Wall warnings
[tools/e2fsprogs.git] / debugfs / htree.c
index 2fb804e..83f558c 100644 (file)
@@ -44,6 +44,11 @@ static void htree_dump_leaf_node(ext2_filsys fs, ext2_ino_t ino,
        ext2_dirhash_t  hash, minor_hash;
        unsigned int    rec_len;
        int             hash_alg;
+       int             csum_size = 0;
+
+       if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
+                                      EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
+               csum_size = sizeof(struct ext2_dir_entry_tail);
 
        errcode = ext2fs_bmap2(fs, ino, inode, buf, 0, blk, 0, &pblk);
        if (errcode) {
@@ -52,8 +57,8 @@ static void htree_dump_leaf_node(ext2_filsys fs, ext2_ino_t ino,
                return;
        }
 
-       printf("Reading directory block %llu, phys %llu\n", blk, pblk);
-       errcode = ext2fs_read_dir_block2(current_fs, pblk, buf, 0);
+       fprintf(pager, "Reading directory block %llu, phys %llu\n", blk, pblk);
+       errcode = ext2fs_read_dir_block4(current_fs, pblk, buf, 0, ino);
        if (errcode) {
                com_err("htree_dump_leaf_node", errcode,
                        "while reading block %llu (%llu)\n",
@@ -74,15 +79,15 @@ static void htree_dump_leaf_node(ext2_filsys fs, ext2_ino_t ino,
                                (unsigned long) blk);
                        return;
                }
+               thislen = ext2fs_dirent_name_len(dirent);
                if (((offset + rec_len) > fs->blocksize) ||
                    (rec_len < 8) ||
                    ((rec_len % 4) != 0) ||
-                   ((((unsigned) dirent->name_len & 0xFF)+8) > rec_len)) {
+                   ((unsigned) thislen + 8 > rec_len)) {
                        fprintf(pager, "Corrupted directory block (%llu)!\n",
                                blk);
                        break;
                }
-               thislen = dirent->name_len & 0xFF;
                strncpy(name, dirent->name, thislen);
                name[thislen] = '\0';
                errcode = ext2fs_dirhash(hash_alg, name,
@@ -91,8 +96,23 @@ static void htree_dump_leaf_node(ext2_filsys fs, ext2_ino_t ino,
                if (errcode)
                        com_err("htree_dump_leaf_node", errcode,
                                "while calculating hash");
-               snprintf(tmp, EXT2_NAME_LEN + 64, "%u 0x%08x-%08x (%d) %s   ",
-                       dirent->inode, hash, minor_hash, rec_len, name);
+               if ((offset == fs->blocksize - csum_size) &&
+                   (dirent->inode == 0) &&
+                   (dirent->rec_len == csum_size) &&
+                   (dirent->name_len == EXT2_DIR_NAME_LEN_CSUM)) {
+                       struct ext2_dir_entry_tail *t;
+
+                       t = (struct ext2_dir_entry_tail *) dirent;
+
+                       snprintf(tmp, EXT2_NAME_LEN + 64,
+                                "leaf block checksum: 0x%08x  ",
+                                t->det_checksum);
+               } else {
+                       snprintf(tmp, EXT2_NAME_LEN + 64,
+                                "%u 0x%08x-%08x (%d) %s   ",
+                                dirent->inode, hash, minor_hash,
+                                rec_len, name);
+               }
                thislen = strlen(tmp);
                if (col + thislen > 80) {
                        fprintf(pager, "\n");
@@ -118,21 +138,20 @@ static void htree_dump_int_node(ext2_filsys fs, ext2_ino_t ino,
                                struct ext2_dx_entry *ent,
                                char *buf, int level)
 {
-       struct ext2_dx_countlimit       limit;
-       struct ext2_dx_entry            e;
+       struct ext2_dx_countlimit       dx_countlimit;
        struct ext2_dx_tail             *tail;
        int                             hash, i;
+       int                             limit, count;
        int                             remainder;
 
-       limit = *((struct ext2_dx_countlimit *) ent);
-       limit.count = ext2fs_le16_to_cpu(limit.count);
-       limit.limit = ext2fs_le16_to_cpu(limit.limit);
+       dx_countlimit = *((struct ext2_dx_countlimit *) ent);
+       count = ext2fs_le16_to_cpu(dx_countlimit.count);
+       limit = ext2fs_le16_to_cpu(dx_countlimit.limit);
 
-       fprintf(pager, "Number of entries (count): %d\n", limit.count);
-       fprintf(pager, "Number of entries (limit): %d\n", limit.limit);
+       fprintf(pager, "Number of entries (count): %d\n", count);
+       fprintf(pager, "Number of entries (limit): %d\n", limit);
 
-       remainder = fs->blocksize - (limit.limit *
-                                    sizeof(struct ext2_dx_entry));
+       remainder = fs->blocksize - (limit * sizeof(struct ext2_dx_entry));
        if (ent == (struct ext2_dx_entry *)(rootnode + 1))
                remainder -= sizeof(struct ext2_dx_root_info) + 24;
        else
@@ -140,12 +159,12 @@ static void htree_dump_int_node(ext2_filsys fs, ext2_ino_t ino,
        if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
                                       EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
            remainder == sizeof(struct ext2_dx_tail)) {
-               tail = (struct ext2_dx_tail *)(ent + limit.limit);
+               tail = (struct ext2_dx_tail *)(ent + limit);
                fprintf(pager, "Checksum: 0x%08x\n",
                        ext2fs_le32_to_cpu(tail->dt_checksum));
        }
 
-       for (i=0; i < limit.count; i++) {
+       for (i=0; i < count; i++) {
                hash = i ? ext2fs_le32_to_cpu(ent[i].hash) : 0;
                fprintf(pager, "Entry #%d: Hash 0x%08x%s, block %u\n", i,
                        hash, (hash & 1) ? " (**)" : "",
@@ -154,17 +173,19 @@ static void htree_dump_int_node(ext2_filsys fs, ext2_ino_t ino,
 
        fprintf(pager, "\n");
 
-       for (i=0; i < limit.count; i++) {
-               e.hash = ext2fs_le32_to_cpu(ent[i].hash);
-               e.block = ext2fs_le32_to_cpu(ent[i].block);
+       for (i=0; i < count; i++) {
+               unsigned int hashval, block;
+
+               hashval = ext2fs_le32_to_cpu(ent[i].hash);
+               block = ext2fs_le32_to_cpu(ent[i].block);
                fprintf(pager, "Entry #%d: Hash 0x%08x, block %u\n", i,
-                      i ? e.hash : 0, e.block);
+                      i ? hashval : 0, block);
                if (level)
                        htree_dump_int_block(fs, ino, inode, rootnode,
-                                            e.block, buf, level-1);
+                                            block, buf, level-1);
                else
                        htree_dump_leaf_node(fs, ino, inode, rootnode,
-                                            e.block, buf);
+                                            block, buf);
        }
 
        fprintf(pager, "---------------------\n");
@@ -216,7 +237,6 @@ void do_htree_dump(int argc, char *argv[])
        char            *buf = NULL;
        struct          ext2_dx_root_info  *rootnode;
        struct          ext2_dx_entry *ent;
-       struct          ext2_dx_countlimit *limit;
        errcode_t       errcode;
 
        if (check_fs_open(argv[0]))
@@ -270,7 +290,6 @@ void do_htree_dump(int argc, char *argv[])
        fprintf(pager, "\t Flags: %d\n", rootnode->unused_flags);
 
        ent = (struct ext2_dx_entry *) (buf + 24 + rootnode->info_length);
-       limit = (struct ext2_dx_countlimit *) ent;
 
        htree_dump_int_node(current_fs, ino, &inode, rootnode, ent,
                            buf + current_fs->blocksize,
@@ -410,7 +429,7 @@ static int search_dir_block(ext2_filsys fs, blk64_t *blocknr,
                        return BLOCK_ABORT;
                }
                if (dirent->inode &&
-                   p->len == (dirent->name_len & 0xFF) &&
+                   p->len == ext2fs_dirent_name_len(dirent) &&
                    strncmp(p->search_name, dirent->name,
                            p->len) == 0) {
                        printf("Entry found at logical block %lld, "