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) {
"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);
(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)
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));
}
if (errcode) {
com_err("htree_dump_int_block", errcode,
"while mapping logical block %u\n", blk);
- return;
+ 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 %u\n", blk);
- return;
+ goto errout;
}
htree_dump_int_node(fs, ino, inode, rootnode,
(struct ext2_dx_entry *) (buf+8),
cbuf, level);
+errout:
free(cbuf);
}
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;
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;
}
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;
}
pb.search_name = argv[2];
pb.len = strlen(pb.search_name);
- ext2fs_block_iterate2(current_fs, inode, 0, 0, search_dir_block, &pb);
+ ext2fs_block_iterate2(current_fs, inode, BLOCK_FLAG_READ_ONLY, 0,
+ search_dir_block, &pb);
free(pb.buf);
}
strncmp(p->search_name, dirent->name,
p->len) == 0) {
printf("Entry found at logical block %lld, "
- "phys %u, offset %u\n", blockcnt,
+ "phys %u, offset %u\n", (long long)blockcnt,
*blocknr, offset);
printf("offset %u\n", offset);
return BLOCK_ABORT;