Skip to content

Commit 29d83fe

Browse files
srivathsa729tytso
authored andcommitted
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>
1 parent 569074c commit 29d83fe

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

debugfs/htree.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,18 @@ void do_dx_hash(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
336336
errcode_t err;
337337
int c;
338338
int hash_version = 0;
339-
__u32 hash_seed[4];
339+
__u32 hash_seed[4] = { 0, };
340340
int hash_flags = 0;
341341
const struct ext2fs_nls_table *encoding = NULL;
342342

343-
hash_seed[0] = hash_seed[1] = hash_seed[2] = hash_seed[3] = 0;
343+
if (current_fs) {
344+
hash_seed[0] = current_fs->super->s_hash_seed[0];
345+
hash_seed[1] = current_fs->super->s_hash_seed[1];
346+
hash_seed[2] = current_fs->super->s_hash_seed[2];
347+
hash_seed[3] = current_fs->super->s_hash_seed[3];
348+
349+
hash_version = current_fs->super->s_def_hash_version;
350+
}
344351

345352
reset_getopt();
346353
while ((c = getopt(argc, argv, "h:s:ce:")) != EOF) {

0 commit comments

Comments
 (0)