blob: 03b62a75645022c850caecdd0a9209972ab77fbe [file] [log] [blame]
Theodore Ts'odf614db2002-02-25 04:28:45 -05001/*
2 * htree.c --- hash tree routines
Theodore Ts'oefc6f622008-08-27 23:07:54 -04003 *
Theodore Ts'odf614db2002-02-25 04:28:45 -05004 * Copyright (C) 2002 Theodore Ts'o. This file may be redistributed
5 * under the terms of the GNU Public License.
6 */
7
8#include <stdio.h>
9#include <unistd.h>
10#include <stdlib.h>
11#include <ctype.h>
12#include <string.h>
13#include <time.h>
14#ifdef HAVE_ERRNO_H
15#include <errno.h>
16#endif
17#include <sys/types.h>
18#ifdef HAVE_GETOPT_H
19#include <getopt.h>
Theodore Ts'oefc6f622008-08-27 23:07:54 -040020#else
Theodore Ts'odf614db2002-02-25 04:28:45 -050021extern int optind;
22extern char *optarg;
23#endif
Theodore Ts'odf614db2002-02-25 04:28:45 -050024
25#include "debugfs.h"
Theodore Ts'o42080a82009-07-11 23:23:16 -040026#include "uuid/uuid.h"
27#include "e2p/e2p.h"
Theodore Ts'odf614db2002-02-25 04:28:45 -050028
29static FILE *pager;
30
Theodore Ts'odf614db2002-02-25 04:28:45 -050031static void htree_dump_leaf_node(ext2_filsys fs, ext2_ino_t ino,
32 struct ext2_inode *inode,
Theodore Ts'o3e699062002-10-13 23:56:28 -040033 struct ext2_dx_root_info * rootnode,
JP Abgralle0ed7402014-03-19 19:08:39 -070034 blk64_t blk, char *buf)
Theodore Ts'odf614db2002-02-25 04:28:45 -050035{
36 errcode_t errcode;
37 struct ext2_dir_entry *dirent;
Theodore Ts'o54434922003-12-07 01:28:50 -050038 int thislen, col = 0;
39 unsigned int offset = 0;
Brian Behlendorfb7729002007-03-21 15:09:15 -040040 char name[EXT2_NAME_LEN + 1];
JP Abgralle0ed7402014-03-19 19:08:39 -070041 char tmp[EXT2_NAME_LEN + 64];
42 blk64_t pblk;
Theodore Ts'o226515d2008-08-08 11:56:07 -040043 ext2_dirhash_t hash, minor_hash;
Theodore Ts'o8a480352009-06-21 21:07:38 -040044 unsigned int rec_len;
45 int hash_alg;
Theodore Ts'oefc6f622008-08-27 23:07:54 -040046
JP Abgralle0ed7402014-03-19 19:08:39 -070047 errcode = ext2fs_bmap2(fs, ino, inode, buf, 0, blk, 0, &pblk);
Theodore Ts'odf614db2002-02-25 04:28:45 -050048 if (errcode) {
49 com_err("htree_dump_leaf_node", errcode,
JP Abgralle0ed7402014-03-19 19:08:39 -070050 "while mapping logical block %llu\n", blk);
Theodore Ts'odf614db2002-02-25 04:28:45 -050051 return;
52 }
53
JP Abgralle0ed7402014-03-19 19:08:39 -070054 fprintf(pager, "Reading directory block %llu, phys %llu\n", blk, pblk);
Theodore Ts'o8132d842002-10-02 22:07:17 -040055 errcode = ext2fs_read_dir_block2(current_fs, pblk, buf, 0);
Theodore Ts'odf614db2002-02-25 04:28:45 -050056 if (errcode) {
57 com_err("htree_dump_leaf_node", errcode,
JP Abgralle0ed7402014-03-19 19:08:39 -070058 "while reading block %llu (%llu)\n",
59 blk, pblk);
Theodore Ts'odf614db2002-02-25 04:28:45 -050060 return;
61 }
Theodore Ts'of77704e2006-11-11 22:32:35 -050062 hash_alg = rootnode->hash_version;
63 if ((hash_alg <= EXT2_HASH_TEA) &&
64 (fs->super->s_flags & EXT2_FLAGS_UNSIGNED_HASH))
65 hash_alg += 3;
Theodore Ts'odf614db2002-02-25 04:28:45 -050066
67 while (offset < fs->blocksize) {
68 dirent = (struct ext2_dir_entry *) (buf + offset);
Theodore Ts'o8a480352009-06-21 21:07:38 -040069 errcode = ext2fs_get_rec_len(fs, dirent, &rec_len);
70 if (errcode) {
71 com_err("htree_dump_leaf_inode", errcode,
72 "while getting rec_len for block %lu",
73 (unsigned long) blk);
74 return;
75 }
Theodore Ts'o5dd77db2008-08-25 21:08:19 -040076 if (((offset + rec_len) > fs->blocksize) ||
77 (rec_len < 8) ||
78 ((rec_len % 4) != 0) ||
Theodore Ts'o42080a82009-07-11 23:23:16 -040079 ((((unsigned) dirent->name_len & 0xFF)+8) > rec_len)) {
JP Abgralle0ed7402014-03-19 19:08:39 -070080 fprintf(pager, "Corrupted directory block (%llu)!\n",
81 blk);
Theodore Ts'odf614db2002-02-25 04:28:45 -050082 break;
83 }
JP Abgralle0ed7402014-03-19 19:08:39 -070084 thislen = dirent->name_len & 0xFF;
Theodore Ts'odf614db2002-02-25 04:28:45 -050085 strncpy(name, dirent->name, thislen);
86 name[thislen] = '\0';
Theodore Ts'of77704e2006-11-11 22:32:35 -050087 errcode = ext2fs_dirhash(hash_alg, name,
Theodore Ts'o3e699062002-10-13 23:56:28 -040088 thislen, fs->super->s_hash_seed,
Theodore Ts'o226515d2008-08-08 11:56:07 -040089 &hash, &minor_hash);
Theodore Ts'o52783e02002-03-11 15:04:45 -050090 if (errcode)
91 com_err("htree_dump_leaf_node", errcode,
92 "while calculating hash");
JP Abgralle0ed7402014-03-19 19:08:39 -070093 snprintf(tmp, EXT2_NAME_LEN + 64, "%u 0x%08x-%08x (%d) %s ",
94 dirent->inode, hash, minor_hash, rec_len, name);
Theodore Ts'odf614db2002-02-25 04:28:45 -050095 thislen = strlen(tmp);
96 if (col + thislen > 80) {
97 fprintf(pager, "\n");
98 col = 0;
99 }
100 fprintf(pager, "%s", tmp);
101 col += thislen;
Theodore Ts'o5dd77db2008-08-25 21:08:19 -0400102 offset += rec_len;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500103 }
104 fprintf(pager, "\n");
105}
106
107
108static void htree_dump_int_block(ext2_filsys fs, ext2_ino_t ino,
109 struct ext2_inode *inode,
Theodore Ts'o3e699062002-10-13 23:56:28 -0400110 struct ext2_dx_root_info * rootnode,
JP Abgralle0ed7402014-03-19 19:08:39 -0700111 blk64_t blk, char *buf, int level);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500112
113
114static void htree_dump_int_node(ext2_filsys fs, ext2_ino_t ino,
115 struct ext2_inode *inode,
Theodore Ts'o3e699062002-10-13 23:56:28 -0400116 struct ext2_dx_root_info * rootnode,
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400117 struct ext2_dx_entry *ent,
Theodore Ts'odf614db2002-02-25 04:28:45 -0500118 char *buf, int level)
119{
Theodore Ts'o621732c2002-07-18 22:19:51 -0400120 struct ext2_dx_countlimit limit;
121 struct ext2_dx_entry e;
Theodore Ts'o42e5b5f2002-09-22 15:27:28 -0400122 int hash, i;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400123
Theodore Ts'odf614db2002-02-25 04:28:45 -0500124
Theodore Ts'o621732c2002-07-18 22:19:51 -0400125 limit = *((struct ext2_dx_countlimit *) ent);
126 limit.count = ext2fs_le16_to_cpu(limit.count);
127 limit.limit = ext2fs_le16_to_cpu(limit.limit);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500128
Theodore Ts'o621732c2002-07-18 22:19:51 -0400129 fprintf(pager, "Number of entries (count): %d\n", limit.count);
130 fprintf(pager, "Number of entries (limit): %d\n", limit.limit);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500131
Theodore Ts'o42e5b5f2002-09-22 15:27:28 -0400132 for (i=0; i < limit.count; i++) {
133 hash = i ? ext2fs_le32_to_cpu(ent[i].hash) : 0;
Eric Sandeend0ff90d2006-09-12 14:56:15 -0400134 fprintf(pager, "Entry #%d: Hash 0x%08x%s, block %u\n", i,
Theodore Ts'o42e5b5f2002-09-22 15:27:28 -0400135 hash, (hash & 1) ? " (**)" : "",
Theodore Ts'o621732c2002-07-18 22:19:51 -0400136 ext2fs_le32_to_cpu(ent[i].block));
Theodore Ts'o42e5b5f2002-09-22 15:27:28 -0400137 }
Theodore Ts'odf614db2002-02-25 04:28:45 -0500138
139 fprintf(pager, "\n");
140
Theodore Ts'o621732c2002-07-18 22:19:51 -0400141 for (i=0; i < limit.count; i++) {
142 e.hash = ext2fs_le32_to_cpu(ent[i].hash);
143 e.block = ext2fs_le32_to_cpu(ent[i].block);
Takashi Sato8deb80a2006-03-18 21:43:46 -0500144 fprintf(pager, "Entry #%d: Hash 0x%08x, block %u\n", i,
Theodore Ts'o621732c2002-07-18 22:19:51 -0400145 i ? e.hash : 0, e.block);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500146 if (level)
Theodore Ts'o3e699062002-10-13 23:56:28 -0400147 htree_dump_int_block(fs, ino, inode, rootnode,
Theodore Ts'o621732c2002-07-18 22:19:51 -0400148 e.block, buf, level-1);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500149 else
Theodore Ts'o3e699062002-10-13 23:56:28 -0400150 htree_dump_leaf_node(fs, ino, inode, rootnode,
Theodore Ts'o621732c2002-07-18 22:19:51 -0400151 e.block, buf);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500152 }
153
154 fprintf(pager, "---------------------\n");
155}
156
157static void htree_dump_int_block(ext2_filsys fs, ext2_ino_t ino,
158 struct ext2_inode *inode,
Theodore Ts'o3e699062002-10-13 23:56:28 -0400159 struct ext2_dx_root_info * rootnode,
JP Abgralle0ed7402014-03-19 19:08:39 -0700160 blk64_t blk, char *buf, int level)
Theodore Ts'odf614db2002-02-25 04:28:45 -0500161{
162 char *cbuf;
163 errcode_t errcode;
JP Abgralle0ed7402014-03-19 19:08:39 -0700164 blk64_t pblk;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500165
166 cbuf = malloc(fs->blocksize);
167 if (!cbuf) {
168 fprintf(pager, "Couldn't allocate child block.\n");
169 return;
170 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400171
JP Abgralle0ed7402014-03-19 19:08:39 -0700172 errcode = ext2fs_bmap2(fs, ino, inode, buf, 0, blk, 0, &pblk);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500173 if (errcode) {
174 com_err("htree_dump_int_block", errcode,
JP Abgralle0ed7402014-03-19 19:08:39 -0700175 "while mapping logical block %llu\n", blk);
Brian Behlendorf89456552007-03-21 17:53:33 -0400176 goto errout;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500177 }
178
JP Abgralle0ed7402014-03-19 19:08:39 -0700179 errcode = io_channel_read_blk64(current_fs->io, pblk, 1, buf);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500180 if (errcode) {
181 com_err("htree_dump_int_block", errcode,
JP Abgralle0ed7402014-03-19 19:08:39 -0700182 "while reading block %llu\n", blk);
Brian Behlendorf89456552007-03-21 17:53:33 -0400183 goto errout;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500184 }
185
Theodore Ts'o3e699062002-10-13 23:56:28 -0400186 htree_dump_int_node(fs, ino, inode, rootnode,
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400187 (struct ext2_dx_entry *) (buf+8),
Theodore Ts'odf614db2002-02-25 04:28:45 -0500188 cbuf, level);
Brian Behlendorf89456552007-03-21 17:53:33 -0400189errout:
Theodore Ts'odf614db2002-02-25 04:28:45 -0500190 free(cbuf);
191}
192
193
194
195void do_htree_dump(int argc, char *argv[])
196{
197 ext2_ino_t ino;
198 struct ext2_inode inode;
JP Abgralle0ed7402014-03-19 19:08:39 -0700199 blk64_t blk;
Theodore Ts'o3e699062002-10-13 23:56:28 -0400200 char *buf = NULL;
201 struct ext2_dx_root_info *rootnode;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500202 struct ext2_dx_entry *ent;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500203 errcode_t errcode;
204
205 if (check_fs_open(argv[0]))
206 return;
207
208 pager = open_pager();
209
JP Abgralle0ed7402014-03-19 19:08:39 -0700210 if (common_inode_args_process(argc, argv, &ino, 0))
Theodore Ts'o155f5772002-07-21 14:17:45 -0400211 goto errout;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500212
213 if (debugfs_read_inode(ino, &inode, argv[1]))
Theodore Ts'o155f5772002-07-21 14:17:45 -0400214 goto errout;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500215
216 if (!LINUX_S_ISDIR(inode.i_mode)) {
217 com_err(argv[0], 0, "Not a directory");
Theodore Ts'o155f5772002-07-21 14:17:45 -0400218 goto errout;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500219 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400220
Theodore Ts'odf614db2002-02-25 04:28:45 -0500221 if ((inode.i_flags & EXT2_BTREE_FL) == 0) {
222 com_err(argv[0], 0, "Not a hash-indexed directory");
Theodore Ts'o155f5772002-07-21 14:17:45 -0400223 goto errout;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500224 }
225
226 buf = malloc(2*current_fs->blocksize);
227 if (!buf) {
228 com_err(argv[0], 0, "Couldn't allocate htree buffer");
Theodore Ts'o155f5772002-07-21 14:17:45 -0400229 goto errout;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500230 }
231
JP Abgralle0ed7402014-03-19 19:08:39 -0700232 errcode = ext2fs_bmap2(current_fs, ino, &inode, buf, 0, 0, 0, &blk);
Theodore Ts'o226515d2008-08-08 11:56:07 -0400233 if (errcode) {
234 com_err("do_htree_block", errcode,
235 "while mapping logical block 0\n");
236 goto errout;
237 }
238
JP Abgralle0ed7402014-03-19 19:08:39 -0700239 errcode = io_channel_read_blk64(current_fs->io, blk,
240 1, buf);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500241 if (errcode) {
242 com_err(argv[0], errcode, "Error reading root node");
243 goto errout;
244 }
245
Theodore Ts'o3e699062002-10-13 23:56:28 -0400246 rootnode = (struct ext2_dx_root_info *) (buf + 24);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500247
248 fprintf(pager, "Root node dump:\n");
Takashi Sato8deb80a2006-03-18 21:43:46 -0500249 fprintf(pager, "\t Reserved zero: %u\n", rootnode->reserved_zero);
Theodore Ts'o3e699062002-10-13 23:56:28 -0400250 fprintf(pager, "\t Hash Version: %d\n", rootnode->hash_version);
251 fprintf(pager, "\t Info length: %d\n", rootnode->info_length);
252 fprintf(pager, "\t Indirect levels: %d\n", rootnode->indirect_levels);
253 fprintf(pager, "\t Flags: %d\n", rootnode->unused_flags);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500254
Theodore Ts'o3e699062002-10-13 23:56:28 -0400255 ent = (struct ext2_dx_entry *) (buf + 24 + rootnode->info_length);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500256
Theodore Ts'o3e699062002-10-13 23:56:28 -0400257 htree_dump_int_node(current_fs, ino, &inode, rootnode, ent,
Theodore Ts'odf614db2002-02-25 04:28:45 -0500258 buf + current_fs->blocksize,
Theodore Ts'o3e699062002-10-13 23:56:28 -0400259 rootnode->indirect_levels);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500260
261errout:
Jim Meyering45e338f2009-02-23 18:07:50 +0100262 free(buf);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500263 close_pager(pager);
264}
265
266/*
267 * This function prints the hash of a given file.
268 */
269void do_dx_hash(int argc, char *argv[])
270{
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400271 ext2_dirhash_t hash, minor_hash;
Theodore Ts'o52783e02002-03-11 15:04:45 -0500272 errcode_t err;
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400273 int c;
274 int hash_version = 0;
275 __u32 hash_seed[4];
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400276
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400277 hash_seed[0] = hash_seed[1] = hash_seed[2] = hash_seed[3] = 0;
Theodore Ts'o88494bb2003-05-13 23:03:43 -0400278
279 reset_getopt();
Theodore Ts'of8bd5512008-09-10 11:30:46 -0400280 while ((c = getopt (argc, argv, "h:s:")) != EOF) {
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400281 switch (c) {
282 case 'h':
Theodore Ts'of8bd5512008-09-10 11:30:46 -0400283 hash_version = e2p_string2hash(optarg);
284 if (hash_version < 0)
285 hash_version = atoi(optarg);
286 break;
287 case 's':
Theodore Ts'o42080a82009-07-11 23:23:16 -0400288 if (uuid_parse(optarg, (unsigned char *) hash_seed)) {
Theodore Ts'of8bd5512008-09-10 11:30:46 -0400289 fprintf(stderr, "Invalid UUID format: %s\n",
290 optarg);
291 return;
292 }
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400293 break;
Theodore Ts'o49c6b4e2006-04-27 20:59:42 -0400294 default:
295 goto print_usage;
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400296 }
297 }
298 if (optind != argc-1) {
Theodore Ts'o49c6b4e2006-04-27 20:59:42 -0400299 print_usage:
Theodore Ts'of8bd5512008-09-10 11:30:46 -0400300 com_err(argv[0], 0, "usage: dx_hash [-h hash_alg] "
301 "[-s hash_seed] filename");
Theodore Ts'odf614db2002-02-25 04:28:45 -0500302 return;
303 }
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400304 err = ext2fs_dirhash(hash_version, argv[optind], strlen(argv[optind]),
305 hash_seed, &hash, &minor_hash);
Theodore Ts'o52783e02002-03-11 15:04:45 -0500306 if (err) {
307 com_err(argv[0], err, "while caclulating hash");
308 return;
309 }
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400310 printf("Hash of %s is 0x%0x (minor 0x%0x)\n", argv[optind],
311 hash, minor_hash);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500312}
313
314/*
315 * Search for particular directory entry (useful for debugging very
316 * large hash tree directories that have lost some blocks from the
317 * btree index).
318 */
319struct process_block_struct {
320 char *search_name;
321 char *buf;
322 int len;
323};
324
JP Abgralle0ed7402014-03-19 19:08:39 -0700325static int search_dir_block(ext2_filsys fs, blk64_t *blocknr,
326 e2_blkcnt_t blockcnt, blk64_t ref_blk,
Theodore Ts'odf614db2002-02-25 04:28:45 -0500327 int ref_offset, void *priv_data);
328
329void do_dirsearch(int argc, char *argv[])
330{
331 ext2_ino_t inode;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500332 struct process_block_struct pb;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400333
Theodore Ts'odf614db2002-02-25 04:28:45 -0500334 if (check_fs_open(argv[0]))
335 return;
336
337 if (argc != 3) {
338 com_err(0, 0, "Usage: dirsearch dir filename");
339 return;
340 }
341
342 inode = string_to_inode(argv[1]);
343 if (!inode)
344 return;
345
346 pb.buf = malloc(current_fs->blocksize);
347 if (!pb.buf) {
348 com_err("dirsearch", 0, "Couldn't allocate buffer");
349 return;
350 }
351 pb.search_name = argv[2];
352 pb.len = strlen(pb.search_name);
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400353
JP Abgralle0ed7402014-03-19 19:08:39 -0700354 ext2fs_block_iterate3(current_fs, inode, BLOCK_FLAG_READ_ONLY, 0,
Theodore Ts'o43323be2008-02-07 14:37:17 -0500355 search_dir_block, &pb);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500356
357 free(pb.buf);
358}
359
360
JP Abgralle0ed7402014-03-19 19:08:39 -0700361static int search_dir_block(ext2_filsys fs, blk64_t *blocknr,
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400362 e2_blkcnt_t blockcnt,
JP Abgralle0ed7402014-03-19 19:08:39 -0700363 blk64_t ref_blk EXT2FS_ATTR((unused)),
Theodore Ts'o54434922003-12-07 01:28:50 -0500364 int ref_offset EXT2FS_ATTR((unused)),
365 void *priv_data)
Theodore Ts'odf614db2002-02-25 04:28:45 -0500366{
367 struct process_block_struct *p;
368 struct ext2_dir_entry *dirent;
369 errcode_t errcode;
Theodore Ts'o54434922003-12-07 01:28:50 -0500370 unsigned int offset = 0;
Theodore Ts'o8a480352009-06-21 21:07:38 -0400371 unsigned int rec_len;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500372
373 if (blockcnt < 0)
374 return 0;
375
376 p = (struct process_block_struct *) priv_data;
377
JP Abgralle0ed7402014-03-19 19:08:39 -0700378 errcode = io_channel_read_blk64(current_fs->io, *blocknr, 1, p->buf);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500379 if (errcode) {
380 com_err("search_dir_block", errcode,
Theodore Ts'o54434922003-12-07 01:28:50 -0500381 "while reading block %lu", (unsigned long) *blocknr);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500382 return BLOCK_ABORT;
383 }
384
385 while (offset < fs->blocksize) {
386 dirent = (struct ext2_dir_entry *) (p->buf + offset);
Theodore Ts'o8a480352009-06-21 21:07:38 -0400387 errcode = ext2fs_get_rec_len(fs, dirent, &rec_len);
388 if (errcode) {
389 com_err("htree_dump_leaf_inode", errcode,
390 "while getting rec_len for block %lu",
391 (unsigned long) *blocknr);
Theodore Ts'o42080a82009-07-11 23:23:16 -0400392 return BLOCK_ABORT;
Theodore Ts'o8a480352009-06-21 21:07:38 -0400393 }
Theodore Ts'odf614db2002-02-25 04:28:45 -0500394 if (dirent->inode &&
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400395 p->len == (dirent->name_len & 0xFF) &&
Theodore Ts'odf614db2002-02-25 04:28:45 -0500396 strncmp(p->search_name, dirent->name,
397 p->len) == 0) {
398 printf("Entry found at logical block %lld, "
JP Abgralle0ed7402014-03-19 19:08:39 -0700399 "phys %llu, offset %u\n", (long long)blockcnt,
Theodore Ts'odf614db2002-02-25 04:28:45 -0500400 *blocknr, offset);
Takashi Sato8deb80a2006-03-18 21:43:46 -0500401 printf("offset %u\n", offset);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500402 return BLOCK_ABORT;
403 }
Theodore Ts'o5dd77db2008-08-25 21:08:19 -0400404 offset += rec_len;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500405 }
406 return 0;
407}
408