summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/udf/unicode.c57
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,
129 return gotch; 129 return gotch;
130} 130}
131 131
132static int udf_name_from_CS0(uint8_t *str_o, int str_max_len, 132static int udf_name_from_CS0(struct super_block *sb,
133 uint8_t *str_o, int str_max_len,
133 const uint8_t *ocu, int ocu_len, 134 const uint8_t *ocu, int ocu_len,
134 int (*conv_f)(wchar_t, unsigned char *, int),
135 int translate) 135 int translate)
136{ 136{
137 uint32_t c; 137 uint32_t c;
@@ -148,6 +148,7 @@ static int udf_name_from_CS0(uint8_t *str_o, int str_max_len,
148 unsigned short valueCRC; 148 unsigned short valueCRC;
149 uint8_t ext[EXT_SIZE * NLS_MAX_CHARSET_SIZE + 1]; 149 uint8_t ext[EXT_SIZE * NLS_MAX_CHARSET_SIZE + 1];
150 uint8_t crc[CRC_LEN]; 150 uint8_t crc[CRC_LEN];
151 int (*conv_f)(wchar_t, unsigned char *, int);
151 152
152 if (str_max_len <= 0) 153 if (str_max_len <= 0)
153 return 0; 154 return 0;
@@ -157,6 +158,13 @@ static int udf_name_from_CS0(uint8_t *str_o, int str_max_len,
157 return 0; 158 return 0;
158 } 159 }
159 160
161 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
162 conv_f = udf_uni2char_utf8;
163 } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) {
164 conv_f = UDF_SB(sb)->s_nls_map->uni2char;
165 } else
166 BUG();
167
160 cmp_id = ocu[0]; 168 cmp_id = ocu[0];
161 if (cmp_id != 8 && cmp_id != 16) { 169 if (cmp_id != 8 && cmp_id != 16) {
162 memset(str_o, 0, str_max_len); 170 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,
247 return str_o_len; 255 return str_o_len;
248} 256}
249 257
250static int udf_name_to_CS0(uint8_t *ocu, int ocu_max_len, 258static int udf_name_to_CS0(struct super_block *sb,
251 const uint8_t *str_i, int str_len, 259 uint8_t *ocu, int ocu_max_len,
252 int (*conv_f)(const unsigned char *, int, wchar_t *)) 260 const uint8_t *str_i, int str_len)
253{ 261{
254 int i, len; 262 int i, len;
255 unsigned int max_val; 263 unsigned int max_val;
256 wchar_t uni_char; 264 wchar_t uni_char;
257 int u_len, u_ch; 265 int u_len, u_ch;
266 int (*conv_f)(const unsigned char *, int, wchar_t *);
258 267
259 if (ocu_max_len <= 0) 268 if (ocu_max_len <= 0)
260 return 0; 269 return 0;
261 270
271 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
272 conv_f = udf_char2uni_utf8;
273 } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) {
274 conv_f = UDF_SB(sb)->s_nls_map->char2uni;
275 } else
276 BUG();
277
262 memset(ocu, 0, ocu_max_len); 278 memset(ocu, 0, ocu_max_len);
263 ocu[0] = 8; 279 ocu[0] = 8;
264 max_val = 0xff; 280 max_val = 0xff;
@@ -298,7 +314,6 @@ try_again:
298int udf_dstrCS0toChar(struct super_block *sb, uint8_t *utf_o, int o_len, 314int udf_dstrCS0toChar(struct super_block *sb, uint8_t *utf_o, int o_len,
299 const uint8_t *ocu_i, int i_len) 315 const uint8_t *ocu_i, int i_len)
300{ 316{
301 int (*conv_f)(wchar_t, unsigned char *, int);
302 int s_len = 0; 317 int s_len = 0;
303 318
304 if (i_len > 0) { 319 if (i_len > 0) {
@@ -310,20 +325,12 @@ int udf_dstrCS0toChar(struct super_block *sb, uint8_t *utf_o, int o_len,
310 } 325 }
311 } 326 }
312 327
313 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { 328 return udf_name_from_CS0(sb, utf_o, o_len, ocu_i, s_len, 0);
314 conv_f = udf_uni2char_utf8;
315 } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) {
316 conv_f = UDF_SB(sb)->s_nls_map->uni2char;
317 } else
318 BUG();
319
320 return udf_name_from_CS0(utf_o, o_len, ocu_i, s_len, conv_f, 0);
321} 329}
322 330
323int udf_get_filename(struct super_block *sb, const uint8_t *sname, int slen, 331int udf_get_filename(struct super_block *sb, const uint8_t *sname, int slen,
324 uint8_t *dname, int dlen) 332 uint8_t *dname, int dlen)
325{ 333{
326 int (*conv_f)(wchar_t, unsigned char *, int);
327 int ret; 334 int ret;
328 335
329 if (!slen) 336 if (!slen)
@@ -332,14 +339,7 @@ int udf_get_filename(struct super_block *sb, const uint8_t *sname, int slen,
332 if (dlen <= 0) 339 if (dlen <= 0)
333 return 0; 340 return 0;
334 341
335 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { 342 ret = udf_name_from_CS0(sb, dname, dlen, sname, slen, 1);
336 conv_f = udf_uni2char_utf8;
337 } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) {
338 conv_f = UDF_SB(sb)->s_nls_map->uni2char;
339 } else
340 BUG();
341
342 ret = udf_name_from_CS0(dname, dlen, sname, slen, conv_f, 1);
343 /* Zero length filename isn't valid... */ 343 /* Zero length filename isn't valid... */
344 if (ret == 0) 344 if (ret == 0)
345 ret = -EINVAL; 345 ret = -EINVAL;
@@ -349,15 +349,6 @@ int udf_get_filename(struct super_block *sb, const uint8_t *sname, int slen,
349int udf_put_filename(struct super_block *sb, const uint8_t *sname, int slen, 349int udf_put_filename(struct super_block *sb, const uint8_t *sname, int slen,
350 uint8_t *dname, int dlen) 350 uint8_t *dname, int dlen)
351{ 351{
352 int (*conv_f)(const unsigned char *, int, wchar_t *); 352 return udf_name_to_CS0(sb, dname, dlen, sname, slen);
353
354 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
355 conv_f = udf_char2uni_utf8;
356 } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) {
357 conv_f = UDF_SB(sb)->s_nls_map->char2uni;
358 } else
359 BUG();
360
361 return udf_name_to_CS0(dname, dlen, sname, slen, conv_f);
362} 353}
363 354