aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2023-06-05 08:37:15 -0700
committerCarlos Maiolino <cem@kernel.org>2023-06-22 14:04:28 +0200
commit47560612f1213c2159bb4bbe4244df4ffef4d1e0 (patch)
tree83ea5be6e32798c306a25ce08a9fe5ddd864f1e8
parentc51c8c857999615a23c27a038099070ab2fab7ea (diff)
downloadxfsprogs-dev-47560612f1213c2159bb4bbe4244df4ffef4d1e0.tar.gz
xfs_db: make the hash command print the dirent hash
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>
-rw-r--r--db/hash.c42
-rw-r--r--man/man8/xfs_db.88
2 files changed, 44 insertions, 6 deletions
diff --git a/db/hash.c b/db/hash.c
index 79a250526e..716da88baf 100644
--- a/db/hash.c
+++ b/db/hash.c
@@ -18,9 +18,15 @@
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;
}
diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8
index fde1c5c6c6..60dcdc52cb 100644
--- a/man/man8/xfs_db.8
+++ b/man/man8/xfs_db.8
@@ -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