diff options
author | Theodore Ts'o <tytso@mit.edu> | 2024-01-15 21:49:29 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2024-01-15 21:49:29 -0500 |
commit | 6cde9c20dcea7f1a6085e742da94863636522cb1 (patch) | |
tree | da10f0cb262488a189e1b74bba7f67ce29d58952 | |
parent | 260dfea450e387cbd2c8de79a7c2eeacc26f74e9 (diff) | |
download | e2fsprogs-6cde9c20dcea7f1a6085e742da94863636522cb1.tar.gz |
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 <tytso@mit.edu>
-rw-r--r-- | debugfs/debugfs.8.in | 17 | ||||
-rw-r--r-- | debugfs/htree.c | 18 |
2 files changed, 30 insertions, 5 deletions
diff --git a/debugfs/debugfs.8.in b/debugfs/debugfs.8.in index 5b5329c38..7cf5c1659 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 a3e95ddb0..fab04e2b3 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); + } } /* |