Whamcloud - gitweb
Fix gcc -Wall warnings, especially on 64-bit systems
[tools/e2fsprogs.git] / debugfs / htree.c
index 7af3d1b..d0e673e 100644 (file)
@@ -35,24 +35,29 @@ static void htree_dump_leaf_node(ext2_filsys fs, ext2_ino_t ino,
        struct ext2_dir_entry *dirent;
        int             thislen, col = 0;
        unsigned int    offset = 0;
-       char            name[EXT2_NAME_LEN];
+       char            name[EXT2_NAME_LEN + 1];
        char            tmp[EXT2_NAME_LEN + 16];
        blk_t           pblk;
        ext2_dirhash_t  hash;
+       int             hash_alg;
        
        errcode = ext2fs_bmap(fs, ino, inode, buf, 0, blk, &pblk);
        if (errcode) {
                com_err("htree_dump_leaf_node", errcode,
-                       "while mapping logical block %d\n", blk);
+                       "while mapping logical block %u\n", blk);
                return;
        }
 
        errcode = ext2fs_read_dir_block2(current_fs, pblk, buf, 0);
        if (errcode) {
                com_err("htree_dump_leaf_node", errcode,
-                       "while  reading block %d\n", blk);
+                       "while  reading block %u\n", blk);
                return;
        }
+       hash_alg = rootnode->hash_version;
+       if ((hash_alg <= EXT2_HASH_TEA) &&
+           (fs->super->s_flags & EXT2_FLAGS_UNSIGNED_HASH))
+               hash_alg += 3;
 
        while (offset < fs->blocksize) {
                dirent = (struct ext2_dir_entry *) (buf + offset);
@@ -60,14 +65,14 @@ static void htree_dump_leaf_node(ext2_filsys fs, ext2_ino_t ino,
                    (dirent->rec_len < 8) ||
                    ((dirent->rec_len % 4) != 0) ||
                    (((dirent->name_len & 0xFF)+8) > dirent->rec_len)) {
-                       fprintf(pager, "Corrupted directory block (%d)!\n", blk);
+                       fprintf(pager, "Corrupted directory block (%u)!\n", blk);
                        break;
                }
                thislen = ((dirent->name_len & 0xFF) < EXT2_NAME_LEN) ?
                        (dirent->name_len & 0xFF) : EXT2_NAME_LEN;
                strncpy(name, dirent->name, thislen);
                name[thislen] = '\0';
-               errcode = ext2fs_dirhash(rootnode->hash_version, name,
+               errcode = ext2fs_dirhash(hash_alg, name,
                                         thislen, fs->super->s_hash_seed,
                                         &hash, 0);
                if (errcode)
@@ -114,7 +119,7 @@ static void htree_dump_int_node(ext2_filsys fs, ext2_ino_t ino,
 
        for (i=0; i < limit.count; i++) {
                hash = i ? ext2fs_le32_to_cpu(ent[i].hash) : 0;
-               fprintf(pager, "Entry #%d: Hash 0x%08x%s, block %d\n", i,
+               fprintf(pager, "Entry #%d: Hash 0x%08x%s, block %u\n", i,
                        hash, (hash & 1) ? " (**)" : "",
                        ext2fs_le32_to_cpu(ent[i].block));
                }
@@ -124,7 +129,7 @@ static void htree_dump_int_node(ext2_filsys fs, ext2_ino_t ino,
        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);
-               fprintf(pager, "Entry #%d: Hash 0x%08x, block %d\n", i,
+               fprintf(pager, "Entry #%d: Hash 0x%08x, block %u\n", i,
                       i ? e.hash : 0, e.block);
                if (level)
                        htree_dump_int_block(fs, ino, inode, rootnode,
@@ -155,20 +160,21 @@ static void htree_dump_int_block(ext2_filsys fs, ext2_ino_t ino,
        errcode = ext2fs_bmap(fs, ino, inode, buf, 0, blk, &pblk);
        if (errcode) {
                com_err("htree_dump_int_block", errcode,
-                       "while mapping logical block %d\n", blk);
-               return;
+                       "while mapping logical block %u\n", blk);
+               goto errout;
        }
 
        errcode = io_channel_read_blk(current_fs->io, pblk, 1, buf);
        if (errcode) {
                com_err("htree_dump_int_block", errcode,
-                       "while  reading block %d\n", blk);
-               return;
+                       "while  reading block %u\n", blk);
+               goto errout;
        }
 
        htree_dump_int_node(fs, ino, inode, rootnode,
                            (struct ext2_dx_entry *) (buf+8),
                            cbuf, level);
+errout:
        free(cbuf);
 }
 
@@ -179,7 +185,7 @@ void do_htree_dump(int argc, char *argv[])
        ext2_ino_t      ino;
        struct ext2_inode inode;
        int             c;
-       int             long_opt;
+       int             long_opt = 0;
        char            *buf = NULL;
        struct          ext2_dx_root_info  *rootnode;
        struct          ext2_dx_entry *ent;
@@ -197,10 +203,13 @@ void do_htree_dump(int argc, char *argv[])
                case 'l':
                        long_opt++;
                        break;
+               default:
+                       goto print_usage;
                }
        }
 
        if (argc > optind+1) {
+       print_usage:
                com_err(0, 0, "Usage: htree_dump [-l] file");
                goto errout;
        }
@@ -241,7 +250,7 @@ void do_htree_dump(int argc, char *argv[])
        rootnode = (struct ext2_dx_root_info *) (buf + 24);
 
        fprintf(pager, "Root node dump:\n");
-       fprintf(pager, "\t Reserved zero: %d\n", rootnode->reserved_zero);
+       fprintf(pager, "\t Reserved zero: %u\n", rootnode->reserved_zero);
        fprintf(pager, "\t Hash Version: %d\n", rootnode->hash_version);
        fprintf(pager, "\t Info length: %d\n", rootnode->info_length);
        fprintf(pager, "\t Indirect levels: %d\n", rootnode->indirect_levels);
@@ -279,9 +288,12 @@ void do_dx_hash(int argc, char *argv[])
                case 'h':
                        hash_version = atoi(optarg);
                        break;
+               default:
+                       goto print_usage;
                }
        }
        if (optind != argc-1) {
+       print_usage:
                com_err(argv[0], 0, "usage: dx_hash filename");
                return;
        }
@@ -372,9 +384,9 @@ static int search_dir_block(ext2_filsys fs, blk_t *blocknr,
                    strncmp(p->search_name, dirent->name,
                            p->len) == 0) {
                        printf("Entry found at logical block %lld, "
-                              "phys %d, offset %d\n", blockcnt,
+                              "phys %u, offset %u\n", (long long)blockcnt,
                               *blocknr, offset);
-                       printf("offset %d\n", offset);
+                       printf("offset %u\n", offset);
                        return BLOCK_ABORT;
                }
                offset += dirent->rec_len;