diff options
Diffstat (limited to 'fs/udf/unicode.c')
-rw-r--r-- | fs/udf/unicode.c | 258 |
1 files changed, 110 insertions, 148 deletions
diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c index 706c92e1dcc9..9e6099c26c27 100644 --- a/fs/udf/unicode.c +++ b/fs/udf/unicode.c | |||
@@ -31,12 +31,14 @@ static int udf_translate_to_linux(uint8_t *, uint8_t *, int, uint8_t *, int); | |||
31 | 31 | ||
32 | static int udf_char_to_ustr(struct ustr *dest, const uint8_t *src, int strlen) | 32 | static int udf_char_to_ustr(struct ustr *dest, const uint8_t *src, int strlen) |
33 | { | 33 | { |
34 | if ( (!dest) || (!src) || (!strlen) || (strlen > UDF_NAME_LEN-2) ) | 34 | if ((!dest) || (!src) || (!strlen) || (strlen > UDF_NAME_LEN - 2)) |
35 | return 0; | 35 | return 0; |
36 | |||
36 | memset(dest, 0, sizeof(struct ustr)); | 37 | memset(dest, 0, sizeof(struct ustr)); |
37 | memcpy(dest->u_name, src, strlen); | 38 | memcpy(dest->u_name, src, strlen); |
38 | dest->u_cmpID = 0x08; | 39 | dest->u_cmpID = 0x08; |
39 | dest->u_len = strlen; | 40 | dest->u_len = strlen; |
41 | |||
40 | return strlen; | 42 | return strlen; |
41 | } | 43 | } |
42 | 44 | ||
@@ -47,14 +49,15 @@ int udf_build_ustr(struct ustr *dest, dstring *ptr, int size) | |||
47 | { | 49 | { |
48 | int usesize; | 50 | int usesize; |
49 | 51 | ||
50 | if ( (!dest) || (!ptr) || (!size) ) | 52 | if ((!dest) || (!ptr) || (!size)) |
51 | return -1; | 53 | return -1; |
52 | 54 | ||
53 | memset(dest, 0, sizeof(struct ustr)); | 55 | memset(dest, 0, sizeof(struct ustr)); |
54 | usesize= (size > UDF_NAME_LEN) ? UDF_NAME_LEN : size; | 56 | usesize = (size > UDF_NAME_LEN) ? UDF_NAME_LEN : size; |
55 | dest->u_cmpID=ptr[0]; | 57 | dest->u_cmpID = ptr[0]; |
56 | dest->u_len=ptr[size-1]; | 58 | dest->u_len = ptr[size - 1]; |
57 | memcpy(dest->u_name, ptr+1, usesize-1); | 59 | memcpy(dest->u_name, ptr + 1, usesize - 1); |
60 | |||
58 | return 0; | 61 | return 0; |
59 | } | 62 | } |
60 | 63 | ||
@@ -63,13 +66,14 @@ int udf_build_ustr(struct ustr *dest, dstring *ptr, int size) | |||
63 | */ | 66 | */ |
64 | static int udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize) | 67 | static int udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize) |
65 | { | 68 | { |
66 | if ( (!dest) || (!ptr) || (!exactsize) ) | 69 | if ((!dest) || (!ptr) || (!exactsize)) |
67 | return -1; | 70 | return -1; |
68 | 71 | ||
69 | memset(dest, 0, sizeof(struct ustr)); | 72 | memset(dest, 0, sizeof(struct ustr)); |
70 | dest->u_cmpID=ptr[0]; | 73 | dest->u_cmpID = ptr[0]; |
71 | dest->u_len=exactsize-1; | 74 | dest->u_len = exactsize - 1; |
72 | memcpy(dest->u_name, ptr+1, exactsize-1); | 75 | memcpy(dest->u_name, ptr + 1, exactsize - 1); |
76 | |||
73 | return 0; | 77 | return 0; |
74 | } | 78 | } |
75 | 79 | ||
@@ -108,22 +112,20 @@ int udf_CS0toUTF8(struct ustr *utf_o, struct ustr *ocu_i) | |||
108 | cmp_id = ocu_i->u_cmpID; | 112 | cmp_id = ocu_i->u_cmpID; |
109 | utf_o->u_len = 0; | 113 | utf_o->u_len = 0; |
110 | 114 | ||
111 | if (ocu_len == 0) | 115 | if (ocu_len == 0) { |
112 | { | ||
113 | memset(utf_o, 0, sizeof(struct ustr)); | 116 | memset(utf_o, 0, sizeof(struct ustr)); |
114 | utf_o->u_cmpID = 0; | 117 | utf_o->u_cmpID = 0; |
115 | utf_o->u_len = 0; | 118 | utf_o->u_len = 0; |
116 | return 0; | 119 | return 0; |
117 | } | 120 | } |
118 | 121 | ||
119 | if ((cmp_id != 8) && (cmp_id != 16)) | 122 | if ((cmp_id != 8) && (cmp_id != 16)) { |
120 | { | 123 | printk(KERN_ERR "udf: unknown compression code (%d) stri=%s\n", |
121 | printk(KERN_ERR "udf: unknown compression code (%d) stri=%s\n", cmp_id, ocu_i->u_name); | 124 | cmp_id, ocu_i->u_name); |
122 | return 0; | 125 | return 0; |
123 | } | 126 | } |
124 | 127 | ||
125 | for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN-3)) ;) | 128 | for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN - 3));) { |
126 | { | ||
127 | 129 | ||
128 | /* Expand OSTA compressed Unicode to Unicode */ | 130 | /* Expand OSTA compressed Unicode to Unicode */ |
129 | c = ocu[i++]; | 131 | c = ocu[i++]; |
@@ -131,21 +133,18 @@ int udf_CS0toUTF8(struct ustr *utf_o, struct ustr *ocu_i) | |||
131 | c = (c << 8) | ocu[i++]; | 133 | c = (c << 8) | ocu[i++]; |
132 | 134 | ||
133 | /* Compress Unicode to UTF-8 */ | 135 | /* Compress Unicode to UTF-8 */ |
134 | if (c < 0x80U) | 136 | if (c < 0x80U) { |
135 | utf_o->u_name[utf_o->u_len++] = (uint8_t)c; | 137 | utf_o->u_name[utf_o->u_len++] = (uint8_t)c; |
136 | else if (c < 0x800U) | 138 | } else if (c < 0x800U) { |
137 | { | ||
138 | utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xc0 | (c >> 6)); | 139 | utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xc0 | (c >> 6)); |
139 | utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f)); | 140 | utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f)); |
140 | } | 141 | } else { |
141 | else | ||
142 | { | ||
143 | utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xe0 | (c >> 12)); | 142 | utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xe0 | (c >> 12)); |
144 | utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | ((c >> 6) & 0x3f)); | 143 | utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | ((c >> 6) & 0x3f)); |
145 | utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f)); | 144 | utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f)); |
146 | } | 145 | } |
147 | } | 146 | } |
148 | utf_o->u_cmpID=8; | 147 | utf_o->u_cmpID = 8; |
149 | 148 | ||
150 | return utf_o->u_len; | 149 | return utf_o->u_len; |
151 | } | 150 | } |
@@ -186,61 +185,46 @@ try_again: | |||
186 | u_len = 0U; | 185 | u_len = 0U; |
187 | utf_char = 0U; | 186 | utf_char = 0U; |
188 | utf_cnt = 0U; | 187 | utf_cnt = 0U; |
189 | for (i = 0U; i < utf->u_len; i++) | 188 | for (i = 0U; i < utf->u_len; i++) { |
190 | { | ||
191 | c = (uint8_t)utf->u_name[i]; | 189 | c = (uint8_t)utf->u_name[i]; |
192 | 190 | ||
193 | /* Complete a multi-byte UTF-8 character */ | 191 | /* Complete a multi-byte UTF-8 character */ |
194 | if (utf_cnt) | 192 | if (utf_cnt) { |
195 | { | ||
196 | utf_char = (utf_char << 6) | (c & 0x3fU); | 193 | utf_char = (utf_char << 6) | (c & 0x3fU); |
197 | if (--utf_cnt) | 194 | if (--utf_cnt) |
198 | continue; | 195 | continue; |
199 | } | 196 | } else { |
200 | else | ||
201 | { | ||
202 | /* Check for a multi-byte UTF-8 character */ | 197 | /* Check for a multi-byte UTF-8 character */ |
203 | if (c & 0x80U) | 198 | if (c & 0x80U) { |
204 | { | ||
205 | /* Start a multi-byte UTF-8 character */ | 199 | /* Start a multi-byte UTF-8 character */ |
206 | if ((c & 0xe0U) == 0xc0U) | 200 | if ((c & 0xe0U) == 0xc0U) { |
207 | { | ||
208 | utf_char = c & 0x1fU; | 201 | utf_char = c & 0x1fU; |
209 | utf_cnt = 1; | 202 | utf_cnt = 1; |
210 | } | 203 | } else if ((c & 0xf0U) == 0xe0U) { |
211 | else if ((c & 0xf0U) == 0xe0U) | ||
212 | { | ||
213 | utf_char = c & 0x0fU; | 204 | utf_char = c & 0x0fU; |
214 | utf_cnt = 2; | 205 | utf_cnt = 2; |
215 | } | 206 | } else if ((c & 0xf8U) == 0xf0U) { |
216 | else if ((c & 0xf8U) == 0xf0U) | ||
217 | { | ||
218 | utf_char = c & 0x07U; | 207 | utf_char = c & 0x07U; |
219 | utf_cnt = 3; | 208 | utf_cnt = 3; |
220 | } | 209 | } else if ((c & 0xfcU) == 0xf8U) { |
221 | else if ((c & 0xfcU) == 0xf8U) | ||
222 | { | ||
223 | utf_char = c & 0x03U; | 210 | utf_char = c & 0x03U; |
224 | utf_cnt = 4; | 211 | utf_cnt = 4; |
225 | } | 212 | } else if ((c & 0xfeU) == 0xfcU) { |
226 | else if ((c & 0xfeU) == 0xfcU) | ||
227 | { | ||
228 | utf_char = c & 0x01U; | 213 | utf_char = c & 0x01U; |
229 | utf_cnt = 5; | 214 | utf_cnt = 5; |
230 | } | 215 | } else { |
231 | else | ||
232 | goto error_out; | 216 | goto error_out; |
217 | } | ||
233 | continue; | 218 | continue; |
234 | } else | 219 | } else { |
235 | /* Single byte UTF-8 character (most common) */ | 220 | /* Single byte UTF-8 character (most common) */ |
236 | utf_char = c; | 221 | utf_char = c; |
222 | } | ||
237 | } | 223 | } |
238 | 224 | ||
239 | /* Choose no compression if necessary */ | 225 | /* Choose no compression if necessary */ |
240 | if (utf_char > max_val) | 226 | if (utf_char > max_val) { |
241 | { | 227 | if (max_val == 0xffU) { |
242 | if ( 0xffU == max_val ) | ||
243 | { | ||
244 | max_val = 0xffffU; | 228 | max_val = 0xffffU; |
245 | ocu[0] = (uint8_t)0x10U; | 229 | ocu[0] = (uint8_t)0x10U; |
246 | goto try_again; | 230 | goto try_again; |
@@ -248,26 +232,25 @@ try_again: | |||
248 | goto error_out; | 232 | goto error_out; |
249 | } | 233 | } |
250 | 234 | ||
251 | if (max_val == 0xffffU) | 235 | if (max_val == 0xffffU) { |
252 | { | ||
253 | ocu[++u_len] = (uint8_t)(utf_char >> 8); | 236 | ocu[++u_len] = (uint8_t)(utf_char >> 8); |
254 | } | 237 | } |
255 | ocu[++u_len] = (uint8_t)(utf_char & 0xffU); | 238 | ocu[++u_len] = (uint8_t)(utf_char & 0xffU); |
256 | } | 239 | } |
257 | 240 | ||
258 | 241 | if (utf_cnt) { | |
259 | if (utf_cnt) | ||
260 | { | ||
261 | error_out: | 242 | error_out: |
262 | ocu[++u_len] = '?'; | 243 | ocu[++u_len] = '?'; |
263 | printk(KERN_DEBUG "udf: bad UTF-8 character\n"); | 244 | printk(KERN_DEBUG "udf: bad UTF-8 character\n"); |
264 | } | 245 | } |
265 | 246 | ||
266 | ocu[length - 1] = (uint8_t)u_len + 1; | 247 | ocu[length - 1] = (uint8_t)u_len + 1; |
248 | |||
267 | return u_len + 1; | 249 | return u_len + 1; |
268 | } | 250 | } |
269 | 251 | ||
270 | static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o, struct ustr *ocu_i) | 252 | static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o, |
253 | struct ustr *ocu_i) | ||
271 | { | 254 | { |
272 | uint8_t *ocu; | 255 | uint8_t *ocu; |
273 | uint32_t c; | 256 | uint32_t c; |
@@ -280,36 +263,35 @@ static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o, struct ustr * | |||
280 | cmp_id = ocu_i->u_cmpID; | 263 | cmp_id = ocu_i->u_cmpID; |
281 | utf_o->u_len = 0; | 264 | utf_o->u_len = 0; |
282 | 265 | ||
283 | if (ocu_len == 0) | 266 | if (ocu_len == 0) { |
284 | { | ||
285 | memset(utf_o, 0, sizeof(struct ustr)); | 267 | memset(utf_o, 0, sizeof(struct ustr)); |
286 | utf_o->u_cmpID = 0; | 268 | utf_o->u_cmpID = 0; |
287 | utf_o->u_len = 0; | 269 | utf_o->u_len = 0; |
288 | return 0; | 270 | return 0; |
289 | } | 271 | } |
290 | 272 | ||
291 | if ((cmp_id != 8) && (cmp_id != 16)) | 273 | if ((cmp_id != 8) && (cmp_id != 16)) { |
292 | { | 274 | printk(KERN_ERR "udf: unknown compression code (%d) stri=%s\n", |
293 | printk(KERN_ERR "udf: unknown compression code (%d) stri=%s\n", cmp_id, ocu_i->u_name); | 275 | cmp_id, ocu_i->u_name); |
294 | return 0; | 276 | return 0; |
295 | } | 277 | } |
296 | 278 | ||
297 | for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN-3)) ;) | 279 | for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN - 3));) { |
298 | { | ||
299 | /* Expand OSTA compressed Unicode to Unicode */ | 280 | /* Expand OSTA compressed Unicode to Unicode */ |
300 | c = ocu[i++]; | 281 | c = ocu[i++]; |
301 | if (cmp_id == 16) | 282 | if (cmp_id == 16) |
302 | c = (c << 8) | ocu[i++]; | 283 | c = (c << 8) | ocu[i++]; |
303 | 284 | ||
304 | utf_o->u_len += nls->uni2char(c, &utf_o->u_name[utf_o->u_len], | 285 | utf_o->u_len += nls->uni2char(c, &utf_o->u_name[utf_o->u_len], |
305 | UDF_NAME_LEN - utf_o->u_len); | 286 | UDF_NAME_LEN - utf_o->u_len); |
306 | } | 287 | } |
307 | utf_o->u_cmpID=8; | 288 | utf_o->u_cmpID = 8; |
308 | 289 | ||
309 | return utf_o->u_len; | 290 | return utf_o->u_len; |
310 | } | 291 | } |
311 | 292 | ||
312 | static int udf_NLStoCS0(struct nls_table *nls, dstring *ocu, struct ustr *uni, int length) | 293 | static int udf_NLStoCS0(struct nls_table *nls, dstring *ocu, struct ustr *uni, |
294 | int length) | ||
313 | { | 295 | { |
314 | unsigned len, i, max_val; | 296 | unsigned len, i, max_val; |
315 | uint16_t uni_char; | 297 | uint16_t uni_char; |
@@ -321,19 +303,17 @@ static int udf_NLStoCS0(struct nls_table *nls, dstring *ocu, struct ustr *uni, i | |||
321 | 303 | ||
322 | try_again: | 304 | try_again: |
323 | u_len = 0U; | 305 | u_len = 0U; |
324 | for (i = 0U; i < uni->u_len; i++) | 306 | for (i = 0U; i < uni->u_len; i++) { |
325 | { | 307 | len = nls->char2uni(&uni->u_name[i], uni->u_len - i, &uni_char); |
326 | len = nls->char2uni(&uni->u_name[i], uni->u_len-i, &uni_char); | ||
327 | if (len <= 0) | 308 | if (len <= 0) |
328 | continue; | 309 | continue; |
329 | 310 | ||
330 | if (uni_char > max_val) | 311 | if (uni_char > max_val) { |
331 | { | ||
332 | max_val = 0xffffU; | 312 | max_val = 0xffffU; |
333 | ocu[0] = (uint8_t)0x10U; | 313 | ocu[0] = (uint8_t)0x10U; |
334 | goto try_again; | 314 | goto try_again; |
335 | } | 315 | } |
336 | 316 | ||
337 | if (max_val == 0xffffU) | 317 | if (max_val == 0xffffU) |
338 | ocu[++u_len] = (uint8_t)(uni_char >> 8); | 318 | ocu[++u_len] = (uint8_t)(uni_char >> 8); |
339 | ocu[++u_len] = (uint8_t)(uni_char & 0xffU); | 319 | ocu[++u_len] = (uint8_t)(uni_char & 0xffU); |
@@ -344,112 +324,98 @@ try_again: | |||
344 | return u_len + 1; | 324 | return u_len + 1; |
345 | } | 325 | } |
346 | 326 | ||
347 | int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname, int flen) | 327 | int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname, |
328 | int flen) | ||
348 | { | 329 | { |
349 | struct ustr filename, unifilename; | 330 | struct ustr filename, unifilename; |
350 | int len; | 331 | int len; |
351 | 332 | ||
352 | if (udf_build_ustr_exact(&unifilename, sname, flen)) | 333 | if (udf_build_ustr_exact(&unifilename, sname, flen)) { |
353 | { | ||
354 | return 0; | 334 | return 0; |
355 | } | 335 | } |
356 | 336 | ||
357 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) | 337 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { |
358 | { | 338 | if (!udf_CS0toUTF8(&filename, &unifilename)) { |
359 | if (!udf_CS0toUTF8(&filename, &unifilename) ) | ||
360 | { | ||
361 | udf_debug("Failed in udf_get_filename: sname = %s\n", sname); | 339 | udf_debug("Failed in udf_get_filename: sname = %s\n", sname); |
362 | return 0; | 340 | return 0; |
363 | } | 341 | } |
364 | } | 342 | } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { |
365 | else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) | 343 | if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, &filename, &unifilename)) { |
366 | { | ||
367 | if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, &filename, &unifilename) ) | ||
368 | { | ||
369 | udf_debug("Failed in udf_get_filename: sname = %s\n", sname); | 344 | udf_debug("Failed in udf_get_filename: sname = %s\n", sname); |
370 | return 0; | 345 | return 0; |
371 | } | 346 | } |
372 | } | 347 | } else { |
373 | else | ||
374 | return 0; | 348 | return 0; |
349 | } | ||
375 | 350 | ||
376 | if ((len = udf_translate_to_linux(dname, filename.u_name, filename.u_len, | 351 | len = udf_translate_to_linux(dname, filename.u_name, filename.u_len, |
377 | unifilename.u_name, unifilename.u_len))) | 352 | unifilename.u_name, unifilename.u_len); |
378 | { | 353 | if (len) { |
379 | return len; | 354 | return len; |
380 | } | 355 | } |
356 | |||
381 | return 0; | 357 | return 0; |
382 | } | 358 | } |
383 | 359 | ||
384 | int udf_put_filename(struct super_block *sb, const uint8_t *sname, uint8_t *dname, int flen) | 360 | int udf_put_filename(struct super_block *sb, const uint8_t *sname, |
361 | uint8_t *dname, int flen) | ||
385 | { | 362 | { |
386 | struct ustr unifilename; | 363 | struct ustr unifilename; |
387 | int namelen; | 364 | int namelen; |
388 | 365 | ||
389 | if ( !(udf_char_to_ustr(&unifilename, sname, flen)) ) | 366 | if (!(udf_char_to_ustr(&unifilename, sname, flen))) { |
390 | { | ||
391 | return 0; | 367 | return 0; |
392 | } | 368 | } |
393 | 369 | ||
394 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) | 370 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { |
395 | { | 371 | namelen = udf_UTF8toCS0(dname, &unifilename, UDF_NAME_LEN); |
396 | if ( !(namelen = udf_UTF8toCS0(dname, &unifilename, UDF_NAME_LEN)) ) | 372 | if (!namelen) { |
397 | { | ||
398 | return 0; | 373 | return 0; |
399 | } | 374 | } |
400 | } | 375 | } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { |
401 | else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) | 376 | namelen = udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname, &unifilename, UDF_NAME_LEN); |
402 | { | 377 | if (!namelen) { |
403 | if ( !(namelen = udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname, &unifilename, UDF_NAME_LEN)) ) | ||
404 | { | ||
405 | return 0; | 378 | return 0; |
406 | } | 379 | } |
407 | } | 380 | } else { |
408 | else | ||
409 | return 0; | 381 | return 0; |
382 | } | ||
410 | 383 | ||
411 | return namelen; | 384 | return namelen; |
412 | } | 385 | } |
413 | 386 | ||
414 | #define ILLEGAL_CHAR_MARK '_' | 387 | #define ILLEGAL_CHAR_MARK '_' |
415 | #define EXT_MARK '.' | 388 | #define EXT_MARK '.' |
416 | #define CRC_MARK '#' | 389 | #define CRC_MARK '#' |
417 | #define EXT_SIZE 5 | 390 | #define EXT_SIZE 5 |
418 | 391 | ||
419 | static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen, uint8_t *fidName, int fidNameLen) | 392 | static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen, |
393 | uint8_t *fidName, int fidNameLen) | ||
420 | { | 394 | { |
421 | int index, newIndex = 0, needsCRC = 0; | 395 | int index, newIndex = 0, needsCRC = 0; |
422 | int extIndex = 0, newExtIndex = 0, hasExt = 0; | 396 | int extIndex = 0, newExtIndex = 0, hasExt = 0; |
423 | unsigned short valueCRC; | 397 | unsigned short valueCRC; |
424 | uint8_t curr; | 398 | uint8_t curr; |
425 | const uint8_t hexChar[] = "0123456789ABCDEF"; | 399 | const uint8_t hexChar[] = "0123456789ABCDEF"; |
426 | 400 | ||
427 | if (udfName[0] == '.' && (udfLen == 1 || | 401 | if (udfName[0] == '.' && |
428 | (udfLen == 2 && udfName[1] == '.'))) | 402 | (udfLen == 1 || (udfLen == 2 && udfName[1] == '.'))) { |
429 | { | ||
430 | needsCRC = 1; | 403 | needsCRC = 1; |
431 | newIndex = udfLen; | 404 | newIndex = udfLen; |
432 | memcpy(newName, udfName, udfLen); | 405 | memcpy(newName, udfName, udfLen); |
433 | } | 406 | } else { |
434 | else | 407 | for (index = 0; index < udfLen; index++) { |
435 | { | ||
436 | for (index = 0; index < udfLen; index++) | ||
437 | { | ||
438 | curr = udfName[index]; | 408 | curr = udfName[index]; |
439 | if (curr == '/' || curr == 0) | 409 | if (curr == '/' || curr == 0) { |
440 | { | ||
441 | needsCRC = 1; | 410 | needsCRC = 1; |
442 | curr = ILLEGAL_CHAR_MARK; | 411 | curr = ILLEGAL_CHAR_MARK; |
443 | while (index+1 < udfLen && (udfName[index+1] == '/' || | 412 | while (index + 1 < udfLen && (udfName[index + 1] == '/' || |
444 | udfName[index+1] == 0)) | 413 | udfName[index + 1] == 0)) |
445 | index++; | 414 | index++; |
446 | } | 415 | } if (curr == EXT_MARK && (udfLen - index - 1) <= EXT_SIZE) { |
447 | if (curr == EXT_MARK && (udfLen - index - 1) <= EXT_SIZE) | 416 | if (udfLen == index + 1) { |
448 | { | ||
449 | if (udfLen == index + 1) | ||
450 | hasExt = 0; | 417 | hasExt = 0; |
451 | else | 418 | } else { |
452 | { | ||
453 | hasExt = 1; | 419 | hasExt = 1; |
454 | extIndex = index; | 420 | extIndex = index; |
455 | newExtIndex = newIndex; | 421 | newExtIndex = newIndex; |
@@ -461,26 +427,22 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen | |||
461 | needsCRC = 1; | 427 | needsCRC = 1; |
462 | } | 428 | } |
463 | } | 429 | } |
464 | if (needsCRC) | 430 | if (needsCRC) { |
465 | { | ||
466 | uint8_t ext[EXT_SIZE]; | 431 | uint8_t ext[EXT_SIZE]; |
467 | int localExtIndex = 0; | 432 | int localExtIndex = 0; |
468 | 433 | ||
469 | if (hasExt) | 434 | if (hasExt) { |
470 | { | ||
471 | int maxFilenameLen; | 435 | int maxFilenameLen; |
472 | for(index = 0; index<EXT_SIZE && extIndex + index +1 < udfLen; | 436 | for(index = 0; index < EXT_SIZE && extIndex + index + 1 < udfLen; index++) { |
473 | index++ ) | ||
474 | { | ||
475 | curr = udfName[extIndex + index + 1]; | 437 | curr = udfName[extIndex + index + 1]; |
476 | 438 | ||
477 | if (curr == '/' || curr == 0) | 439 | if (curr == '/' || curr == 0) { |
478 | { | ||
479 | needsCRC = 1; | 440 | needsCRC = 1; |
480 | curr = ILLEGAL_CHAR_MARK; | 441 | curr = ILLEGAL_CHAR_MARK; |
481 | while(extIndex + index + 2 < udfLen && (index + 1 < EXT_SIZE | 442 | while(extIndex + index + 2 < udfLen && |
482 | && (udfName[extIndex + index + 2] == '/' || | 443 | (index + 1 < EXT_SIZE |
483 | udfName[extIndex + index + 2] == 0))) | 444 | && (udfName[extIndex + index + 2] == '/' || |
445 | udfName[extIndex + index + 2] == 0))) | ||
484 | index++; | 446 | index++; |
485 | } | 447 | } |
486 | ext[localExtIndex++] = curr; | 448 | ext[localExtIndex++] = curr; |
@@ -490,9 +452,9 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen | |||
490 | newIndex = maxFilenameLen; | 452 | newIndex = maxFilenameLen; |
491 | else | 453 | else |
492 | newIndex = newExtIndex; | 454 | newIndex = newExtIndex; |
493 | } | 455 | } else if (newIndex > 250) { |
494 | else if (newIndex > 250) | ||
495 | newIndex = 250; | 456 | newIndex = 250; |
457 | } | ||
496 | newName[newIndex++] = CRC_MARK; | 458 | newName[newIndex++] = CRC_MARK; |
497 | valueCRC = udf_crc(fidName, fidNameLen, 0); | 459 | valueCRC = udf_crc(fidName, fidNameLen, 0); |
498 | newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12]; | 460 | newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12]; |
@@ -500,12 +462,12 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen | |||
500 | newName[newIndex++] = hexChar[(valueCRC & 0x00f0) >> 4]; | 462 | newName[newIndex++] = hexChar[(valueCRC & 0x00f0) >> 4]; |
501 | newName[newIndex++] = hexChar[(valueCRC & 0x000f)]; | 463 | newName[newIndex++] = hexChar[(valueCRC & 0x000f)]; |
502 | 464 | ||
503 | if (hasExt) | 465 | if (hasExt) { |
504 | { | ||
505 | newName[newIndex++] = EXT_MARK; | 466 | newName[newIndex++] = EXT_MARK; |
506 | for (index = 0;index < localExtIndex ;index++ ) | 467 | for (index = 0; index < localExtIndex; index++) |
507 | newName[newIndex++] = ext[index]; | 468 | newName[newIndex++] = ext[index]; |
508 | } | 469 | } |
509 | } | 470 | } |
471 | |||
510 | return newIndex; | 472 | return newIndex; |
511 | } | 473 | } |