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