From: Theodore Ts'o Date: Thu, 2 May 2019 15:48:45 +0000 (-0400) Subject: libe2p: print the filename character encoding in list_super[2] X-Git-Tag: v1.45.1-rc1~10 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=5a7761e88f7ba944beb044c0656b0b959b6cca79;p=tools%2Fe2fsprogs.git 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 --- diff --git a/lib/e2p/e2p.h b/lib/e2p/e2p.h index cc2dbf3..c3a6b25 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 69fa6e4..ccd9582 100644 --- a/lib/e2p/encoding.c +++ b/lib/e2p/encoding.c @@ -23,13 +23,18 @@ (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", .default_flags = 0, }, @@ -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 a7586e0..11e7415 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)