]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_db: make the hash command print the dirent hash
authorDarrick J. Wong <djwong@kernel.org>
Mon, 5 Jun 2023 15:37:15 +0000 (08:37 -0700)
committerCarlos Maiolino <cem@kernel.org>
Thu, 22 Jun 2023 12:04:28 +0000 (14:04 +0200)
It turns out that the da and dir2 hashname functions are /not/ the same,
at least not on ascii-ci filesystems.  Enhance this debugger command to
support printing the dir2 hashname.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Andrey Albershteyn <aalbersh@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
db/hash.c
man/man8/xfs_db.8

index 79a250526e9ca6c17e3115aa0a36ce7ed92e5e78..716da88baf9251cdcaf1273e65c627b6c7484d2d 100644 (file)
--- a/db/hash.c
+++ b/db/hash.c
 static int hash_f(int argc, char **argv);
 static void hash_help(void);
 
-static const cmdinfo_t hash_cmd =
-       { "hash", NULL, hash_f, 1, 1, 0, N_("string"),
-         N_("calculate hash value"), hash_help };
+static const cmdinfo_t hash_cmd = {
+       .name           = "hash",
+       .cfunc          = hash_f,
+       .argmin         = 1,
+       .argmax         = -1,
+       .args           = N_("string"),
+       .oneline        = N_("calculate hash value"),
+       .help           = hash_help,
+};
 
 static void
 hash_help(void)
@@ -43,9 +49,35 @@ hash_f(
        char            **argv)
 {
        xfs_dahash_t    hashval;
+       bool            use_dir2_hash = false;
+       int             c;
+
+       while ((c = getopt(argc, argv, "d")) != EOF) {
+               switch (c) {
+               case 'd':
+                       use_dir2_hash = true;
+                       break;
+               default:
+                       exitcode = 1;
+                       hash_help();
+                       return 0;
+               }
+       }
+
+       for (c = optind; c < argc; c++) {
+               if (use_dir2_hash) {
+                       struct xfs_name xname = {
+                               .name   = (uint8_t *)argv[c],
+                               .len    = strlen(argv[c]),
+                       };
+
+                       hashval = libxfs_dir2_hashname(mp, &xname);
+               } else {
+                       hashval = libxfs_da_hashname(argv[c], strlen(argv[c]));
+               }
+               dbprintf("0x%x\n", hashval);
+       }
 
-       hashval = libxfs_da_hashname((unsigned char *)argv[1], (int)strlen(argv[1]));
-       dbprintf("0x%x\n", hashval);
        return 0;
 }
 
index fde1c5c6c696ed51495f298daade99eb756672de..60dcdc52cbaba57eb953db034e08d99c2b0120af 100644 (file)
@@ -763,10 +763,16 @@ Skip write verifiers but perform CRC recalculation; allows invalid data to be
 written to disk to test detection of invalid data.
 .RE
 .TP
-.BI hash " string
+.BI hash [-d]" strings
 Prints the hash value of
 .I string
 using the hash function of the XFS directory and attribute implementation.
+
+If the
+.B \-d
+option is specified, the directory-specific hash function is used.
+This only makes a difference on filesystems with ascii case-insensitive
+lookups enabled.
 .TP
 .BI "hashcoll [-a] [-s seed] [-n " nr "] [-p " path "] -i | " names...
 Create directory entries or extended attributes names that all have the same