2 * Copyright (c) 2000-2010 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/malloc.h>
34 #include <sys/queue.h>
35 #include <sys/utfconv.h>
36 #include <kern/host.h>
37 #include <mach/host_priv.h>
38 #include <libkern/OSKextLib.h>
39 #include <libkern/OSKextLibPrivate.h>
44 lck_grp_t
* encodinglst_lck_grp
;
45 lck_grp_attr_t
* encodinglst_lck_grp_attr
;
46 lck_attr_t
* encodinglst_lck_attr
;
49 /* hfs encoding converter list */
50 SLIST_HEAD(encodinglst
, hfs_encoding
) hfs_encoding_list
= {0};
52 lck_mtx_t encodinglst_mutex
;
56 /* hfs encoding converter entry */
58 SLIST_ENTRY(hfs_encoding
) link
;
62 hfs_to_unicode_func_t get_unicode_func
;
63 unicode_to_hfs_func_t get_hfsname_func
;
66 #define MAX_HFS_UNICODE_CHARS (15*5)
68 static int unicode_to_mac_roman(UniChar
*uni_str
, u_int32_t unicodeChars
, Str31 hfs_str
);
71 hfs_converterinit(void)
73 SLIST_INIT(&hfs_encoding_list
);
75 encodinglst_lck_grp_attr
= lck_grp_attr_alloc_init();
76 encodinglst_lck_grp
= lck_grp_alloc_init("cnode_hash", encodinglst_lck_grp_attr
);
77 encodinglst_lck_attr
= lck_attr_alloc_init();
79 lck_mtx_init(&encodinglst_mutex
, encodinglst_lck_grp
, encodinglst_lck_attr
);
82 * add resident MacRoman converter and take a reference
83 * since its always "loaded".
85 hfs_addconverter(0, kTextEncodingMacRoman
, mac_roman_to_unicode
, unicode_to_mac_roman
);
86 SLIST_FIRST(&hfs_encoding_list
)->refcount
++;
91 * hfs_addconverter - add an HFS encoding converter
93 * This is called exclusivly by kernel loadable modules
94 * (like HFS_Japanese.kmod) to register hfs encoding
95 * conversion routines.
99 hfs_addconverter(int id
, u_int32_t encoding
, hfs_to_unicode_func_t get_unicode
, unicode_to_hfs_func_t get_hfsname
)
101 struct hfs_encoding
*encp
;
103 MALLOC(encp
, struct hfs_encoding
*, sizeof(struct hfs_encoding
), M_TEMP
, M_WAITOK
);
105 lck_mtx_lock(&encodinglst_mutex
);
107 encp
->link
.sle_next
= NULL
;
109 encp
->encoding
= encoding
;
110 encp
->get_unicode_func
= get_unicode
;
111 encp
->get_hfsname_func
= get_hfsname
;
113 SLIST_INSERT_HEAD(&hfs_encoding_list
, encp
, link
);
115 lck_mtx_unlock(&encodinglst_mutex
);
121 * hfs_remconverter - remove an HFS encoding converter
123 * Can be called by a kernel loadable module's finalize
124 * routine to remove an encoding converter so that the
125 * module (i.e. the code) can be unloaded.
127 * However, in the normal case, the removing and unloading
128 * of these converters is done in hfs_relconverter.
129 * The call is initiated from within the kernel during the unmounting of an hfs voulume.
132 hfs_remconverter(int id
, u_int32_t encoding
)
134 struct hfs_encoding
*encp
;
136 lck_mtx_lock(&encodinglst_mutex
);
137 SLIST_FOREACH(encp
, &hfs_encoding_list
, link
) {
138 if (encp
->encoding
== encoding
&& encp
->kmod_id
== id
) {
141 /* if converter is no longer in use, release it */
142 if (encp
->refcount
<= 0 && encp
->kmod_id
!= 0) {
143 SLIST_REMOVE(&hfs_encoding_list
, encp
, hfs_encoding
, link
);
144 lck_mtx_unlock(&encodinglst_mutex
);
148 lck_mtx_unlock(&encodinglst_mutex
);
149 return (1); /* busy */
154 lck_mtx_unlock(&encodinglst_mutex
);
161 * hfs_getconverter - get HFS encoding converters
163 * Normally called during the mounting of an hfs voulume.
166 hfs_getconverter(u_int32_t encoding
, hfs_to_unicode_func_t
*get_unicode
, unicode_to_hfs_func_t
*get_hfsname
)
168 struct hfs_encoding
*encp
;
171 lck_mtx_lock(&encodinglst_mutex
);
172 SLIST_FOREACH(encp
, &hfs_encoding_list
, link
) {
173 if (encp
->encoding
== encoding
) {
175 *get_unicode
= encp
->get_unicode_func
;
176 *get_hfsname
= encp
->get_hfsname_func
;
181 lck_mtx_unlock(&encodinglst_mutex
);
194 * hfs_relconverter - release interest in an HFS encoding converter
196 * Normally called during the unmounting of an hfs voulume.
199 hfs_relconverter(u_int32_t encoding
)
201 struct hfs_encoding
*encp
;
203 lck_mtx_lock(&encodinglst_mutex
);
204 SLIST_FOREACH(encp
, &hfs_encoding_list
, link
) {
205 if (encp
->encoding
== encoding
) {
208 /* if converter is no longer in use, release it */
209 if (encp
->refcount
<= 0 && encp
->kmod_id
!= 0) {
210 uint32_t loadTag
= (uint32_t)encp
->kmod_id
;
212 SLIST_REMOVE(&hfs_encoding_list
, encp
, hfs_encoding
, link
);
213 lck_mtx_unlock(&encodinglst_mutex
);
216 (void)OSKextUnloadKextWithLoadTag(loadTag
);
219 lck_mtx_unlock(&encodinglst_mutex
);
223 lck_mtx_unlock(&encodinglst_mutex
);
230 * Convert HFS encoded string into UTF-8
232 * Unicode output is fully decomposed
233 * '/' chars are converted to ':'
236 hfs_to_utf8(ExtendedVCB
*vcb
, const Str31 hfs_str
, ByteCount maxDstLen
, ByteCount
*actualDstLen
, unsigned char* dstStr
)
239 UniChar uniStr
[MAX_HFS_UNICODE_CHARS
];
242 hfs_to_unicode_func_t hfs_get_unicode
= VCBTOHFS(vcb
)->hfs_get_unicode
;
243 u_int8_t pascal_length
= 0;
246 * Validate the length of the Pascal-style string before passing it
247 * down to the decoding engine.
249 pascal_length
= *((const u_int8_t
*)(hfs_str
));
250 if (pascal_length
> 31) {
251 /* invalid string; longer than 31 bytes */
256 error
= hfs_get_unicode(hfs_str
, uniStr
, MAX_HFS_UNICODE_CHARS
, &uniCount
);
262 error
= utf8_encodestr(uniStr
, uniCount
* sizeof(UniChar
), dstStr
, &utf8len
, maxDstLen
, ':', 0);
263 if (error
== ENAMETOOLONG
)
264 *actualDstLen
= utf8_encodelen(uniStr
, uniCount
* sizeof(UniChar
), ':', 0);
266 *actualDstLen
= utf8len
;
274 * When an HFS name cannot be encoded with the current
275 * volume encoding then MacRoman is used as a fallback.
278 mac_roman_to_utf8(const Str31 hfs_str
, ByteCount maxDstLen
, ByteCount
*actualDstLen
, unsigned char* dstStr
)
281 UniChar uniStr
[MAX_HFS_UNICODE_CHARS
];
284 u_int8_t pascal_length
= 0;
287 * Validate the length of the Pascal-style string before passing it
288 * down to the decoding engine.
290 pascal_length
= *((const u_int8_t
*)(hfs_str
));
291 if (pascal_length
> 31) {
292 /* invalid string; longer than 31 bytes */
297 error
= mac_roman_to_unicode(hfs_str
, uniStr
, MAX_HFS_UNICODE_CHARS
, &uniCount
);
303 error
= utf8_encodestr(uniStr
, uniCount
* sizeof(UniChar
), dstStr
, &utf8len
, maxDstLen
, ':', 0);
304 if (error
== ENAMETOOLONG
)
305 *actualDstLen
= utf8_encodelen(uniStr
, uniCount
* sizeof(UniChar
), ':', 0);
307 *actualDstLen
= utf8len
;
315 * Convert Unicode string into HFS encoding
317 * ':' chars are converted to '/'
318 * Assumes input represents fully decomposed Unicode
321 unicode_to_hfs(ExtendedVCB
*vcb
, ByteCount srcLen
, u_int16_t
* srcStr
, Str31 dstStr
, int retry
)
324 unicode_to_hfs_func_t hfs_get_hfsname
= VCBTOHFS(vcb
)->hfs_get_hfsname
;
326 error
= hfs_get_hfsname(srcStr
, srcLen
/sizeof(UniChar
), dstStr
);
327 if (error
&& retry
) {
328 error
= unicode_to_mac_roman(srcStr
, srcLen
/sizeof(UniChar
), dstStr
);
334 * Convert UTF-8 string into HFS encoding
336 * ':' chars are converted to '/'
337 * Assumes input represents fully decomposed Unicode
340 utf8_to_hfs(ExtendedVCB
*vcb
, ByteCount srcLen
, const unsigned char* srcStr
, Str31 dstStr
/*, int retry*/)
343 UniChar uniStr
[MAX_HFS_UNICODE_CHARS
];
346 error
= utf8_decodestr(srcStr
, srcLen
, uniStr
, &ucslen
, sizeof(uniStr
), ':', 0);
348 error
= unicode_to_hfs(vcb
, ucslen
, uniStr
, dstStr
, 1);
354 utf8_to_mac_roman(ByteCount srcLen
, const unsigned char* srcStr
, Str31 dstStr
)
357 UniChar uniStr
[MAX_HFS_UNICODE_CHARS
];
360 error
= utf8_decodestr(srcStr
, srcLen
, uniStr
, &ucslen
, sizeof(uniStr
), ':', 0);
362 error
= unicode_to_mac_roman(uniStr
, ucslen
/sizeof(UniChar
), dstStr
);
368 * HFS MacRoman to/from Unicode conversions are built into the kernel
369 * All others hfs encodings are loadable.
372 /* 0x00A0 - 0x00FF = Latin 1 Supplement (30 total) */
373 static u_int8_t gLatin1Table
[] = {
374 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
375 /* 0x00A0 */ 0xCA, 0xC1, 0xA2, 0xA3, 0xDB, 0xB4, '?', 0xA4, 0xAC, 0xA9, 0xBB, 0xC7, 0xC2, '?', 0xA8, 0xF8,
376 /* 0x00B0 */ 0xA1, 0XB1, '?', '?', 0xAB, 0xB5, 0xA6, 0xe1, 0xFC, '?', 0xBC, 0xC8, '?', '?', '?', 0xC0,
377 /* 0x00C0 */ '?', '?', '?', '?', '?', '?', 0xAE, '?', '?', '?', '?', '?', '?', '?', '?', '?',
378 /* 0x00D0 */ '?', '?', '?', '?', '?', '?', '?', '?', 0xAF, '?', '?', '?', '?', '?', '?', 0xA7,
379 /* 0x00E0 */ '?', '?', '?', '?', '?', '?', 0xBE, '?', '?', '?', '?', '?', '?', '?', '?', '?',
380 /* 0x00F0 */ '?', '?', '?', '?', '?', '?', '?', 0xD6, 0xBF, '?', '?', '?', '?', '?', '?', '?'
383 /* 0x02C0 - 0x02DF = Spacing Modifiers (8 total) */
384 static u_int8_t gSpaceModsTable
[] = {
385 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
386 /* 0x02C0 */ '?', '?', '?', '?', '?', '?', 0xF6, 0xFF, '?', '?', '?', '?', '?', '?', '?', '?',
387 /* 0x02D0 */ '?', '?', '?', '?', '?', '?', '?', '?', 0xF9, 0xFA, 0xFB, 0xFE, 0xF7, 0xFD, '?', '?'
390 /* 0x2010 - 0x20AF = General Punctuation (17 total) */
391 static u_int8_t gPunctTable
[] = {
392 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
393 /* 0x2010 */ '?', '?', '?', 0xd0, 0xd1, '?', '?', '?', 0xd4, 0xd5, 0xe2, '?', 0xd2, 0xd3, 0xe3, '?',
394 /* 0x2020 */ 0xa0, 0xe0, 0xa5, '?', '?', '?', 0xc9, '?', '?', '?', '?', '?', '?', '?', '?', '?',
395 /* 0x2030 */ 0xe4, '?', '?', '?', '?', '?', '?', '?', '?', 0xdc, 0xdd, '?', '?', '?', '?', '?',
396 /* 0x2040 */ '?', '?', '?', '?', 0xda, '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
397 /* 0x2050 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
398 /* 0x2060 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
399 /* 0x2070 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
400 /* 0x2080 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
401 /* 0x2090 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
402 /* 0x20A0 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', 0xdb, '?', '?', '?'
405 /* 0x22xx = Mathematical Operators (11 total) */
406 static u_int8_t gMathTable
[] = {
407 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
408 /* 0x2200 */ '?', '?', 0xb6, '?', '?', '?', 0xc6, '?', '?', '?', '?', '?', '?', '?', '?', 0xb8,
409 /* 0x2210 */ '?', 0xb7, '?', '?', '?', '?', '?', '?', '?', '?', 0xc3, '?', '?', '?', 0xb0, '?',
410 /* 0x2220 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', 0xba, '?', '?', '?', '?',
411 /* 0x2230 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
412 /* 0x2240 */ '?', '?', '?', '?', '?', '?', '?', '?', 0xc5, '?', '?', '?', '?', '?', '?', '?',
413 /* 0x2250 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?',
414 /* 0x2260 */ 0xad, '?', '?', '?', 0xb2, 0xb3, '?', '?'
418 static u_int8_t gReverseCombTable
[] = {
419 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
420 /* 0x40 */ 0xDA, 0x40, 0xDA, 0xDA, 0xDA, 0x56, 0xDA, 0xDA, 0xDA, 0x6C, 0xDA, 0xDA, 0xDA, 0xDA, 0x82, 0x98,
421 /* 0x50 */ 0xDA, 0xDA, 0xDA, 0xDA, 0xDA, 0xAE, 0xDA, 0xDA, 0xDA, 0xC4, 0xDA, 0xDA, 0xDA, 0xDA, 0xDA, 0xDA,
422 /* 0x60 */ 0xDA, 0x4B, 0xDA, 0xDA, 0xDA, 0x61, 0xDA, 0xDA, 0xDA, 0x77, 0xDA, 0xDA, 0xDA, 0xDA, 0x8D, 0xA3,
423 /* 0x70 */ 0xDA, 0xDA, 0xDA, 0xDA, 0xDA, 0xB9, 0xDA, 0xDA, 0xDA, 0xCF, 0xDA, 0xDA, 0xDA, 0xDA, 0xDA, 0xDA,
425 /* Combining Diacritical Marks (0x0300 - 0x030A) */
426 /* 0 1 2 3 4 5 6 7 8 9 A */
428 /* 0x0300 */ 0xCB, 0xE7, 0xE5, 0xCC, '?', '?', '?', '?', 0x80, '?', 0x81,
431 /* 0x0300 */ 0x88, 0x87, 0x89, 0x8B, '?', '?', '?', '?', 0x8A, '?', 0x8C,
434 /* 0x0300 */ 0xE9, 0x83, 0xE6, '?', '?', '?', '?', '?', 0xE8, '?', '?',
437 /* 0x0300 */ 0x8F, 0x8E, 0x90, '?', '?', '?', '?', '?', 0x91, '?', '?',
440 /* 0x0300 */ 0xED, 0xEA, 0xEB, '?', '?', '?', '?', '?', 0xEC, '?', '?',
443 /* 0x0300 */ 0x93, 0x92, 0x94, '?', '?', '?', '?', '?', 0x95, '?', '?',
446 /* 0x0300 */ '?', '?', '?', 0x84, '?', '?', '?', '?', '?', '?', '?',
449 /* 0x0300 */ '?', '?', '?', 0x96, '?', '?', '?', '?', '?', '?', '?',
452 /* 0x0300 */ 0xF1, 0xEE, 0xEF, 0xCD, '?', '?', '?', '?', 0x85, '?', '?',
455 /* 0x0300 */ 0x98, 0x97, 0x99, 0x9B, '?', '?', '?', '?', 0x9A, '?', '?',
458 /* 0x0300 */ 0xF4, 0xF2, 0xF3, '?', '?', '?', '?', '?', 0x86, '?', '?',
461 /* 0x0300 */ 0x9D, 0x9C, 0x9E, '?', '?', '?', '?', '?', 0x9F, '?', '?',
464 /* 0x0300 */ '?', '?', '?', '?', '?', '?', '?', '?', 0xD9, '?', '?',
467 /* 0x0300 */ '?', '?', '?', '?', '?', '?', '?', '?', 0xD8, '?', '?',
470 /* 0x0300 */ '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?'
475 * Convert Unicode string into HFS MacRoman encoding
477 * Assumes Unicode input is fully decomposed
479 static int unicode_to_mac_roman(UniChar
*uni_str
, u_int32_t unicodeChars
, Str31 hfs_str
)
485 u_int16_t inputChars
;
486 u_int16_t pascalChars
;
487 OSErr result
= noErr
;
492 mask
= (UniChar
) 0xFF80;
495 inputChars
= unicodeChars
;
496 pascalChars
= prevChar
= 0;
503 * If its not 7-bit ascii, then we need to map it
507 switch (c
& 0xFF00) {
510 mc
= gLatin1Table
[lsb
- 0xA0];
514 if (lsb
>= 0xC0 && lsb
<= 0xDF)
515 mc
= gSpaceModsTable
[lsb
- 0xC0];
519 if (lsb
>= 0x10 && lsb
<= 0xAF)
520 mc
= gPunctTable
[lsb
- 0x10];
525 mc
= gMathTable
[lsb
];
530 if (prevChar
>= 'A' && prevChar
< 'z') {
531 mc
= gReverseCombTable
[gReverseCombTable
[prevChar
- 0x40] + lsb
];
532 --p
; /* backup over base char */
537 case 0x0327: /* combining cedilla */
540 else if (prevChar
== 'c')
544 --p
; /* backup over base char */
548 case 0x03A9: mc
= 0xBD; break; /* omega */
550 case 0x03C0: mc
= 0xB9; break; /* pi */
557 case 0x0131: mc
= 0xf5; break; /* dotless i */
559 case 0x0152: mc
= 0xce; break; /* OE */
561 case 0x0153: mc
= 0xcf; break; /* oe */
563 case 0x0192: mc
= 0xc4; break; /* Ä */
565 case 0x2122: mc
= 0xaa; break; /* TM */
567 case 0x25ca: mc
= 0xd7; break; /* diamond */
569 case 0xf8ff: mc
= 0xf0; break; /* apple logo */
571 case 0xfb01: mc
= 0xde; break; /* fi */
573 case 0xfb02: mc
= 0xdf; break; /* fl */
575 } /* end switch (c & 0xFF00) */
578 * If we have an unmapped character then we need to mangle the name...
581 result
= kTECUsedFallbacksStatus
;
590 if (pascalChars
>= 31)
599 hfs_str
[0] = pascalChars
;
602 result
= ENAMETOOLONG
; /* ran out of room! */
608 static UniChar gHiBitBaseUnicode
[128] = {
609 /* 0x80 */ 0x0041, 0x0041, 0x0043, 0x0045, 0x004e, 0x004f, 0x0055, 0x0061,
610 /* 0x88 */ 0x0061, 0x0061, 0x0061, 0x0061, 0x0061, 0x0063, 0x0065, 0x0065,
611 /* 0x90 */ 0x0065, 0x0065, 0x0069, 0x0069, 0x0069, 0x0069, 0x006e, 0x006f,
612 /* 0x98 */ 0x006f, 0x006f, 0x006f, 0x006f, 0x0075, 0x0075, 0x0075, 0x0075,
613 /* 0xa0 */ 0x2020, 0x00b0, 0x00a2, 0x00a3, 0x00a7, 0x2022, 0x00b6, 0x00df,
614 /* 0xa8 */ 0x00ae, 0x00a9, 0x2122, 0x00b4, 0x00a8, 0x2260, 0x00c6, 0x00d8,
615 /* 0xb0 */ 0x221e, 0x00b1, 0x2264, 0x2265, 0x00a5, 0x00b5, 0x2202, 0x2211,
616 /* 0xb8 */ 0x220f, 0x03c0, 0x222b, 0x00aa, 0x00ba, 0x03a9, 0x00e6, 0x00f8,
617 /* 0xc0 */ 0x00bf, 0x00a1, 0x00ac, 0x221a, 0x0192, 0x2248, 0x2206, 0x00ab,
618 /* 0xc8 */ 0x00bb, 0x2026, 0x00a0, 0x0041, 0x0041, 0x004f, 0x0152, 0x0153,
619 /* 0xd0 */ 0x2013, 0x2014, 0x201c, 0x201d, 0x2018, 0x2019, 0x00f7, 0x25ca,
620 /* 0xd8 */ 0x0079, 0x0059, 0x2044, 0x20ac, 0x2039, 0x203a, 0xfb01, 0xfb02,
621 /* 0xe0 */ 0x2021, 0x00b7, 0x201a, 0x201e, 0x2030, 0x0041, 0x0045, 0x0041,
622 /* 0xe8 */ 0x0045, 0x0045, 0x0049, 0x0049, 0x0049, 0x0049, 0x004f, 0x004f,
623 /* 0xf0 */ 0xf8ff, 0x004f, 0x0055, 0x0055, 0x0055, 0x0131, 0x02c6, 0x02dc,
624 /* 0xf8 */ 0x00af, 0x02d8, 0x02d9, 0x02da, 0x00b8, 0x02dd, 0x02db, 0x02c7
627 static UniChar gHiBitCombUnicode
[128] = {
628 /* 0x80 */ 0x0308, 0x030a, 0x0327, 0x0301, 0x0303, 0x0308, 0x0308, 0x0301,
629 /* 0x88 */ 0x0300, 0x0302, 0x0308, 0x0303, 0x030a, 0x0327, 0x0301, 0x0300,
630 /* 0x90 */ 0x0302, 0x0308, 0x0301, 0x0300, 0x0302, 0x0308, 0x0303, 0x0301,
631 /* 0x98 */ 0x0300, 0x0302, 0x0308, 0x0303, 0x0301, 0x0300, 0x0302, 0x0308,
632 /* 0xa0 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
633 /* 0xa8 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
634 /* 0xb0 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
635 /* 0xb8 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
636 /* 0xc0 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
637 /* 0xc8 */ 0x0000, 0x0000, 0x0000, 0x0300, 0x0303, 0x0303, 0x0000, 0x0000,
638 /* 0xd0 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
639 /* 0xd8 */ 0x0308, 0x0308, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
640 /* 0xe0 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0302, 0x0302, 0x0301,
641 /* 0xe8 */ 0x0308, 0x0300, 0x0301, 0x0302, 0x0308, 0x0300, 0x0301, 0x0302,
642 /* 0xf0 */ 0x0000, 0x0300, 0x0301, 0x0302, 0x0300, 0x0000, 0x0000, 0x0000,
643 /* 0xf8 */ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
648 * Convert HFS MacRoman encoded string into Unicode
650 * Unicode output is fully decomposed
653 mac_roman_to_unicode(const Str31 hfs_str
, UniChar
*uni_str
,
654 __unused u_int32_t maxCharLen
, u_int32_t
*unicodeChars
)
658 u_int16_t pascalChars
;
664 *unicodeChars
= pascalChars
= *(p
++); /* pick up length byte */
666 while (pascalChars
--) {
669 if ( (int8_t) c
>= 0 ) { /* check if seven bit ascii */
670 *(u
++) = (UniChar
) c
; /* just pad high byte with zero */
671 } else { /* its a hi bit character */
675 *(u
++) = uc
= gHiBitBaseUnicode
[c
];
678 * if the unicode character we get back is an alpha char
679 * then we must have an additional combining character
681 if ((uc
<= (UniChar
) 'z') && (uc
>= (UniChar
) 'A')) {
682 *(u
++) = gHiBitCombUnicode
[c
];
691 #else /* not HFS - temp workaround until 4277828 is fixed */
692 /* stubs for exported routines that aren't present when we build kernel without HFS */
694 #include <sys/types.h>
695 #include <sys/errno.h>
697 int hfs_addconverter(int id
, u_int32_t encoding
, void * get_unicode
, void * get_hfsname
);
698 int hfs_getconverter(u_int32_t encoding
, void *get_unicode
, void *get_hfsname
);
699 int hfs_relconverter(u_int32_t encoding
);
700 int hfs_remconverter(int id
, u_int32_t encoding
);
702 int hfs_addconverter( __unused
int id
,
703 __unused u_int32_t encoding
,
704 __unused
void * get_unicode
,
705 __unused
void * get_hfsname
)
710 int hfs_getconverter(__unused u_int32_t encoding
, __unused
void *get_unicode
, __unused
void *get_hfsname
)
715 int hfs_relconverter(__unused u_int32_t encoding
)
720 int hfs_remconverter(__unused
int id
, __unused u_int32_t encoding
)