]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * unicode.c | |
3 | * | |
4 | * PURPOSE | |
5 | * Routines for converting between UTF-8 and OSTA Compressed Unicode. | |
6 | * Also handles filename mangling | |
7 | * | |
8 | * DESCRIPTION | |
9 | * OSTA Compressed Unicode is explained in the OSTA UDF specification. | |
10 | * http://www.osta.org/ | |
11 | * UTF-8 is explained in the IETF RFC XXXX. | |
12 | * ftp://ftp.internic.net/rfc/rfcxxxx.txt | |
13 | * | |
1da177e4 LT |
14 | * COPYRIGHT |
15 | * This file is distributed under the terms of the GNU General Public | |
16 | * License (GPL). Copies of the GPL can be obtained from: | |
17 | * ftp://prep.ai.mit.edu/pub/gnu/GPL | |
18 | * Each contributing author retains all rights to their own work. | |
19 | */ | |
20 | ||
21 | #include "udfdecl.h" | |
22 | ||
23 | #include <linux/kernel.h> | |
24 | #include <linux/string.h> /* for memset */ | |
25 | #include <linux/nls.h> | |
f845fced | 26 | #include <linux/crc-itu-t.h> |
5a0e3ad6 | 27 | #include <linux/slab.h> |
1da177e4 LT |
28 | |
29 | #include "udf_sb.h" | |
30 | ||
0e5cc9a4 JK |
31 | static int udf_translate_to_linux(uint8_t *, int, uint8_t *, int, uint8_t *, |
32 | int); | |
1da177e4 | 33 | |
28de7948 | 34 | static int udf_char_to_ustr(struct ustr *dest, const uint8_t *src, int strlen) |
1da177e4 | 35 | { |
cb00ea35 | 36 | if ((!dest) || (!src) || (!strlen) || (strlen > UDF_NAME_LEN - 2)) |
1da177e4 | 37 | return 0; |
28de7948 | 38 | |
1da177e4 LT |
39 | memset(dest, 0, sizeof(struct ustr)); |
40 | memcpy(dest->u_name, src, strlen); | |
41 | dest->u_cmpID = 0x08; | |
42 | dest->u_len = strlen; | |
28de7948 | 43 | |
1da177e4 LT |
44 | return strlen; |
45 | } | |
46 | ||
47 | /* | |
48 | * udf_build_ustr | |
49 | */ | |
28de7948 | 50 | int udf_build_ustr(struct ustr *dest, dstring *ptr, int size) |
1da177e4 LT |
51 | { |
52 | int usesize; | |
53 | ||
6305a0a9 | 54 | if (!dest || !ptr || !size) |
1da177e4 | 55 | return -1; |
6305a0a9 | 56 | BUG_ON(size < 2); |
1da177e4 | 57 | |
6305a0a9 MS |
58 | usesize = min_t(size_t, ptr[size - 1], sizeof(dest->u_name)); |
59 | usesize = min(usesize, size - 2); | |
cb00ea35 | 60 | dest->u_cmpID = ptr[0]; |
6305a0a9 MS |
61 | dest->u_len = usesize; |
62 | memcpy(dest->u_name, ptr + 1, usesize); | |
63 | memset(dest->u_name + usesize, 0, sizeof(dest->u_name) - usesize); | |
28de7948 | 64 | |
1da177e4 LT |
65 | return 0; |
66 | } | |
67 | ||
68 | /* | |
69 | * udf_build_ustr_exact | |
70 | */ | |
28de7948 | 71 | static int udf_build_ustr_exact(struct ustr *dest, dstring *ptr, int exactsize) |
1da177e4 | 72 | { |
cb00ea35 | 73 | if ((!dest) || (!ptr) || (!exactsize)) |
1da177e4 LT |
74 | return -1; |
75 | ||
76 | memset(dest, 0, sizeof(struct ustr)); | |
cb00ea35 CG |
77 | dest->u_cmpID = ptr[0]; |
78 | dest->u_len = exactsize - 1; | |
79 | memcpy(dest->u_name, ptr + 1, exactsize - 1); | |
28de7948 | 80 | |
1da177e4 LT |
81 | return 0; |
82 | } | |
83 | ||
84 | /* | |
85 | * udf_ocu_to_utf8 | |
86 | * | |
87 | * PURPOSE | |
88 | * Convert OSTA Compressed Unicode to the UTF-8 equivalent. | |
89 | * | |
1da177e4 LT |
90 | * PRE-CONDITIONS |
91 | * utf Pointer to UTF-8 output buffer. | |
92 | * ocu Pointer to OSTA Compressed Unicode input buffer | |
93 | * of size UDF_NAME_LEN bytes. | |
94 | * both of type "struct ustr *" | |
95 | * | |
96 | * POST-CONDITIONS | |
97 | * <return> Zero on success. | |
98 | * | |
99 | * HISTORY | |
100 | * November 12, 1997 - Andrew E. Mileski | |
101 | * Written, tested, and released. | |
102 | */ | |
79cfe0ff | 103 | int udf_CS0toUTF8(struct ustr *utf_o, const struct ustr *ocu_i) |
1da177e4 | 104 | { |
79cfe0ff | 105 | const uint8_t *ocu; |
1da177e4 LT |
106 | uint8_t cmp_id, ocu_len; |
107 | int i; | |
108 | ||
1da177e4 | 109 | ocu_len = ocu_i->u_len; |
cb00ea35 | 110 | if (ocu_len == 0) { |
1da177e4 | 111 | memset(utf_o, 0, sizeof(struct ustr)); |
1da177e4 LT |
112 | return 0; |
113 | } | |
114 | ||
79cfe0ff | 115 | cmp_id = ocu_i->u_cmpID; |
116 | if (cmp_id != 8 && cmp_id != 16) { | |
117 | memset(utf_o, 0, sizeof(struct ustr)); | |
78ace70c | 118 | pr_err("unknown compression code (%d) stri=%s\n", |
cb00ea35 | 119 | cmp_id, ocu_i->u_name); |
1da177e4 LT |
120 | return 0; |
121 | } | |
122 | ||
79cfe0ff | 123 | ocu = ocu_i->u_name; |
124 | utf_o->u_len = 0; | |
cb00ea35 | 125 | for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN - 3));) { |
1da177e4 LT |
126 | |
127 | /* Expand OSTA compressed Unicode to Unicode */ | |
79cfe0ff | 128 | uint32_t c = ocu[i++]; |
1da177e4 LT |
129 | if (cmp_id == 16) |
130 | c = (c << 8) | ocu[i++]; | |
131 | ||
132 | /* Compress Unicode to UTF-8 */ | |
79cfe0ff | 133 | if (c < 0x80U) |
28de7948 | 134 | utf_o->u_name[utf_o->u_len++] = (uint8_t)c; |
79cfe0ff | 135 | else if (c < 0x800U) { |
4b11111a MS |
136 | utf_o->u_name[utf_o->u_len++] = |
137 | (uint8_t)(0xc0 | (c >> 6)); | |
138 | utf_o->u_name[utf_o->u_len++] = | |
139 | (uint8_t)(0x80 | (c & 0x3f)); | |
cb00ea35 | 140 | } else { |
4b11111a MS |
141 | utf_o->u_name[utf_o->u_len++] = |
142 | (uint8_t)(0xe0 | (c >> 12)); | |
143 | utf_o->u_name[utf_o->u_len++] = | |
144 | (uint8_t)(0x80 | | |
145 | ((c >> 6) & 0x3f)); | |
146 | utf_o->u_name[utf_o->u_len++] = | |
147 | (uint8_t)(0x80 | (c & 0x3f)); | |
1da177e4 LT |
148 | } |
149 | } | |
cb00ea35 | 150 | utf_o->u_cmpID = 8; |
1da177e4 LT |
151 | |
152 | return utf_o->u_len; | |
153 | } | |
154 | ||
155 | /* | |
156 | * | |
157 | * udf_utf8_to_ocu | |
158 | * | |
159 | * PURPOSE | |
160 | * Convert UTF-8 to the OSTA Compressed Unicode equivalent. | |
161 | * | |
162 | * DESCRIPTION | |
163 | * This routine is only called by udf_lookup(). | |
164 | * | |
165 | * PRE-CONDITIONS | |
166 | * ocu Pointer to OSTA Compressed Unicode output | |
167 | * buffer of size UDF_NAME_LEN bytes. | |
168 | * utf Pointer to UTF-8 input buffer. | |
169 | * utf_len Length of UTF-8 input buffer in bytes. | |
170 | * | |
171 | * POST-CONDITIONS | |
172 | * <return> Zero on success. | |
173 | * | |
174 | * HISTORY | |
175 | * November 12, 1997 - Andrew E. Mileski | |
176 | * Written, tested, and released. | |
177 | */ | |
28de7948 | 178 | static int udf_UTF8toCS0(dstring *ocu, struct ustr *utf, int length) |
1da177e4 LT |
179 | { |
180 | unsigned c, i, max_val, utf_char; | |
181 | int utf_cnt, u_len; | |
182 | ||
183 | memset(ocu, 0, sizeof(dstring) * length); | |
184 | ocu[0] = 8; | |
185 | max_val = 0xffU; | |
186 | ||
28de7948 | 187 | try_again: |
1da177e4 LT |
188 | u_len = 0U; |
189 | utf_char = 0U; | |
190 | utf_cnt = 0U; | |
cb00ea35 | 191 | for (i = 0U; i < utf->u_len; i++) { |
28de7948 | 192 | c = (uint8_t)utf->u_name[i]; |
1da177e4 LT |
193 | |
194 | /* Complete a multi-byte UTF-8 character */ | |
cb00ea35 | 195 | if (utf_cnt) { |
1da177e4 LT |
196 | utf_char = (utf_char << 6) | (c & 0x3fU); |
197 | if (--utf_cnt) | |
198 | continue; | |
cb00ea35 | 199 | } else { |
1da177e4 | 200 | /* Check for a multi-byte UTF-8 character */ |
cb00ea35 | 201 | if (c & 0x80U) { |
1da177e4 | 202 | /* Start a multi-byte UTF-8 character */ |
cb00ea35 | 203 | if ((c & 0xe0U) == 0xc0U) { |
1da177e4 LT |
204 | utf_char = c & 0x1fU; |
205 | utf_cnt = 1; | |
cb00ea35 | 206 | } else if ((c & 0xf0U) == 0xe0U) { |
1da177e4 LT |
207 | utf_char = c & 0x0fU; |
208 | utf_cnt = 2; | |
cb00ea35 | 209 | } else if ((c & 0xf8U) == 0xf0U) { |
1da177e4 LT |
210 | utf_char = c & 0x07U; |
211 | utf_cnt = 3; | |
cb00ea35 | 212 | } else if ((c & 0xfcU) == 0xf8U) { |
1da177e4 LT |
213 | utf_char = c & 0x03U; |
214 | utf_cnt = 4; | |
cb00ea35 | 215 | } else if ((c & 0xfeU) == 0xfcU) { |
1da177e4 LT |
216 | utf_char = c & 0x01U; |
217 | utf_cnt = 5; | |
28de7948 | 218 | } else { |
1da177e4 | 219 | goto error_out; |
28de7948 | 220 | } |
1da177e4 | 221 | continue; |
28de7948 | 222 | } else { |
1da177e4 LT |
223 | /* Single byte UTF-8 character (most common) */ |
224 | utf_char = c; | |
28de7948 | 225 | } |
1da177e4 LT |
226 | } |
227 | ||
228 | /* Choose no compression if necessary */ | |
cb00ea35 | 229 | if (utf_char > max_val) { |
28de7948 | 230 | if (max_val == 0xffU) { |
1da177e4 | 231 | max_val = 0xffffU; |
28de7948 | 232 | ocu[0] = (uint8_t)0x10U; |
1da177e4 LT |
233 | goto try_again; |
234 | } | |
235 | goto error_out; | |
236 | } | |
237 | ||
4b11111a | 238 | if (max_val == 0xffffU) |
28de7948 | 239 | ocu[++u_len] = (uint8_t)(utf_char >> 8); |
28de7948 | 240 | ocu[++u_len] = (uint8_t)(utf_char & 0xffU); |
1da177e4 LT |
241 | } |
242 | ||
cb00ea35 | 243 | if (utf_cnt) { |
28de7948 | 244 | error_out: |
1da177e4 | 245 | ocu[++u_len] = '?'; |
78ace70c | 246 | printk(KERN_DEBUG pr_fmt("bad UTF-8 character\n")); |
1da177e4 LT |
247 | } |
248 | ||
28de7948 CG |
249 | ocu[length - 1] = (uint8_t)u_len + 1; |
250 | ||
1da177e4 LT |
251 | return u_len + 1; |
252 | } | |
253 | ||
cb00ea35 | 254 | static int udf_CS0toNLS(struct nls_table *nls, struct ustr *utf_o, |
34f953dd | 255 | const struct ustr *ocu_i) |
1da177e4 | 256 | { |
34f953dd | 257 | const uint8_t *ocu; |
1da177e4 | 258 | uint8_t cmp_id, ocu_len; |
59285c28 | 259 | int i, len; |
1da177e4 | 260 | |
1da177e4 LT |
261 | |
262 | ocu_len = ocu_i->u_len; | |
cb00ea35 | 263 | if (ocu_len == 0) { |
1da177e4 | 264 | memset(utf_o, 0, sizeof(struct ustr)); |
1da177e4 LT |
265 | return 0; |
266 | } | |
267 | ||
34f953dd | 268 | cmp_id = ocu_i->u_cmpID; |
269 | if (cmp_id != 8 && cmp_id != 16) { | |
270 | memset(utf_o, 0, sizeof(struct ustr)); | |
78ace70c | 271 | pr_err("unknown compression code (%d) stri=%s\n", |
cb00ea35 | 272 | cmp_id, ocu_i->u_name); |
1da177e4 LT |
273 | return 0; |
274 | } | |
275 | ||
34f953dd | 276 | ocu = ocu_i->u_name; |
277 | utf_o->u_len = 0; | |
cb00ea35 | 278 | for (i = 0; (i < ocu_len) && (utf_o->u_len <= (UDF_NAME_LEN - 3));) { |
1da177e4 | 279 | /* Expand OSTA compressed Unicode to Unicode */ |
34f953dd | 280 | uint32_t c = ocu[i++]; |
1da177e4 LT |
281 | if (cmp_id == 16) |
282 | c = (c << 8) | ocu[i++]; | |
283 | ||
59285c28 JK |
284 | len = nls->uni2char(c, &utf_o->u_name[utf_o->u_len], |
285 | UDF_NAME_LEN - utf_o->u_len); | |
286 | /* Valid character? */ | |
287 | if (len >= 0) | |
288 | utf_o->u_len += len; | |
289 | else | |
290 | utf_o->u_name[utf_o->u_len++] = '?'; | |
1da177e4 | 291 | } |
cb00ea35 | 292 | utf_o->u_cmpID = 8; |
1da177e4 LT |
293 | |
294 | return utf_o->u_len; | |
295 | } | |
296 | ||
28de7948 | 297 | static int udf_NLStoCS0(struct nls_table *nls, dstring *ocu, struct ustr *uni, |
cb00ea35 | 298 | int length) |
1da177e4 | 299 | { |
59285c28 JK |
300 | int len; |
301 | unsigned i, max_val; | |
1da177e4 LT |
302 | uint16_t uni_char; |
303 | int u_len; | |
304 | ||
305 | memset(ocu, 0, sizeof(dstring) * length); | |
306 | ocu[0] = 8; | |
307 | max_val = 0xffU; | |
308 | ||
28de7948 | 309 | try_again: |
1da177e4 | 310 | u_len = 0U; |
cb00ea35 CG |
311 | for (i = 0U; i < uni->u_len; i++) { |
312 | len = nls->char2uni(&uni->u_name[i], uni->u_len - i, &uni_char); | |
59285c28 | 313 | if (!len) |
1da177e4 | 314 | continue; |
59285c28 JK |
315 | /* Invalid character, deal with it */ |
316 | if (len < 0) { | |
317 | len = 1; | |
318 | uni_char = '?'; | |
319 | } | |
1da177e4 | 320 | |
cb00ea35 | 321 | if (uni_char > max_val) { |
1da177e4 | 322 | max_val = 0xffffU; |
28de7948 | 323 | ocu[0] = (uint8_t)0x10U; |
1da177e4 LT |
324 | goto try_again; |
325 | } | |
cb00ea35 | 326 | |
1da177e4 | 327 | if (max_val == 0xffffU) |
28de7948 CG |
328 | ocu[++u_len] = (uint8_t)(uni_char >> 8); |
329 | ocu[++u_len] = (uint8_t)(uni_char & 0xffU); | |
1da177e4 LT |
330 | i += len - 1; |
331 | } | |
332 | ||
28de7948 | 333 | ocu[length - 1] = (uint8_t)u_len + 1; |
1da177e4 LT |
334 | return u_len + 1; |
335 | } | |
336 | ||
0e5cc9a4 JK |
337 | int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen, |
338 | uint8_t *dname, int dlen) | |
1da177e4 | 339 | { |
530f1a5e | 340 | struct ustr *filename, *unifilename; |
5ceb8b55 | 341 | int ret = 0; |
1da177e4 | 342 | |
530f1a5e MS |
343 | filename = kmalloc(sizeof(struct ustr), GFP_NOFS); |
344 | if (!filename) | |
5ceb8b55 | 345 | return -ENOMEM; |
1da177e4 | 346 | |
530f1a5e | 347 | unifilename = kmalloc(sizeof(struct ustr), GFP_NOFS); |
5ceb8b55 FF |
348 | if (!unifilename) { |
349 | ret = -ENOMEM; | |
530f1a5e | 350 | goto out1; |
5ceb8b55 | 351 | } |
530f1a5e | 352 | |
0e5cc9a4 | 353 | if (udf_build_ustr_exact(unifilename, sname, slen)) |
530f1a5e MS |
354 | goto out2; |
355 | ||
cb00ea35 | 356 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { |
530f1a5e | 357 | if (!udf_CS0toUTF8(filename, unifilename)) { |
4b11111a MS |
358 | udf_debug("Failed in udf_get_filename: sname = %s\n", |
359 | sname); | |
530f1a5e | 360 | goto out2; |
1da177e4 | 361 | } |
cb00ea35 | 362 | } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { |
530f1a5e MS |
363 | if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, filename, |
364 | unifilename)) { | |
4b11111a MS |
365 | udf_debug("Failed in udf_get_filename: sname = %s\n", |
366 | sname); | |
530f1a5e | 367 | goto out2; |
1da177e4 | 368 | } |
4b11111a | 369 | } else |
530f1a5e MS |
370 | goto out2; |
371 | ||
5ceb8b55 | 372 | ret = udf_translate_to_linux(dname, dlen, |
0e5cc9a4 | 373 | filename->u_name, filename->u_len, |
530f1a5e MS |
374 | unifilename->u_name, unifilename->u_len); |
375 | out2: | |
376 | kfree(unifilename); | |
377 | out1: | |
378 | kfree(filename); | |
5ceb8b55 | 379 | return ret; |
1da177e4 LT |
380 | } |
381 | ||
28de7948 CG |
382 | int udf_put_filename(struct super_block *sb, const uint8_t *sname, |
383 | uint8_t *dname, int flen) | |
1da177e4 LT |
384 | { |
385 | struct ustr unifilename; | |
386 | int namelen; | |
387 | ||
4b11111a | 388 | if (!udf_char_to_ustr(&unifilename, sname, flen)) |
1da177e4 | 389 | return 0; |
1da177e4 | 390 | |
cb00ea35 | 391 | if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) { |
28de7948 | 392 | namelen = udf_UTF8toCS0(dname, &unifilename, UDF_NAME_LEN); |
4b11111a | 393 | if (!namelen) |
1da177e4 | 394 | return 0; |
cb00ea35 | 395 | } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) { |
4b11111a MS |
396 | namelen = udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname, |
397 | &unifilename, UDF_NAME_LEN); | |
398 | if (!namelen) | |
1da177e4 | 399 | return 0; |
4b11111a | 400 | } else |
1da177e4 LT |
401 | return 0; |
402 | ||
403 | return namelen; | |
404 | } | |
405 | ||
406 | #define ILLEGAL_CHAR_MARK '_' | |
28de7948 CG |
407 | #define EXT_MARK '.' |
408 | #define CRC_MARK '#' | |
409 | #define EXT_SIZE 5 | |
0e5cc9a4 JK |
410 | /* Number of chars we need to store generated CRC to make filename unique */ |
411 | #define CRC_LEN 5 | |
1da177e4 | 412 | |
0e5cc9a4 JK |
413 | static int udf_translate_to_linux(uint8_t *newName, int newLen, |
414 | uint8_t *udfName, int udfLen, | |
415 | uint8_t *fidName, int fidNameLen) | |
1da177e4 | 416 | { |
cb00ea35 | 417 | int index, newIndex = 0, needsCRC = 0; |
1da177e4 LT |
418 | int extIndex = 0, newExtIndex = 0, hasExt = 0; |
419 | unsigned short valueCRC; | |
420 | uint8_t curr; | |
1da177e4 | 421 | |
28de7948 CG |
422 | if (udfName[0] == '.' && |
423 | (udfLen == 1 || (udfLen == 2 && udfName[1] == '.'))) { | |
1da177e4 LT |
424 | needsCRC = 1; |
425 | newIndex = udfLen; | |
426 | memcpy(newName, udfName, udfLen); | |
cb00ea35 CG |
427 | } else { |
428 | for (index = 0; index < udfLen; index++) { | |
1da177e4 | 429 | curr = udfName[index]; |
cb00ea35 | 430 | if (curr == '/' || curr == 0) { |
1da177e4 LT |
431 | needsCRC = 1; |
432 | curr = ILLEGAL_CHAR_MARK; | |
4b11111a MS |
433 | while (index + 1 < udfLen && |
434 | (udfName[index + 1] == '/' || | |
435 | udfName[index + 1] == 0)) | |
1da177e4 | 436 | index++; |
4b11111a MS |
437 | } |
438 | if (curr == EXT_MARK && | |
439 | (udfLen - index - 1) <= EXT_SIZE) { | |
440 | if (udfLen == index + 1) | |
1da177e4 | 441 | hasExt = 0; |
4b11111a | 442 | else { |
1da177e4 LT |
443 | hasExt = 1; |
444 | extIndex = index; | |
445 | newExtIndex = newIndex; | |
446 | } | |
447 | } | |
0e5cc9a4 | 448 | if (newIndex < newLen) |
1da177e4 LT |
449 | newName[newIndex++] = curr; |
450 | else | |
451 | needsCRC = 1; | |
452 | } | |
453 | } | |
cb00ea35 | 454 | if (needsCRC) { |
1da177e4 LT |
455 | uint8_t ext[EXT_SIZE]; |
456 | int localExtIndex = 0; | |
457 | ||
cb00ea35 | 458 | if (hasExt) { |
1da177e4 | 459 | int maxFilenameLen; |
4b11111a MS |
460 | for (index = 0; |
461 | index < EXT_SIZE && extIndex + index + 1 < udfLen; | |
462 | index++) { | |
1da177e4 LT |
463 | curr = udfName[extIndex + index + 1]; |
464 | ||
cb00ea35 | 465 | if (curr == '/' || curr == 0) { |
1da177e4 LT |
466 | needsCRC = 1; |
467 | curr = ILLEGAL_CHAR_MARK; | |
4b11111a MS |
468 | while (extIndex + index + 2 < udfLen && |
469 | (index + 1 < EXT_SIZE && | |
470 | (udfName[extIndex + index + 2] == '/' || | |
471 | udfName[extIndex + index + 2] == 0))) | |
1da177e4 LT |
472 | index++; |
473 | } | |
474 | ext[localExtIndex++] = curr; | |
475 | } | |
0e5cc9a4 | 476 | maxFilenameLen = newLen - CRC_LEN - localExtIndex; |
1da177e4 LT |
477 | if (newIndex > maxFilenameLen) |
478 | newIndex = maxFilenameLen; | |
479 | else | |
480 | newIndex = newExtIndex; | |
0e5cc9a4 JK |
481 | } else if (newIndex > newLen - CRC_LEN) |
482 | newIndex = newLen - CRC_LEN; | |
1da177e4 | 483 | newName[newIndex++] = CRC_MARK; |
f845fced | 484 | valueCRC = crc_itu_t(0, fidName, fidNameLen); |
c7ff4821 AS |
485 | newName[newIndex++] = hex_asc_upper_hi(valueCRC >> 8); |
486 | newName[newIndex++] = hex_asc_upper_lo(valueCRC >> 8); | |
487 | newName[newIndex++] = hex_asc_upper_hi(valueCRC); | |
488 | newName[newIndex++] = hex_asc_upper_lo(valueCRC); | |
1da177e4 | 489 | |
cb00ea35 | 490 | if (hasExt) { |
1da177e4 | 491 | newName[newIndex++] = EXT_MARK; |
cb00ea35 | 492 | for (index = 0; index < localExtIndex; index++) |
1da177e4 LT |
493 | newName[newIndex++] = ext[index]; |
494 | } | |
495 | } | |
28de7948 | 496 | |
1da177e4 LT |
497 | return newIndex; |
498 | } |