2002-02-25 12:28:45 +03:00
|
|
|
/*
|
|
|
|
* htree.c --- hash tree routines
|
2008-08-28 07:07:54 +04:00
|
|
|
*
|
2002-02-25 12:28:45 +03:00
|
|
|
* Copyright (C) 2002 Theodore Ts'o. This file may be redistributed
|
|
|
|
* under the terms of the GNU Public License.
|
|
|
|
*/
|
|
|
|
|
2011-09-19 01:34:37 +04:00
|
|
|
#include "config.h"
|
2002-02-25 12:28:45 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#ifdef HAVE_ERRNO_H
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef HAVE_GETOPT_H
|
|
|
|
#include <getopt.h>
|
2008-08-28 07:07:54 +04:00
|
|
|
#else
|
2002-02-25 12:28:45 +03:00
|
|
|
extern int optind;
|
|
|
|
extern char *optarg;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "debugfs.h"
|
2009-07-12 07:23:16 +04:00
|
|
|
#include "uuid/uuid.h"
|
|
|
|
#include "e2p/e2p.h"
|
2002-02-25 12:28:45 +03:00
|
|
|
|
|
|
|
static FILE *pager;
|
|
|
|
|
|
|
|
static void htree_dump_leaf_node(ext2_filsys fs, ext2_ino_t ino,
|
|
|
|
struct ext2_inode *inode,
|
2002-10-14 07:56:28 +04:00
|
|
|
struct ext2_dx_root_info * rootnode,
|
2009-09-08 06:46:17 +04:00
|
|
|
blk64_t blk, char *buf)
|
2002-02-25 12:28:45 +03:00
|
|
|
{
|
|
|
|
errcode_t errcode;
|
|
|
|
struct ext2_dir_entry *dirent;
|
2003-12-07 09:28:50 +03:00
|
|
|
int thislen, col = 0;
|
|
|
|
unsigned int offset = 0;
|
2007-03-21 22:09:15 +03:00
|
|
|
char name[EXT2_NAME_LEN + 1];
|
2011-11-21 00:47:02 +04:00
|
|
|
char tmp[EXT2_NAME_LEN + 64];
|
2009-09-08 06:46:17 +04:00
|
|
|
blk64_t pblk;
|
2008-08-08 19:56:07 +04:00
|
|
|
ext2_dirhash_t hash, minor_hash;
|
2009-06-22 05:07:38 +04:00
|
|
|
unsigned int rec_len;
|
|
|
|
int hash_alg;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2009-09-08 06:46:17 +04:00
|
|
|
errcode = ext2fs_bmap2(fs, ino, inode, buf, 0, blk, 0, &pblk);
|
2002-02-25 12:28:45 +03:00
|
|
|
if (errcode) {
|
|
|
|
com_err("htree_dump_leaf_node", errcode,
|
2009-09-08 06:46:17 +04:00
|
|
|
"while mapping logical block %llu\n", blk);
|
2002-02-25 12:28:45 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-14 12:54:20 +04:00
|
|
|
fprintf(pager, "Reading directory block %llu, phys %llu\n", blk, pblk);
|
2002-10-03 06:07:17 +04:00
|
|
|
errcode = ext2fs_read_dir_block2(current_fs, pblk, buf, 0);
|
2002-02-25 12:28:45 +03:00
|
|
|
if (errcode) {
|
|
|
|
com_err("htree_dump_leaf_node", errcode,
|
2009-09-08 06:46:17 +04:00
|
|
|
"while reading block %llu (%llu)\n",
|
|
|
|
blk, pblk);
|
2002-02-25 12:28:45 +03:00
|
|
|
return;
|
|
|
|
}
|
2006-11-12 06:32:35 +03:00
|
|
|
hash_alg = rootnode->hash_version;
|
|
|
|
if ((hash_alg <= EXT2_HASH_TEA) &&
|
|
|
|
(fs->super->s_flags & EXT2_FLAGS_UNSIGNED_HASH))
|
|
|
|
hash_alg += 3;
|
2002-02-25 12:28:45 +03:00
|
|
|
|
|
|
|
while (offset < fs->blocksize) {
|
|
|
|
dirent = (struct ext2_dir_entry *) (buf + offset);
|
2009-06-22 05:07:38 +04:00
|
|
|
errcode = ext2fs_get_rec_len(fs, dirent, &rec_len);
|
|
|
|
if (errcode) {
|
|
|
|
com_err("htree_dump_leaf_inode", errcode,
|
|
|
|
"while getting rec_len for block %lu",
|
|
|
|
(unsigned long) blk);
|
|
|
|
return;
|
|
|
|
}
|
2008-08-26 05:08:19 +04:00
|
|
|
if (((offset + rec_len) > fs->blocksize) ||
|
|
|
|
(rec_len < 8) ||
|
|
|
|
((rec_len % 4) != 0) ||
|
2009-07-12 07:23:16 +04:00
|
|
|
((((unsigned) dirent->name_len & 0xFF)+8) > rec_len)) {
|
2009-09-08 06:46:17 +04:00
|
|
|
fprintf(pager, "Corrupted directory block (%llu)!\n",
|
|
|
|
blk);
|
2002-02-25 12:28:45 +03:00
|
|
|
break;
|
|
|
|
}
|
2011-09-17 00:49:17 +04:00
|
|
|
thislen = dirent->name_len & 0xFF;
|
2002-02-25 12:28:45 +03:00
|
|
|
strncpy(name, dirent->name, thislen);
|
|
|
|
name[thislen] = '\0';
|
2006-11-12 06:32:35 +03:00
|
|
|
errcode = ext2fs_dirhash(hash_alg, name,
|
2002-10-14 07:56:28 +04:00
|
|
|
thislen, fs->super->s_hash_seed,
|
2008-08-08 19:56:07 +04:00
|
|
|
&hash, &minor_hash);
|
2002-03-11 23:04:45 +03:00
|
|
|
if (errcode)
|
|
|
|
com_err("htree_dump_leaf_node", errcode,
|
|
|
|
"while calculating hash");
|
2011-11-21 00:47:02 +04:00
|
|
|
snprintf(tmp, EXT2_NAME_LEN + 64, "%u 0x%08x-%08x (%d) %s ",
|
|
|
|
dirent->inode, hash, minor_hash, rec_len, name);
|
2002-02-25 12:28:45 +03:00
|
|
|
thislen = strlen(tmp);
|
|
|
|
if (col + thislen > 80) {
|
|
|
|
fprintf(pager, "\n");
|
|
|
|
col = 0;
|
|
|
|
}
|
|
|
|
fprintf(pager, "%s", tmp);
|
|
|
|
col += thislen;
|
2008-08-26 05:08:19 +04:00
|
|
|
offset += rec_len;
|
2002-02-25 12:28:45 +03:00
|
|
|
}
|
|
|
|
fprintf(pager, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void htree_dump_int_block(ext2_filsys fs, ext2_ino_t ino,
|
|
|
|
struct ext2_inode *inode,
|
2002-10-14 07:56:28 +04:00
|
|
|
struct ext2_dx_root_info * rootnode,
|
2009-09-08 06:46:17 +04:00
|
|
|
blk64_t blk, char *buf, int level);
|
2002-02-25 12:28:45 +03:00
|
|
|
|
|
|
|
|
|
|
|
static void htree_dump_int_node(ext2_filsys fs, ext2_ino_t ino,
|
|
|
|
struct ext2_inode *inode,
|
2002-10-14 07:56:28 +04:00
|
|
|
struct ext2_dx_root_info * rootnode,
|
2008-08-28 07:07:54 +04:00
|
|
|
struct ext2_dx_entry *ent,
|
2002-02-25 12:28:45 +03:00
|
|
|
char *buf, int level)
|
|
|
|
{
|
2002-07-19 06:19:51 +04:00
|
|
|
struct ext2_dx_countlimit limit;
|
|
|
|
struct ext2_dx_entry e;
|
2002-09-22 23:27:28 +04:00
|
|
|
int hash, i;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2002-02-25 12:28:45 +03:00
|
|
|
|
2002-07-19 06:19:51 +04:00
|
|
|
limit = *((struct ext2_dx_countlimit *) ent);
|
|
|
|
limit.count = ext2fs_le16_to_cpu(limit.count);
|
|
|
|
limit.limit = ext2fs_le16_to_cpu(limit.limit);
|
2002-02-25 12:28:45 +03:00
|
|
|
|
2002-07-19 06:19:51 +04:00
|
|
|
fprintf(pager, "Number of entries (count): %d\n", limit.count);
|
|
|
|
fprintf(pager, "Number of entries (limit): %d\n", limit.limit);
|
2002-02-25 12:28:45 +03:00
|
|
|
|
2002-09-22 23:27:28 +04:00
|
|
|
for (i=0; i < limit.count; i++) {
|
|
|
|
hash = i ? ext2fs_le32_to_cpu(ent[i].hash) : 0;
|
2006-09-12 22:56:15 +04:00
|
|
|
fprintf(pager, "Entry #%d: Hash 0x%08x%s, block %u\n", i,
|
2002-09-22 23:27:28 +04:00
|
|
|
hash, (hash & 1) ? " (**)" : "",
|
2002-07-19 06:19:51 +04:00
|
|
|
ext2fs_le32_to_cpu(ent[i].block));
|
2002-09-22 23:27:28 +04:00
|
|
|
}
|
2002-02-25 12:28:45 +03:00
|
|
|
|
|
|
|
fprintf(pager, "\n");
|
|
|
|
|
2002-07-19 06:19:51 +04:00
|
|
|
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);
|
2006-03-19 05:43:46 +03:00
|
|
|
fprintf(pager, "Entry #%d: Hash 0x%08x, block %u\n", i,
|
2002-07-19 06:19:51 +04:00
|
|
|
i ? e.hash : 0, e.block);
|
2002-02-25 12:28:45 +03:00
|
|
|
if (level)
|
2002-10-14 07:56:28 +04:00
|
|
|
htree_dump_int_block(fs, ino, inode, rootnode,
|
2002-07-19 06:19:51 +04:00
|
|
|
e.block, buf, level-1);
|
2002-02-25 12:28:45 +03:00
|
|
|
else
|
2002-10-14 07:56:28 +04:00
|
|
|
htree_dump_leaf_node(fs, ino, inode, rootnode,
|
2002-07-19 06:19:51 +04:00
|
|
|
e.block, buf);
|
2002-02-25 12:28:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(pager, "---------------------\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void htree_dump_int_block(ext2_filsys fs, ext2_ino_t ino,
|
|
|
|
struct ext2_inode *inode,
|
2002-10-14 07:56:28 +04:00
|
|
|
struct ext2_dx_root_info * rootnode,
|
2009-09-08 06:46:17 +04:00
|
|
|
blk64_t blk, char *buf, int level)
|
2002-02-25 12:28:45 +03:00
|
|
|
{
|
|
|
|
char *cbuf;
|
|
|
|
errcode_t errcode;
|
2009-09-08 06:46:17 +04:00
|
|
|
blk64_t pblk;
|
2002-02-25 12:28:45 +03:00
|
|
|
|
|
|
|
cbuf = malloc(fs->blocksize);
|
|
|
|
if (!cbuf) {
|
|
|
|
fprintf(pager, "Couldn't allocate child block.\n");
|
|
|
|
return;
|
|
|
|
}
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2009-09-08 06:46:17 +04:00
|
|
|
errcode = ext2fs_bmap2(fs, ino, inode, buf, 0, blk, 0, &pblk);
|
2002-02-25 12:28:45 +03:00
|
|
|
if (errcode) {
|
|
|
|
com_err("htree_dump_int_block", errcode,
|
2009-09-08 06:46:17 +04:00
|
|
|
"while mapping logical block %llu\n", blk);
|
2007-03-22 00:53:33 +03:00
|
|
|
goto errout;
|
2002-02-25 12:28:45 +03:00
|
|
|
}
|
|
|
|
|
2009-09-08 05:14:24 +04:00
|
|
|
errcode = io_channel_read_blk64(current_fs->io, pblk, 1, buf);
|
2002-02-25 12:28:45 +03:00
|
|
|
if (errcode) {
|
|
|
|
com_err("htree_dump_int_block", errcode,
|
2009-09-08 06:46:17 +04:00
|
|
|
"while reading block %llu\n", blk);
|
2007-03-22 00:53:33 +03:00
|
|
|
goto errout;
|
2002-02-25 12:28:45 +03:00
|
|
|
}
|
|
|
|
|
2002-10-14 07:56:28 +04:00
|
|
|
htree_dump_int_node(fs, ino, inode, rootnode,
|
2002-06-27 00:52:10 +04:00
|
|
|
(struct ext2_dx_entry *) (buf+8),
|
2002-02-25 12:28:45 +03:00
|
|
|
cbuf, level);
|
2007-03-22 00:53:33 +03:00
|
|
|
errout:
|
2002-02-25 12:28:45 +03:00
|
|
|
free(cbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void do_htree_dump(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
ext2_ino_t ino;
|
|
|
|
struct ext2_inode inode;
|
2009-09-08 06:46:17 +04:00
|
|
|
blk64_t blk;
|
2002-10-14 07:56:28 +04:00
|
|
|
char *buf = NULL;
|
|
|
|
struct ext2_dx_root_info *rootnode;
|
2002-02-25 12:28:45 +03:00
|
|
|
struct ext2_dx_entry *ent;
|
|
|
|
errcode_t errcode;
|
|
|
|
|
|
|
|
if (check_fs_open(argv[0]))
|
|
|
|
return;
|
|
|
|
|
|
|
|
pager = open_pager();
|
|
|
|
|
2011-05-11 20:46:19 +04:00
|
|
|
if (common_inode_args_process(argc, argv, &ino, 0))
|
2002-07-21 22:17:45 +04:00
|
|
|
goto errout;
|
2002-02-25 12:28:45 +03:00
|
|
|
|
|
|
|
if (debugfs_read_inode(ino, &inode, argv[1]))
|
2002-07-21 22:17:45 +04:00
|
|
|
goto errout;
|
2002-02-25 12:28:45 +03:00
|
|
|
|
|
|
|
if (!LINUX_S_ISDIR(inode.i_mode)) {
|
|
|
|
com_err(argv[0], 0, "Not a directory");
|
2002-07-21 22:17:45 +04:00
|
|
|
goto errout;
|
2002-02-25 12:28:45 +03:00
|
|
|
}
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2002-02-25 12:28:45 +03:00
|
|
|
if ((inode.i_flags & EXT2_BTREE_FL) == 0) {
|
|
|
|
com_err(argv[0], 0, "Not a hash-indexed directory");
|
2002-07-21 22:17:45 +04:00
|
|
|
goto errout;
|
2002-02-25 12:28:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
buf = malloc(2*current_fs->blocksize);
|
|
|
|
if (!buf) {
|
|
|
|
com_err(argv[0], 0, "Couldn't allocate htree buffer");
|
2002-07-21 22:17:45 +04:00
|
|
|
goto errout;
|
2002-02-25 12:28:45 +03:00
|
|
|
}
|
|
|
|
|
2009-09-08 06:46:17 +04:00
|
|
|
errcode = ext2fs_bmap2(current_fs, ino, &inode, buf, 0, 0, 0, &blk);
|
2008-08-08 19:56:07 +04:00
|
|
|
if (errcode) {
|
|
|
|
com_err("do_htree_block", errcode,
|
|
|
|
"while mapping logical block 0\n");
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2009-09-08 05:14:24 +04:00
|
|
|
errcode = io_channel_read_blk64(current_fs->io, blk,
|
|
|
|
1, buf);
|
2002-02-25 12:28:45 +03:00
|
|
|
if (errcode) {
|
|
|
|
com_err(argv[0], errcode, "Error reading root node");
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2002-10-14 07:56:28 +04:00
|
|
|
rootnode = (struct ext2_dx_root_info *) (buf + 24);
|
2002-02-25 12:28:45 +03:00
|
|
|
|
|
|
|
fprintf(pager, "Root node dump:\n");
|
2006-03-19 05:43:46 +03:00
|
|
|
fprintf(pager, "\t Reserved zero: %u\n", rootnode->reserved_zero);
|
2002-10-14 07:56:28 +04:00
|
|
|
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);
|
2002-02-25 12:28:45 +03:00
|
|
|
|
2002-10-14 07:56:28 +04:00
|
|
|
ent = (struct ext2_dx_entry *) (buf + 24 + rootnode->info_length);
|
2002-02-25 12:28:45 +03:00
|
|
|
|
2002-10-14 07:56:28 +04:00
|
|
|
htree_dump_int_node(current_fs, ino, &inode, rootnode, ent,
|
2002-02-25 12:28:45 +03:00
|
|
|
buf + current_fs->blocksize,
|
2002-10-14 07:56:28 +04:00
|
|
|
rootnode->indirect_levels);
|
2002-02-25 12:28:45 +03:00
|
|
|
|
|
|
|
errout:
|
2009-02-23 20:07:50 +03:00
|
|
|
free(buf);
|
2002-02-25 12:28:45 +03:00
|
|
|
close_pager(pager);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function prints the hash of a given file.
|
|
|
|
*/
|
|
|
|
void do_dx_hash(int argc, char *argv[])
|
|
|
|
{
|
2002-06-27 00:52:10 +04:00
|
|
|
ext2_dirhash_t hash, minor_hash;
|
2002-03-11 23:04:45 +03:00
|
|
|
errcode_t err;
|
2002-06-27 00:52:10 +04:00
|
|
|
int c;
|
|
|
|
int hash_version = 0;
|
|
|
|
__u32 hash_seed[4];
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2002-06-27 00:52:10 +04:00
|
|
|
hash_seed[0] = hash_seed[1] = hash_seed[2] = hash_seed[3] = 0;
|
util.c, ls.c, logdump.c, htree.c, dump.c, debugfs.h, debugfs.c, ChangeLog:
util.c (reset_getopt), debugfs.c (do_open_filesys,
do_show_super_stats), ls.c (do_list_dir), dump.c (do_dump),
htree.c (do_htree_dump, do_dx_hash), logdump.c (do_logdump):
Define and use a new function, reset_getopt(), which does whatever
is necessary to reset getopt() again. This is different for
different implementations, so the portabilty issues are a bit of a
nightmare. (Addresses Debian bug #192834)
2003-05-14 07:03:43 +04:00
|
|
|
|
|
|
|
reset_getopt();
|
2008-09-10 19:30:46 +04:00
|
|
|
while ((c = getopt (argc, argv, "h:s:")) != EOF) {
|
2002-06-27 00:52:10 +04:00
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
2008-09-10 19:30:46 +04:00
|
|
|
hash_version = e2p_string2hash(optarg);
|
|
|
|
if (hash_version < 0)
|
|
|
|
hash_version = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 's':
|
2009-07-12 07:23:16 +04:00
|
|
|
if (uuid_parse(optarg, (unsigned char *) hash_seed)) {
|
2008-09-10 19:30:46 +04:00
|
|
|
fprintf(stderr, "Invalid UUID format: %s\n",
|
|
|
|
optarg);
|
|
|
|
return;
|
|
|
|
}
|
2002-06-27 00:52:10 +04:00
|
|
|
break;
|
2006-04-28 04:59:42 +04:00
|
|
|
default:
|
|
|
|
goto print_usage;
|
2002-06-27 00:52:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (optind != argc-1) {
|
2006-04-28 04:59:42 +04:00
|
|
|
print_usage:
|
2008-09-10 19:30:46 +04:00
|
|
|
com_err(argv[0], 0, "usage: dx_hash [-h hash_alg] "
|
|
|
|
"[-s hash_seed] filename");
|
2002-02-25 12:28:45 +03:00
|
|
|
return;
|
|
|
|
}
|
2002-06-27 00:52:10 +04:00
|
|
|
err = ext2fs_dirhash(hash_version, argv[optind], strlen(argv[optind]),
|
|
|
|
hash_seed, &hash, &minor_hash);
|
2002-03-11 23:04:45 +03:00
|
|
|
if (err) {
|
|
|
|
com_err(argv[0], err, "while caclulating hash");
|
|
|
|
return;
|
|
|
|
}
|
2002-06-27 00:52:10 +04:00
|
|
|
printf("Hash of %s is 0x%0x (minor 0x%0x)\n", argv[optind],
|
|
|
|
hash, minor_hash);
|
2002-02-25 12:28:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search for particular directory entry (useful for debugging very
|
|
|
|
* large hash tree directories that have lost some blocks from the
|
|
|
|
* btree index).
|
|
|
|
*/
|
|
|
|
struct process_block_struct {
|
|
|
|
char *search_name;
|
|
|
|
char *buf;
|
|
|
|
int len;
|
|
|
|
};
|
|
|
|
|
2009-09-08 06:46:17 +04:00
|
|
|
static int search_dir_block(ext2_filsys fs, blk64_t *blocknr,
|
|
|
|
e2_blkcnt_t blockcnt, blk64_t ref_blk,
|
2002-02-25 12:28:45 +03:00
|
|
|
int ref_offset, void *priv_data);
|
|
|
|
|
|
|
|
void do_dirsearch(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
ext2_ino_t inode;
|
|
|
|
struct process_block_struct pb;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2002-02-25 12:28:45 +03:00
|
|
|
if (check_fs_open(argv[0]))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (argc != 3) {
|
|
|
|
com_err(0, 0, "Usage: dirsearch dir filename");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
inode = string_to_inode(argv[1]);
|
|
|
|
if (!inode)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pb.buf = malloc(current_fs->blocksize);
|
|
|
|
if (!pb.buf) {
|
|
|
|
com_err("dirsearch", 0, "Couldn't allocate buffer");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pb.search_name = argv[2];
|
|
|
|
pb.len = strlen(pb.search_name);
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2009-09-08 06:46:17 +04:00
|
|
|
ext2fs_block_iterate3(current_fs, inode, BLOCK_FLAG_READ_ONLY, 0,
|
2008-02-07 22:37:17 +03:00
|
|
|
search_dir_block, &pb);
|
2002-02-25 12:28:45 +03:00
|
|
|
|
|
|
|
free(pb.buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-08 06:46:17 +04:00
|
|
|
static int search_dir_block(ext2_filsys fs, blk64_t *blocknr,
|
2008-08-28 07:07:54 +04:00
|
|
|
e2_blkcnt_t blockcnt,
|
2009-09-08 06:46:17 +04:00
|
|
|
blk64_t ref_blk EXT2FS_ATTR((unused)),
|
2003-12-07 09:28:50 +03:00
|
|
|
int ref_offset EXT2FS_ATTR((unused)),
|
|
|
|
void *priv_data)
|
2002-02-25 12:28:45 +03:00
|
|
|
{
|
|
|
|
struct process_block_struct *p;
|
|
|
|
struct ext2_dir_entry *dirent;
|
|
|
|
errcode_t errcode;
|
2003-12-07 09:28:50 +03:00
|
|
|
unsigned int offset = 0;
|
2009-06-22 05:07:38 +04:00
|
|
|
unsigned int rec_len;
|
2002-02-25 12:28:45 +03:00
|
|
|
|
|
|
|
if (blockcnt < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
p = (struct process_block_struct *) priv_data;
|
|
|
|
|
2009-09-08 05:14:24 +04:00
|
|
|
errcode = io_channel_read_blk64(current_fs->io, *blocknr, 1, p->buf);
|
2002-02-25 12:28:45 +03:00
|
|
|
if (errcode) {
|
|
|
|
com_err("search_dir_block", errcode,
|
2003-12-07 09:28:50 +03:00
|
|
|
"while reading block %lu", (unsigned long) *blocknr);
|
2002-02-25 12:28:45 +03:00
|
|
|
return BLOCK_ABORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (offset < fs->blocksize) {
|
|
|
|
dirent = (struct ext2_dir_entry *) (p->buf + offset);
|
2009-06-22 05:07:38 +04:00
|
|
|
errcode = ext2fs_get_rec_len(fs, dirent, &rec_len);
|
|
|
|
if (errcode) {
|
|
|
|
com_err("htree_dump_leaf_inode", errcode,
|
|
|
|
"while getting rec_len for block %lu",
|
|
|
|
(unsigned long) *blocknr);
|
2009-07-12 07:23:16 +04:00
|
|
|
return BLOCK_ABORT;
|
2009-06-22 05:07:38 +04:00
|
|
|
}
|
2002-02-25 12:28:45 +03:00
|
|
|
if (dirent->inode &&
|
2008-08-28 07:07:54 +04:00
|
|
|
p->len == (dirent->name_len & 0xFF) &&
|
2002-02-25 12:28:45 +03:00
|
|
|
strncmp(p->search_name, dirent->name,
|
|
|
|
p->len) == 0) {
|
|
|
|
printf("Entry found at logical block %lld, "
|
2009-09-08 06:46:17 +04:00
|
|
|
"phys %llu, offset %u\n", (long long)blockcnt,
|
2002-02-25 12:28:45 +03:00
|
|
|
*blocknr, offset);
|
2006-03-19 05:43:46 +03:00
|
|
|
printf("offset %u\n", offset);
|
2002-02-25 12:28:45 +03:00
|
|
|
return BLOCK_ABORT;
|
|
|
|
}
|
2008-08-26 05:08:19 +04:00
|
|
|
offset += rec_len;
|
2002-02-25 12:28:45 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|