Whamcloud - gitweb
debugfs: teach the dx_hash command the -v option
authorTheodore Ts'o <tytso@mit.edu>
Tue, 16 Jan 2024 02:49:29 +0000 (21:49 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 16 Jan 2024 02:49:29 +0000 (21:49 -0500)
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>
debugfs/debugfs.8.in
debugfs/htree.c

index 5b5329c..7cf5c16 100644 (file)
@@ -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
index a3e95dd..fab04e2 100644 (file)
@@ -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);
+       }
 }
 
 /*