aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSrivathsa Dara <srivathsa.d.dara@oracle.com>2023-08-24 06:56:34 +0000
committerTheodore Ts'o <tytso@mit.edu>2023-12-02 21:17:55 -0500
commit29d83fef9e6eab139516afe433c03d975e85c25b (patch)
tree00eb8bb36c6f6978e6e01aeb52a407163a7dfe59
parent569074c65d7b3a2022e53f0d6abd405dbe5320a3 (diff)
downloade2fsprogs-29d83fef9e6eab139516afe433c03d975e85c25b.tar.gz
debugfs: Use the hash_version from superblock if a file system is opened
The debugfs program's dx_hash command computes the hash for the given filename, taking the hash_seed and hash_version (i.e hash algorithm) as arguments. So the user has to refer to the superblock to get these values used by the filesystem. So if debugfs has an opened file system, use those values from the current file system. [ Fixed patch to avoid crashing when a file system is not opened. --TYT ] Signed-off-by: Srivathsa Dara <srivathsa.d.dara@oracle.com> Link: https://lore.kernel.org/r/20230824065634.2662858-1-srivathsa.d.dara@oracle.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--debugfs/htree.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/debugfs/htree.c b/debugfs/htree.c
index a9f9211ba..a3e95ddb0 100644
--- a/debugfs/htree.c
+++ b/debugfs/htree.c
@@ -336,11 +336,18 @@ void do_dx_hash(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
errcode_t err;
int c;
int hash_version = 0;
- __u32 hash_seed[4];
+ __u32 hash_seed[4] = { 0, };
int hash_flags = 0;
const struct ext2fs_nls_table *encoding = NULL;
- hash_seed[0] = hash_seed[1] = hash_seed[2] = hash_seed[3] = 0;
+ if (current_fs) {
+ hash_seed[0] = current_fs->super->s_hash_seed[0];
+ hash_seed[1] = current_fs->super->s_hash_seed[1];
+ hash_seed[2] = current_fs->super->s_hash_seed[2];
+ hash_seed[3] = current_fs->super->s_hash_seed[3];
+
+ hash_version = current_fs->super->s_def_hash_version;
+ }
reset_getopt();
while ((c = getopt(argc, argv, "h:s:ce:")) != EOF) {