[PATCH 3/3] xfs_db: make the hash command print the dirent hash

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Darrick J. Wong <djwong@xxxxxxxxxx>

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@xxxxxxxxxx>
---
 db/hash.c         |   42 +++++++++++++++++++++++++++++++++++++-----
 man/man8/xfs_db.8 |    8 +++++++-
 2 files changed, 44 insertions(+), 6 deletions(-)


diff --git a/db/hash.c b/db/hash.c
index 79a250526e9..716da88baf9 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 fde1c5c6c69..60dcdc52cba 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




[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux