]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
debugfs: support encoding when printing the file hash
authorGabriel Krisman Bertazi <krisman@collabora.co.uk>
Sat, 1 Dec 2018 00:39:07 +0000 (19:39 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 3 Dec 2018 04:59:12 +0000 (23:59 -0500)
Implement two parameters -e and -c, to specify encoding and casefold
when printing the hash of a given file.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.co.uk>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
debugfs/Makefile.in
debugfs/htree.c
lib/ext2fs/Makefile.in

index bb4d1947b33bc06abcb2e58a1dea4c69342f4ed6..bc59f5f97513ece49769794f6937ac4c545ea716 100644 (file)
@@ -287,6 +287,7 @@ htree.o: $(srcdir)/htree.c $(top_builddir)/lib/config.h \
  $(top_srcdir)/lib/ext2fs/ext2_io.h $(top_builddir)/lib/ext2fs/ext2_err.h \
  $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/hashmap.h \
  $(top_srcdir)/lib/ext2fs/bitops.h $(srcdir)/../misc/create_inode.h \
+ $(top_srcdir)/lib/ext2fs/nls.h \
  $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/quotaio.h \
  $(top_srcdir)/lib/support/dqblk_v2.h \
  $(top_srcdir)/lib/support/quotaio_tree.h
index 0c6a3852393eb1d0d384b414ae42c98267313e8b..1cdb3c6a5bb7c1620fd8fb6bab26e5f4919c983a 100644 (file)
@@ -27,6 +27,8 @@ extern char *optarg;
 #include "uuid/uuid.h"
 #include "e2p/e2p.h"
 
+#include "ext2fs/nls.h"
+
 static FILE *pager;
 
 static void htree_dump_leaf_node(ext2_filsys fs, ext2_ino_t ino,
@@ -44,6 +46,7 @@ static void htree_dump_leaf_node(ext2_filsys fs, ext2_ino_t ino,
        ext2_dirhash_t  hash, minor_hash;
        unsigned int    rec_len;
        int             hash_alg;
+       int             hash_flags = inode->i_flags & EXT4_CASEFOLD_FL;
        int             csum_size = 0;
 
        if (ext2fs_has_feature_metadata_csum(fs->super))
@@ -89,9 +92,10 @@ static void htree_dump_leaf_node(ext2_filsys fs, ext2_ino_t ino,
                }
                strncpy(name, dirent->name, thislen);
                name[thislen] = '\0';
-               errcode = ext2fs_dirhash(hash_alg, name,
-                                        thislen, fs->super->s_hash_seed,
-                                        &hash, &minor_hash);
+               errcode = ext2fs_dirhash2(hash_alg, name, thislen,
+                                         fs->encoding, hash_flags,
+                                         fs->super->s_hash_seed,
+                                         &hash, &minor_hash);
                if (errcode)
                        com_err("htree_dump_leaf_node", errcode,
                                "while calculating hash");
@@ -306,11 +310,12 @@ errout:
 void do_dx_hash(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
                void *infop EXT2FS_ATTR((unused)))
 {
-       ext2_dirhash_t hash, minor_hash;
+       ext2_dirhash_t hash, minor_hash, hash_flags;
        errcode_t       err;
        int             c;
        int             hash_version = 0;
        __u32           hash_seed[4];
+       const struct nls_table *encoding;
 
        hash_seed[0] = hash_seed[1] = hash_seed[2] = hash_seed[3] = 0;
 
@@ -329,6 +334,15 @@ void do_dx_hash(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
                                return;
                        }
                        break;
+               case 'c':
+                       hash_flags = EXT4_CASEFOLD_FL;
+                       break;
+               case 'e':
+                       encoding = nls_load_table(e2p_str2encoding(optarg));
+                       if (!encoding)
+                               fprintf(stderr, "Invalid encoding: %s\n",
+                                       optarg);
+                               return;
                default:
                        goto print_usage;
                }
@@ -336,11 +350,13 @@ void do_dx_hash(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
        if (optind != argc-1) {
        print_usage:
                com_err(argv[0], 0, "usage: dx_hash [-h hash_alg] "
-                       "[-s hash_seed] filename");
+                       "[-s hash_seed] [-c] [-e encoding] filename");
                return;
        }
-       err = ext2fs_dirhash(hash_version, argv[optind], strlen(argv[optind]),
-                            hash_seed, &hash, &minor_hash);
+       err = ext2fs_dirhash2(hash_version, argv[optind],
+                             strlen(argv[optind]), encoding, hash_flags,
+                             hash_seed, &hash, &minor_hash);
+
        if (err) {
                com_err(argv[0], err, "while calculating hash");
                return;
index b756bbdf35a597cffb7d46d2444954f0adbc51d2..78c54d1a09de829b1617669e806c8013184ee8ee 100644 (file)
@@ -1299,7 +1299,7 @@ htree.o: $(top_srcdir)/debugfs/htree.c $(top_builddir)/lib/config.h \
  $(srcdir)/hashmap.h $(srcdir)/bitops.h \
  $(top_srcdir)/debugfs/../misc/create_inode.h $(top_srcdir)/lib/e2p/e2p.h \
  $(top_srcdir)/lib/support/quotaio.h $(top_srcdir)/lib/support/dqblk_v2.h \
- $(top_srcdir)/lib/support/quotaio_tree.h
+ $(top_srcdir)/lib/support/quotaio_tree.h $(srcdir)/nls.h
 unused.o: $(top_srcdir)/debugfs/unused.c $(top_builddir)/lib/config.h \
  $(top_builddir)/lib/dirpaths.h $(top_srcdir)/debugfs/debugfs.h \
  $(top_srcdir)/lib/ss/ss.h $(top_builddir)/lib/ss/ss_err.h \