]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libe2p: print the filename character encoding in list_super[2]
authorTheodore Ts'o <tytso@mit.edu>
Thu, 2 May 2019 15:48:45 +0000 (11:48 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 2 May 2019 16:16:16 +0000 (12:16 -0400)
Also clean up some gcc -Wall warnings while we're at it.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/e2p/e2p.h
lib/e2p/encoding.c
lib/e2p/ls.c

index cc2dbf39bfeb7dba09956e085a4949927b929a80..c3a6b2587bf6d566cd6e98cb24e05ab35d5788f6 100644 (file)
@@ -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);
index 69fa6e4c7d2641e3e86894cf6ac3440e83ccaf78..ccd9582e53489a37865f0575b29585ced7edd74d 100644 (file)
         (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;
index a7586e094da1a0438515560b6d2b308f371324eb..11e7415bedc44194f2dfb4bef135d07d7171fc5f 100644 (file)
@@ -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)