From: Theodore Ts'o Date: Tue, 16 Jan 2024 02:49:29 +0000 (-0500) Subject: debugfs: teach the dx_hash command the -v option X-Git-Tag: v1.47.1-rc1~74 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=6cde9c20dcea7f1a6085e742da94863636522cb1;p=tools%2Fe2fsprogs.git debugfs: teach the dx_hash command the -v option Add an option for dx_hash to print more details about the hash algorithm and hash seed to calculate the directory hash value. Signed-off-by: Theodore Ts'o --- diff --git a/debugfs/debugfs.8.in b/debugfs/debugfs.8.in index 5b5329c..7cf5c16 100644 --- a/debugfs/debugfs.8.in +++ b/debugfs/debugfs.8.in @@ -268,9 +268,24 @@ number, otherwise use the .B s_mmp_block field in the superblock to locate and use the existing MMP block. .TP -.BI dx_hash " [-h hash_alg] [-s hash_seed] filename" +.BI dx_hash " [-cv] [-h hash_alg] [-s hash_seed] filename" Calculate the directory hash of .IR filename . +The +.I -c +option will casefold the filename before calculating the hash. The +.I -v +option will make the +.B dx_hash +command more verbose and print the hash algorithm and hash seed to +calculate the hash. +If a file system is open, use the hash_seed and +default hash_algorithm used by the file system, although these can be +overridden by the +.I -h +and +.I -s +options. The hash algorithm specified with .I -h may be diff --git a/debugfs/htree.c b/debugfs/htree.c index a3e95dd..fab04e2 100644 --- a/debugfs/htree.c +++ b/debugfs/htree.c @@ -334,7 +334,7 @@ void do_dx_hash(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)), { ext2_dirhash_t hash, minor_hash; errcode_t err; - int c; + int c, verbose = 0; int hash_version = 0; __u32 hash_seed[4] = { 0, }; int hash_flags = 0; @@ -350,7 +350,7 @@ void do_dx_hash(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)), } reset_getopt(); - while ((c = getopt(argc, argv, "h:s:ce:")) != EOF) { + while ((c = getopt(argc, argv, "h:s:ce:v")) != EOF) { switch (c) { case 'h': hash_version = e2p_string2hash(optarg); @@ -375,14 +375,17 @@ void do_dx_hash(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)), return; } break; + case 'v': + verbose = 1; + break; default: goto print_usage; } } if (optind != argc-1) { print_usage: - com_err(argv[0], 0, "usage: dx_hash [-h hash_alg] " - "[-s hash_seed] [-c] [-e encoding] filename"); + com_err(argv[0], 0, "usage: dx_hash [-cv] [-h hash_alg] " + "[-s hash_seed] [-e encoding] filename"); return; } err = ext2fs_dirhash2(hash_version, argv[optind], @@ -395,6 +398,13 @@ void do_dx_hash(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)), } printf("Hash of %s is 0x%0x (minor 0x%0x)\n", argv[optind], hash, minor_hash); + if (verbose) { + char uuid_str[37]; + + uuid_unparse((__u8 *) hash_seed, uuid_str); + printf(" using hash algorithm %d and hash_seed %s\n", + hash_version, uuid_str); + } } /*