static void htree_dump_int_block(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, struct ext2_dx_root_info * rootnode, blk_t blk, char *buf, int level) { char *cbuf; errcode_t errcode; blk_t pblk; cbuf = malloc(fs->blocksize); if (!cbuf) { fprintf(pager, "Couldn't allocate child block.\n"); return; } errcode = ext2fs_bmap(fs, ino, inode, buf, 0, blk, &pblk); if (errcode) { com_err("htree_dump_int_block", errcode, "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 %u\n", blk); goto errout; } htree_dump_int_node(fs, ino, inode, rootnode, (struct ext2_dx_entry *) (buf+8), cbuf, level); errout: free(cbuf); }
void do_htree_dump(int argc, char *argv[]) { ext2_ino_t ino; struct ext2_inode inode; int c; int long_opt = 0; blk_t blk; 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])) return; pager = open_pager(); reset_getopt(); while ((c = getopt (argc, argv, "l")) != EOF) { switch (c) { 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; } if (argc == optind) ino = cwd; else ino = string_to_inode(argv[optind]); if (!ino) goto errout; if (debugfs_read_inode(ino, &inode, argv[1])) goto errout; if (!LINUX_S_ISDIR(inode.i_mode)) { com_err(argv[0], 0, "Not a directory"); goto errout; } if ((inode.i_flags & EXT2_BTREE_FL) == 0) { com_err(argv[0], 0, "Not a hash-indexed directory"); goto errout; } buf = malloc(2*current_fs->blocksize); if (!buf) { com_err(argv[0], 0, "Couldn't allocate htree buffer"); goto errout; } errcode = ext2fs_bmap(current_fs, ino, &inode, buf, 0, 0, &blk); if (errcode) { com_err("do_htree_block", errcode, "while mapping logical block 0\n"); goto errout; } errcode = io_channel_read_blk(current_fs->io, blk, 1, buf); if (errcode) { com_err(argv[0], errcode, "Error reading root node"); goto errout; } rootnode = (struct ext2_dx_root_info *) (buf + 24); fprintf(pager, "Root node dump:\n"); 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); 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, rootnode->indirect_levels); errout: free(buf); close_pager(pager); }
void do_htree_dump(int argc, char *argv[]) { ext2_ino_t ino; struct ext2_inode inode; blk64_t blk; char *buf = NULL; struct ext2_dx_root_info *rootnode; struct ext2_dx_entry *ent; errcode_t errcode; if (check_fs_open(argv[0])) return; pager = open_pager(); if (common_inode_args_process(argc, argv, &ino, 0)) goto errout; if (debugfs_read_inode(ino, &inode, argv[1])) goto errout; if (!LINUX_S_ISDIR(inode.i_mode)) { com_err(argv[0], 0, "Not a directory"); goto errout; } if ((inode.i_flags & EXT2_BTREE_FL) == 0) { com_err(argv[0], 0, "Not a hash-indexed directory"); goto errout; } buf = malloc(2*current_fs->blocksize); if (!buf) { com_err(argv[0], 0, "Couldn't allocate htree buffer"); goto errout; } errcode = ext2fs_bmap2(current_fs, ino, &inode, buf, 0, 0, 0, &blk); if (errcode) { com_err("do_htree_block", errcode, "while mapping logical block 0\n"); goto errout; } errcode = io_channel_read_blk64(current_fs->io, blk, 1, buf); if (errcode) { com_err(argv[0], errcode, "Error reading root node"); goto errout; } rootnode = (struct ext2_dx_root_info *) (buf + 24); fprintf(pager, "Root node dump:\n"); 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); fprintf(pager, "\t Flags: %d\n", rootnode->unused_flags); ent = (struct ext2_dx_entry *) (buf + 24 + rootnode->info_length); htree_dump_int_node(current_fs, ino, &inode, rootnode, ent, buf + current_fs->blocksize, rootnode->indirect_levels); errout: free(buf); close_pager(pager); }