blob: 05745eb3b4b7d33fdfe8c04ffae19433cbc581a1 [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
Theodore Ts'od1154eb2011-09-18 17:34:37 -04008#include "config.h"
Theodore Ts'odf614db2002-02-25 04:28:45 -05009#include <stdio.h>
10#include <unistd.h>
11#include <stdlib.h>
12#include <ctype.h>
13#include <string.h>
14#include <time.h>
15#ifdef HAVE_ERRNO_H
16#include <errno.h>
17#endif
18#include <sys/types.h>
19#ifdef HAVE_GETOPT_H
20#include <getopt.h>
Theodore Ts'oefc6f622008-08-27 23:07:54 -040021#else
Theodore Ts'odf614db2002-02-25 04:28:45 -050022extern int optind;
23extern char *optarg;
24#endif
Theodore Ts'odf614db2002-02-25 04:28:45 -050025
26#include "debugfs.h"
Theodore Ts'o42080a82009-07-11 23:23:16 -040027#include "uuid/uuid.h"
28#include "e2p/e2p.h"
Theodore Ts'odf614db2002-02-25 04:28:45 -050029
30static FILE *pager;
31
Theodore Ts'odf614db2002-02-25 04:28:45 -050032static void htree_dump_leaf_node(ext2_filsys fs, ext2_ino_t ino,
33 struct ext2_inode *inode,
Theodore Ts'o3e699062002-10-13 23:56:28 -040034 struct ext2_dx_root_info * rootnode,
Valerie Aurora Henson048786d2009-09-07 22:46:17 -040035 blk64_t blk, char *buf)
Theodore Ts'odf614db2002-02-25 04:28:45 -050036{
37 errcode_t errcode;
38 struct ext2_dir_entry *dirent;
Theodore Ts'o54434922003-12-07 01:28:50 -050039 int thislen, col = 0;
40 unsigned int offset = 0;
Brian Behlendorfb7729002007-03-21 15:09:15 -040041 char name[EXT2_NAME_LEN + 1];
Darrick J. Wong9c23b892011-11-20 15:47:02 -050042 char tmp[EXT2_NAME_LEN + 64];
Valerie Aurora Henson048786d2009-09-07 22:46:17 -040043 blk64_t pblk;
Theodore Ts'o226515d2008-08-08 11:56:07 -040044 ext2_dirhash_t hash, minor_hash;
Theodore Ts'o8a480352009-06-21 21:07:38 -040045 unsigned int rec_len;
46 int hash_alg;
Theodore Ts'oefc6f622008-08-27 23:07:54 -040047
Valerie Aurora Henson048786d2009-09-07 22:46:17 -040048 errcode = ext2fs_bmap2(fs, ino, inode, buf, 0, blk, 0, &pblk);
Theodore Ts'odf614db2002-02-25 04:28:45 -050049 if (errcode) {
50 com_err("htree_dump_leaf_node", errcode,
Valerie Aurora Henson048786d2009-09-07 22:46:17 -040051 "while mapping logical block %llu\n", blk);
Theodore Ts'odf614db2002-02-25 04:28:45 -050052 return;
53 }
54
Valerie Aurora Henson048786d2009-09-07 22:46:17 -040055 printf("Reading directory block %llu, phys %llu\n", blk, pblk);
Theodore Ts'o8132d842002-10-02 22:07:17 -040056 errcode = ext2fs_read_dir_block2(current_fs, pblk, buf, 0);
Theodore Ts'odf614db2002-02-25 04:28:45 -050057 if (errcode) {
58 com_err("htree_dump_leaf_node", errcode,
Valerie Aurora Henson048786d2009-09-07 22:46:17 -040059 "while reading block %llu (%llu)\n",
60 blk, pblk);
Theodore Ts'odf614db2002-02-25 04:28:45 -050061 return;
62 }
Theodore Ts'of77704e2006-11-11 22:32:35 -050063 hash_alg = rootnode->hash_version;
64 if ((hash_alg <= EXT2_HASH_TEA) &&
65 (fs->super->s_flags & EXT2_FLAGS_UNSIGNED_HASH))
66 hash_alg += 3;
Theodore Ts'odf614db2002-02-25 04:28:45 -050067
68 while (offset < fs->blocksize) {
69 dirent = (struct ext2_dir_entry *) (buf + offset);
Theodore Ts'o8a480352009-06-21 21:07:38 -040070 errcode = ext2fs_get_rec_len(fs, dirent, &rec_len);
71 if (errcode) {
72 com_err("htree_dump_leaf_inode", errcode,
73 "while getting rec_len for block %lu",
74 (unsigned long) blk);
75 return;
76 }
Theodore Ts'o5dd77db2008-08-25 21:08:19 -040077 if (((offset + rec_len) > fs->blocksize) ||
78 (rec_len < 8) ||
79 ((rec_len % 4) != 0) ||
Theodore Ts'o42080a82009-07-11 23:23:16 -040080 ((((unsigned) dirent->name_len & 0xFF)+8) > rec_len)) {
Valerie Aurora Henson048786d2009-09-07 22:46:17 -040081 fprintf(pager, "Corrupted directory block (%llu)!\n",
82 blk);
Theodore Ts'odf614db2002-02-25 04:28:45 -050083 break;
84 }
Eric Sandeen11ba79b2011-09-16 15:49:17 -050085 thislen = dirent->name_len & 0xFF;
Theodore Ts'odf614db2002-02-25 04:28:45 -050086 strncpy(name, dirent->name, thislen);
87 name[thislen] = '\0';
Theodore Ts'of77704e2006-11-11 22:32:35 -050088 errcode = ext2fs_dirhash(hash_alg, name,
Theodore Ts'o3e699062002-10-13 23:56:28 -040089 thislen, fs->super->s_hash_seed,
Theodore Ts'o226515d2008-08-08 11:56:07 -040090 &hash, &minor_hash);
Theodore Ts'o52783e02002-03-11 15:04:45 -050091 if (errcode)
92 com_err("htree_dump_leaf_node", errcode,
93 "while calculating hash");
Darrick J. Wong9c23b892011-11-20 15:47:02 -050094 snprintf(tmp, EXT2_NAME_LEN + 64, "%u 0x%08x-%08x (%d) %s ",
95 dirent->inode, hash, minor_hash, rec_len, name);
Theodore Ts'odf614db2002-02-25 04:28:45 -050096 thislen = strlen(tmp);
97 if (col + thislen > 80) {
98 fprintf(pager, "\n");
99 col = 0;
100 }
101 fprintf(pager, "%s", tmp);
102 col += thislen;
Theodore Ts'o5dd77db2008-08-25 21:08:19 -0400103 offset += rec_len;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500104 }
105 fprintf(pager, "\n");
106}
107
108
109static void htree_dump_int_block(ext2_filsys fs, ext2_ino_t ino,
110 struct ext2_inode *inode,
Theodore Ts'o3e699062002-10-13 23:56:28 -0400111 struct ext2_dx_root_info * rootnode,
Valerie Aurora Henson048786d2009-09-07 22:46:17 -0400112 blk64_t blk, char *buf, int level);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500113
114
115static void htree_dump_int_node(ext2_filsys fs, ext2_ino_t ino,
116 struct ext2_inode *inode,
Theodore Ts'o3e699062002-10-13 23:56:28 -0400117 struct ext2_dx_root_info * rootnode,
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400118 struct ext2_dx_entry *ent,
Theodore Ts'odf614db2002-02-25 04:28:45 -0500119 char *buf, int level)
120{
Theodore Ts'o621732c2002-07-18 22:19:51 -0400121 struct ext2_dx_countlimit limit;
122 struct ext2_dx_entry e;
Theodore Ts'o42e5b5f2002-09-22 15:27:28 -0400123 int hash, i;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400124
Theodore Ts'odf614db2002-02-25 04:28:45 -0500125
Theodore Ts'o621732c2002-07-18 22:19:51 -0400126 limit = *((struct ext2_dx_countlimit *) ent);
127 limit.count = ext2fs_le16_to_cpu(limit.count);
128 limit.limit = ext2fs_le16_to_cpu(limit.limit);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500129
Theodore Ts'o621732c2002-07-18 22:19:51 -0400130 fprintf(pager, "Number of entries (count): %d\n", limit.count);
131 fprintf(pager, "Number of entries (limit): %d\n", limit.limit);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500132
Theodore Ts'o42e5b5f2002-09-22 15:27:28 -0400133 for (i=0; i < limit.count; i++) {
134 hash = i ? ext2fs_le32_to_cpu(ent[i].hash) : 0;
Eric Sandeend0ff90d2006-09-12 14:56:15 -0400135 fprintf(pager, "Entry #%d: Hash 0x%08x%s, block %u\n", i,
Theodore Ts'o42e5b5f2002-09-22 15:27:28 -0400136 hash, (hash & 1) ? " (**)" : "",
Theodore Ts'o621732c2002-07-18 22:19:51 -0400137 ext2fs_le32_to_cpu(ent[i].block));
Theodore Ts'o42e5b5f2002-09-22 15:27:28 -0400138 }
Theodore Ts'odf614db2002-02-25 04:28:45 -0500139
140 fprintf(pager, "\n");
141
Theodore Ts'o621732c2002-07-18 22:19:51 -0400142 for (i=0; i < limit.count; i++) {
143 e.hash = ext2fs_le32_to_cpu(ent[i].hash);
144 e.block = ext2fs_le32_to_cpu(ent[i].block);
Takashi Sato8deb80a2006-03-18 21:43:46 -0500145 fprintf(pager, "Entry #%d: Hash 0x%08x, block %u\n", i,
Theodore Ts'o621732c2002-07-18 22:19:51 -0400146 i ? e.hash : 0, e.block);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500147 if (level)
Theodore Ts'o3e699062002-10-13 23:56:28 -0400148 htree_dump_int_block(fs, ino, inode, rootnode,
Theodore Ts'o621732c2002-07-18 22:19:51 -0400149 e.block, buf, level-1);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500150 else
Theodore Ts'o3e699062002-10-13 23:56:28 -0400151 htree_dump_leaf_node(fs, ino, inode, rootnode,
Theodore Ts'o621732c2002-07-18 22:19:51 -0400152 e.block, buf);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500153 }
154
155 fprintf(pager, "---------------------\n");
156}
157
158static void htree_dump_int_block(ext2_filsys fs, ext2_ino_t ino,
159 struct ext2_inode *inode,
Theodore Ts'o3e699062002-10-13 23:56:28 -0400160 struct ext2_dx_root_info * rootnode,
Valerie Aurora Henson048786d2009-09-07 22:46:17 -0400161 blk64_t blk, char *buf, int level)
Theodore Ts'odf614db2002-02-25 04:28:45 -0500162{
163 char *cbuf;
164 errcode_t errcode;
Valerie Aurora Henson048786d2009-09-07 22:46:17 -0400165 blk64_t pblk;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500166
167 cbuf = malloc(fs->blocksize);
168 if (!cbuf) {
169 fprintf(pager, "Couldn't allocate child block.\n");
170 return;
171 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400172
Valerie Aurora Henson048786d2009-09-07 22:46:17 -0400173 errcode = ext2fs_bmap2(fs, ino, inode, buf, 0, blk, 0, &pblk);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500174 if (errcode) {
175 com_err("htree_dump_int_block", errcode,
Valerie Aurora Henson048786d2009-09-07 22:46:17 -0400176 "while mapping logical block %llu\n", blk);
Brian Behlendorf89456552007-03-21 17:53:33 -0400177 goto errout;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500178 }
179
Valerie Aurora Henson24a117a2009-09-07 21:14:24 -0400180 errcode = io_channel_read_blk64(current_fs->io, pblk, 1, buf);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500181 if (errcode) {
182 com_err("htree_dump_int_block", errcode,
Valerie Aurora Henson048786d2009-09-07 22:46:17 -0400183 "while reading block %llu\n", blk);
Brian Behlendorf89456552007-03-21 17:53:33 -0400184 goto errout;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500185 }
186
Theodore Ts'o3e699062002-10-13 23:56:28 -0400187 htree_dump_int_node(fs, ino, inode, rootnode,
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400188 (struct ext2_dx_entry *) (buf+8),
Theodore Ts'odf614db2002-02-25 04:28:45 -0500189 cbuf, level);
Brian Behlendorf89456552007-03-21 17:53:33 -0400190errout:
Theodore Ts'odf614db2002-02-25 04:28:45 -0500191 free(cbuf);
192}
193
194
195
196void do_htree_dump(int argc, char *argv[])
197{
198 ext2_ino_t ino;
199 struct ext2_inode inode;
Valerie Aurora Henson048786d2009-09-07 22:46:17 -0400200 blk64_t blk;
Theodore Ts'o3e699062002-10-13 23:56:28 -0400201 char *buf = NULL;
202 struct ext2_dx_root_info *rootnode;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500203 struct ext2_dx_entry *ent;
204 struct ext2_dx_countlimit *limit;
205 errcode_t errcode;
206
207 if (check_fs_open(argv[0]))
208 return;
209
210 pager = open_pager();
211
Eric Sandeen1ec5d102011-05-11 11:46:19 -0500212 if (common_inode_args_process(argc, argv, &ino, 0))
Theodore Ts'o155f5772002-07-21 14:17:45 -0400213 goto errout;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500214
215 if (debugfs_read_inode(ino, &inode, argv[1]))
Theodore Ts'o155f5772002-07-21 14:17:45 -0400216 goto errout;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500217
218 if (!LINUX_S_ISDIR(inode.i_mode)) {
219 com_err(argv[0], 0, "Not a directory");
Theodore Ts'o155f5772002-07-21 14:17:45 -0400220 goto errout;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500221 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400222
Theodore Ts'odf614db2002-02-25 04:28:45 -0500223 if ((inode.i_flags & EXT2_BTREE_FL) == 0) {
224 com_err(argv[0], 0, "Not a hash-indexed directory");
Theodore Ts'o155f5772002-07-21 14:17:45 -0400225 goto errout;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500226 }
227
228 buf = malloc(2*current_fs->blocksize);
229 if (!buf) {
230 com_err(argv[0], 0, "Couldn't allocate htree buffer");
Theodore Ts'o155f5772002-07-21 14:17:45 -0400231 goto errout;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500232 }
233
Valerie Aurora Henson048786d2009-09-07 22:46:17 -0400234 errcode = ext2fs_bmap2(current_fs, ino, &inode, buf, 0, 0, 0, &blk);
Theodore Ts'o226515d2008-08-08 11:56:07 -0400235 if (errcode) {
236 com_err("do_htree_block", errcode,
237 "while mapping logical block 0\n");
238 goto errout;
239 }
240
Valerie Aurora Henson24a117a2009-09-07 21:14:24 -0400241 errcode = io_channel_read_blk64(current_fs->io, blk,
242 1, buf);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500243 if (errcode) {
244 com_err(argv[0], errcode, "Error reading root node");
245 goto errout;
246 }
247
Theodore Ts'o3e699062002-10-13 23:56:28 -0400248 rootnode = (struct ext2_dx_root_info *) (buf + 24);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500249
250 fprintf(pager, "Root node dump:\n");
Takashi Sato8deb80a2006-03-18 21:43:46 -0500251 fprintf(pager, "\t Reserved zero: %u\n", rootnode->reserved_zero);
Theodore Ts'o3e699062002-10-13 23:56:28 -0400252 fprintf(pager, "\t Hash Version: %d\n", rootnode->hash_version);
253 fprintf(pager, "\t Info length: %d\n", rootnode->info_length);
254 fprintf(pager, "\t Indirect levels: %d\n", rootnode->indirect_levels);
255 fprintf(pager, "\t Flags: %d\n", rootnode->unused_flags);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500256
Theodore Ts'o3e699062002-10-13 23:56:28 -0400257 ent = (struct ext2_dx_entry *) (buf + 24 + rootnode->info_length);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500258 limit = (struct ext2_dx_countlimit *) ent;
259
Theodore Ts'o3e699062002-10-13 23:56:28 -0400260 htree_dump_int_node(current_fs, ino, &inode, rootnode, ent,
Theodore Ts'odf614db2002-02-25 04:28:45 -0500261 buf + current_fs->blocksize,
Theodore Ts'o3e699062002-10-13 23:56:28 -0400262 rootnode->indirect_levels);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500263
264errout:
Jim Meyering45e338f2009-02-23 18:07:50 +0100265 free(buf);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500266 close_pager(pager);
267}
268
269/*
270 * This function prints the hash of a given file.
271 */
272void do_dx_hash(int argc, char *argv[])
273{
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400274 ext2_dirhash_t hash, minor_hash;
Theodore Ts'o52783e02002-03-11 15:04:45 -0500275 errcode_t err;
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400276 int c;
277 int hash_version = 0;
278 __u32 hash_seed[4];
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400279
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400280 hash_seed[0] = hash_seed[1] = hash_seed[2] = hash_seed[3] = 0;
Theodore Ts'o88494bb2003-05-13 23:03:43 -0400281
282 reset_getopt();
Theodore Ts'of8bd5512008-09-10 11:30:46 -0400283 while ((c = getopt (argc, argv, "h:s:")) != EOF) {
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400284 switch (c) {
285 case 'h':
Theodore Ts'of8bd5512008-09-10 11:30:46 -0400286 hash_version = e2p_string2hash(optarg);
287 if (hash_version < 0)
288 hash_version = atoi(optarg);
289 break;
290 case 's':
Theodore Ts'o42080a82009-07-11 23:23:16 -0400291 if (uuid_parse(optarg, (unsigned char *) hash_seed)) {
Theodore Ts'of8bd5512008-09-10 11:30:46 -0400292 fprintf(stderr, "Invalid UUID format: %s\n",
293 optarg);
294 return;
295 }
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400296 break;
Theodore Ts'o49c6b4e2006-04-27 20:59:42 -0400297 default:
298 goto print_usage;
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400299 }
300 }
301 if (optind != argc-1) {
Theodore Ts'o49c6b4e2006-04-27 20:59:42 -0400302 print_usage:
Theodore Ts'of8bd5512008-09-10 11:30:46 -0400303 com_err(argv[0], 0, "usage: dx_hash [-h hash_alg] "
304 "[-s hash_seed] filename");
Theodore Ts'odf614db2002-02-25 04:28:45 -0500305 return;
306 }
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400307 err = ext2fs_dirhash(hash_version, argv[optind], strlen(argv[optind]),
308 hash_seed, &hash, &minor_hash);
Theodore Ts'o52783e02002-03-11 15:04:45 -0500309 if (err) {
310 com_err(argv[0], err, "while caclulating hash");
311 return;
312 }
Theodore Ts'o503f9e72002-06-26 16:52:10 -0400313 printf("Hash of %s is 0x%0x (minor 0x%0x)\n", argv[optind],
314 hash, minor_hash);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500315}
316
317/*
318 * Search for particular directory entry (useful for debugging very
319 * large hash tree directories that have lost some blocks from the
320 * btree index).
321 */
322struct process_block_struct {
323 char *search_name;
324 char *buf;
325 int len;
326};
327
Valerie Aurora Henson048786d2009-09-07 22:46:17 -0400328static int search_dir_block(ext2_filsys fs, blk64_t *blocknr,
329 e2_blkcnt_t blockcnt, blk64_t ref_blk,
Theodore Ts'odf614db2002-02-25 04:28:45 -0500330 int ref_offset, void *priv_data);
331
332void do_dirsearch(int argc, char *argv[])
333{
334 ext2_ino_t inode;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500335 struct process_block_struct pb;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400336
Theodore Ts'odf614db2002-02-25 04:28:45 -0500337 if (check_fs_open(argv[0]))
338 return;
339
340 if (argc != 3) {
341 com_err(0, 0, "Usage: dirsearch dir filename");
342 return;
343 }
344
345 inode = string_to_inode(argv[1]);
346 if (!inode)
347 return;
348
349 pb.buf = malloc(current_fs->blocksize);
350 if (!pb.buf) {
351 com_err("dirsearch", 0, "Couldn't allocate buffer");
352 return;
353 }
354 pb.search_name = argv[2];
355 pb.len = strlen(pb.search_name);
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400356
Valerie Aurora Henson048786d2009-09-07 22:46:17 -0400357 ext2fs_block_iterate3(current_fs, inode, BLOCK_FLAG_READ_ONLY, 0,
Theodore Ts'o43323be2008-02-07 14:37:17 -0500358 search_dir_block, &pb);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500359
360 free(pb.buf);
361}
362
363
Valerie Aurora Henson048786d2009-09-07 22:46:17 -0400364static int search_dir_block(ext2_filsys fs, blk64_t *blocknr,
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400365 e2_blkcnt_t blockcnt,
Valerie Aurora Henson048786d2009-09-07 22:46:17 -0400366 blk64_t ref_blk EXT2FS_ATTR((unused)),
Theodore Ts'o54434922003-12-07 01:28:50 -0500367 int ref_offset EXT2FS_ATTR((unused)),
368 void *priv_data)
Theodore Ts'odf614db2002-02-25 04:28:45 -0500369{
370 struct process_block_struct *p;
371 struct ext2_dir_entry *dirent;
372 errcode_t errcode;
Theodore Ts'o54434922003-12-07 01:28:50 -0500373 unsigned int offset = 0;
Theodore Ts'o8a480352009-06-21 21:07:38 -0400374 unsigned int rec_len;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500375
376 if (blockcnt < 0)
377 return 0;
378
379 p = (struct process_block_struct *) priv_data;
380
Valerie Aurora Henson24a117a2009-09-07 21:14:24 -0400381 errcode = io_channel_read_blk64(current_fs->io, *blocknr, 1, p->buf);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500382 if (errcode) {
383 com_err("search_dir_block", errcode,
Theodore Ts'o54434922003-12-07 01:28:50 -0500384 "while reading block %lu", (unsigned long) *blocknr);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500385 return BLOCK_ABORT;
386 }
387
388 while (offset < fs->blocksize) {
389 dirent = (struct ext2_dir_entry *) (p->buf + offset);
Theodore Ts'o8a480352009-06-21 21:07:38 -0400390 errcode = ext2fs_get_rec_len(fs, dirent, &rec_len);
391 if (errcode) {
392 com_err("htree_dump_leaf_inode", errcode,
393 "while getting rec_len for block %lu",
394 (unsigned long) *blocknr);
Theodore Ts'o42080a82009-07-11 23:23:16 -0400395 return BLOCK_ABORT;
Theodore Ts'o8a480352009-06-21 21:07:38 -0400396 }
Theodore Ts'odf614db2002-02-25 04:28:45 -0500397 if (dirent->inode &&
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400398 p->len == (dirent->name_len & 0xFF) &&
Theodore Ts'odf614db2002-02-25 04:28:45 -0500399 strncmp(p->search_name, dirent->name,
400 p->len) == 0) {
401 printf("Entry found at logical block %lld, "
Valerie Aurora Henson048786d2009-09-07 22:46:17 -0400402 "phys %llu, offset %u\n", (long long)blockcnt,
Theodore Ts'odf614db2002-02-25 04:28:45 -0500403 *blocknr, offset);
Takashi Sato8deb80a2006-03-18 21:43:46 -0500404 printf("offset %u\n", offset);
Theodore Ts'odf614db2002-02-25 04:28:45 -0500405 return BLOCK_ABORT;
406 }
Theodore Ts'o5dd77db2008-08-25 21:08:19 -0400407 offset += rec_len;
Theodore Ts'odf614db2002-02-25 04:28:45 -0500408 }
409 return 0;
410}
411