]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_db: compute hashes of parent pointers
authorDarrick J. Wong <djwong@kernel.org>
Mon, 29 Jul 2024 23:23:24 +0000 (16:23 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:12 +0000 (17:01 -0700)
Enhance the hash command to compute the hashes of parent pointers.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
db/hash.c
libxfs/libxfs_api_defs.h
man/man8/xfs_db.8

index 1500a6032fd75affd4263d289277aa7f51aceab8..50f6da0b1a20b2fe44218410a8bddecb97b58123 100644 (file)
--- a/db/hash.c
+++ b/db/hash.c
@@ -36,26 +36,42 @@ hash_help(void)
 " 'hash' prints out the calculated hash value for a string using the\n"
 "directory/attribute code hash function.\n"
 "\n"
-" Usage:  \"hash <string>\"\n"
+" Usage:  \"hash [-d|-p parent_ino] <string>\"\n"
 "\n"
 ));
 
 }
 
+enum hash_what {
+       ATTR,
+       DIRECTORY,
+       PPTR,
+};
+
 /* ARGSUSED */
 static int
 hash_f(
        int             argc,
        char            **argv)
 {
+       xfs_ino_t       p_ino = 0;
        xfs_dahash_t    hashval;
-       bool            use_dir2_hash = false;
+       enum hash_what  what = ATTR;
        int             c;
 
-       while ((c = getopt(argc, argv, "d")) != EOF) {
+       while ((c = getopt(argc, argv, "dp:")) != EOF) {
                switch (c) {
                case 'd':
-                       use_dir2_hash = true;
+                       what = DIRECTORY;
+                       break;
+               case 'p':
+                       errno = 0;
+                       p_ino = strtoull(optarg, NULL, 0);
+                       if (errno) {
+                               perror(optarg);
+                               return 1;
+                       }
+                       what = PPTR;
                        break;
                default:
                        exitcode = 1;
@@ -70,10 +86,18 @@ hash_f(
                        .len    = strlen(argv[c]),
                };
 
-               if (use_dir2_hash)
+               switch (what) {
+               case DIRECTORY:
                        hashval = libxfs_dir2_hashname(mp, &xname);
-               else
+                       break;
+               case PPTR:
+                       hashval = libxfs_parent_hashval(mp, xname.name,
+                                       xname.len, p_ino);
+                       break;
+               case ATTR:
                        hashval = libxfs_attr_hashname(xname.name, xname.len);
+                       break;
+               }
                dbprintf("0x%x\n", hashval);
        }
 
index b7edaf788051b5b6af5ade989b8a20dac721a15e..df83aabdc13d3b455675d2005c3b3a2f9a508500 100644 (file)
 #define xfs_mkdir_space_res            libxfs_mkdir_space_res
 #define xfs_parent_addname             libxfs_parent_addname
 #define xfs_parent_finish              libxfs_parent_finish
+#define xfs_parent_hashval             libxfs_parent_hashval
 #define xfs_parent_removename          libxfs_parent_removename
 #define xfs_parent_start               libxfs_parent_start
 #define xfs_parent_from_attr           libxfs_parent_from_attr
index f8db6c36f40a55e537929688c0a3fe2ee6d7688a..9f6fea5748d477eb841538b525a254f36fc54208 100644 (file)
@@ -822,7 +822,7 @@ 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 [-d]" strings
+.BI hash [-d|-p parent_ino]" strings
 Prints the hash value of
 .I string
 using the hash function of the XFS directory and attribute implementation.
@@ -832,6 +832,13 @@ If the
 option is specified, the directory-specific hash function is used.
 This only makes a difference on filesystems with ascii case-insensitive
 lookups enabled.
+
+If the
+.B \-p
+option is specified, the parent pointer-specific hash function is used.
+The parent directory inumber must be specified as an argument.
+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