diff options
author | Jan Kara <jack@suse.cz> | 2018-04-16 16:57:57 +0200 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2018-04-19 16:00:48 +0200 |
commit | d504adc29142755edda4ef0f24ec81b7088564a4 (patch) | |
tree | d1ac6d0eeb001e21e2d3325a6fe577e7851b9541 | |
parent | e966fc8d9953167fe7c29495495436846467a5d2 (diff) |
udf: Push sb argument to udf_name_[to|from]_CS0()
Push superblock argument to udf_name_[to|from]_CS0() functions so that
we can decide about character conversion functions there.
Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r-- | fs/udf/unicode.c | 57 |
1 files changed, 24 insertions, 33 deletions
diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c index ad806c3125c1..329be783f98a 100644 --- a/fs/udf/unicode.c +++ b/fs/udf/unicode.c @@ -129,9 +129,9 @@ static int udf_name_conv_char(uint8_t *str_o, int str_o_max_len, return gotch; } -static int udf_name_from_CS0(uint8_t *str_o, int str_max_len, +static int udf_name_from_CS0(struct super_block *sb, + uint8_t *str_o, int str_max_len, const uint8_t *ocu, int ocu_len, - int (*conv_f)(wchar_t, unsigned char *, int), int translate) { uint32_t c; @@ -148,6 +148,7 @@ static int udf_name_from_CS0(uint8_t *str_o, int str_max_len, unsigned short valueCRC; uint8_t ext[EXT_SIZE * NLS_MAX_CHARSET_SIZE + 1]; uint8_t crc[CRC_LEN]; + int (*conv_f)(wchar_t, unsigned char *, int); if (str_max_len <= 0) return 0; @@ -157,6 +158,13 @@ static int udf_name_from_CS0(uint8_t *str_o, int str_max_len, return 0; } + if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { + conv_f = udf_uni2char_utf8; + } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { + conv_f = UDF_SB(sb)->s_nls_map->uni2char; + } else + BUG(); + cmp_id = ocu[0]; if (cmp_id != 8 && cmp_id != 16) { memset(str_o, 0, str_max_len); @@ -247,18 +255,26 @@ static int udf_name_from_CS0(uint8_t *str_o, int str_max_len, return str_o_len; } -static int udf_name_to_CS0(uint8_t *ocu, int ocu_max_len, - const uint8_t *str_i, int str_len, - int (*conv_f)(const unsigned char *, int, wchar_t *)) +static int udf_name_to_CS0(struct super_block *sb, + uint8_t *ocu, int ocu_max_len, + const uint8_t *str_i, int str_len) { int i, len; unsigned int max_val; wchar_t uni_char; int u_len, u_ch; + int (*conv_f)(const unsigned char *, int, wchar_t *); if (ocu_max_len <= 0) return 0; + if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { + conv_f = udf_char2uni_utf8; + } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { + conv_f = UDF_SB(sb)->s_nls_map->char2uni; + } else + BUG(); + memset(ocu, 0, ocu_max_len); ocu[0] = 8; max_val = 0xff; @@ -298,7 +314,6 @@ try_again: int udf_dstrCS0toChar(struct super_block *sb, uint8_t *utf_o, int o_len, const uint8_t *ocu_i, int i_len) { - int (*conv_f)(wchar_t, unsigned char *, int); int s_len = 0; if (i_len > 0) { @@ -310,20 +325,12 @@ int udf_dstrCS0toChar(struct super_block *sb, uint8_t *utf_o, int o_len, } } - if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { - conv_f = udf_uni2char_utf8; - } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { - conv_f = UDF_SB(sb)->s_nls_map->uni2char; - } else - BUG(); - - return udf_name_from_CS0(utf_o, o_len, ocu_i, s_len, conv_f, 0); + return udf_name_from_CS0(sb, utf_o, o_len, ocu_i, s_len, 0); } int udf_get_filename(struct super_block *sb, const uint8_t *sname, int slen, uint8_t *dname, int dlen) { - int (*conv_f)(wchar_t, unsigned char *, int); int ret; if (!slen) @@ -332,14 +339,7 @@ int udf_get_filename(struct super_block *sb, const uint8_t *sname, int slen, if (dlen <= 0) return 0; - if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { - conv_f = udf_uni2char_utf8; - } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { - conv_f = UDF_SB(sb)->s_nls_map->uni2char; - } else - BUG(); - - ret = udf_name_from_CS0(dname, dlen, sname, slen, conv_f, 1); + ret = udf_name_from_CS0(sb, dname, dlen, sname, slen, 1); /* Zero length filename isn't valid... */ if (ret == 0) ret = -EINVAL; @@ -349,15 +349,6 @@ int udf_get_filename(struct super_block *sb, const uint8_t *sname, int slen, int udf_put_filename(struct super_block *sb, const uint8_t *sname, int slen, uint8_t *dname, int dlen) { - int (*conv_f)(const unsigned char *, int, wchar_t *); - - if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { - conv_f = udf_char2uni_utf8; - } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { - conv_f = UDF_SB(sb)->s_nls_map->char2uni; - } else - BUG(); - - return udf_name_to_CS0(dname, dlen, sname, slen, conv_f); + return udf_name_to_CS0(sb, dname, dlen, sname, slen); } |