From 5a7761e88f7ba944beb044c0656b0b959b6cca79 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Thu, 2 May 2019 11:48:45 -0400 Subject: [PATCH] libe2p: print the filename character encoding in list_super[2] Also clean up some gcc -Wall warnings while we're at it. Signed-off-by: Theodore Ts'o --- lib/e2p/e2p.h | 1 + lib/e2p/encoding.c | 28 +++++++++++++++++++++++----- lib/e2p/ls.c | 3 +++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/e2p/e2p.h b/lib/e2p/e2p.h index cc2dbf39b..c3a6b2587 100644 --- a/lib/e2p/e2p.h +++ b/lib/e2p/e2p.h @@ -82,5 +82,6 @@ const char *e2p_encmode2string(int num); int e2p_string2encmode(char *string); int e2p_str2encoding(const char *string); +const char *e2p_encoding2str(int encoding); int e2p_get_encoding_flags(int encoding); int e2p_str2encoding_flags(int encoding, char *param, __u16 *flags); diff --git a/lib/e2p/encoding.c b/lib/e2p/encoding.c index 69fa6e4c7..ccd9582e5 100644 --- a/lib/e2p/encoding.c +++ b/lib/e2p/encoding.c @@ -23,11 +23,16 @@ (sizeof(array) / sizeof(array[0])) static const struct { - char *name; + const char *name; __u16 encoding_magic; __u16 default_flags; } ext4_encoding_map[] = { + { + .encoding_magic = EXT4_ENC_UTF8_12_1, + .name = "utf8-12.1", + .default_flags = 0, + }, { .encoding_magic = EXT4_ENC_UTF8_12_1, .name = "utf8", @@ -37,7 +42,7 @@ static const struct { static const struct enc_flags { __u16 flag; - char *param; + const char *param; } encoding_flags[] = { { EXT4_ENC_STRICT_MODE_FL, "strict" }, }; @@ -46,7 +51,7 @@ static const struct enc_flags { * or a negative value indicating error. */ int e2p_str2encoding(const char *string) { - int i; + unsigned int i; for (i = 0 ; i < ARRAY_SIZE(ext4_encoding_map); i++) if (!strcmp(string, ext4_encoding_map[i].name)) @@ -55,9 +60,22 @@ int e2p_str2encoding(const char *string) return -EINVAL; } +/* Return the name of an encoding or NULL */ +const char *e2p_encoding2str(int encoding) +{ + unsigned int i; + static char buf[32]; + + for (i = 0 ; i < ARRAY_SIZE(ext4_encoding_map); i++) + if (ext4_encoding_map[i].encoding_magic == encoding) + return ext4_encoding_map[i].name; + sprintf(buf, "UNKNOWN_ENCODING_%d", encoding); + return buf; +} + int e2p_get_encoding_flags(int encoding) { - int i; + unsigned int i; for (i = 0 ; i < ARRAY_SIZE(ext4_encoding_map); i++) if (ext4_encoding_map[i].encoding_magic == encoding) @@ -70,7 +88,7 @@ int e2p_str2encoding_flags(int encoding, char *param, __u16 *flags) { char *f = strtok(param, "-"); const struct enc_flags *fl; - int i, neg = 0; + unsigned int i, neg = 0; while (f) { neg = 0; diff --git a/lib/e2p/ls.c b/lib/e2p/ls.c index a7586e094..11e7415be 100644 --- a/lib/e2p/ls.c +++ b/lib/e2p/ls.c @@ -470,6 +470,9 @@ void list_super2(struct ext2_super_block * sb, FILE *f) if (ext2fs_has_feature_csum_seed(sb)) fprintf(f, "Checksum seed: 0x%08x\n", sb->s_checksum_seed); + if (ext2fs_has_feature_fname_encoding(sb)) + fprintf(f, "Character encoding: %s\n", + e2p_encoding2str(sb->s_encoding)); } void list_super (struct ext2_super_block * s) -- 2.39.2