]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - lib/e2p/encoding.c
libe2p: print the filename character encoding in list_super[2]
[thirdparty/e2fsprogs.git] / lib / e2p / encoding.c
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;