4 * Copyright (C) 1995-1997 Paul H. Hargrove
5 * This file may be distributed under the terms of the GNU General Public License.
7 * This file contains routines for converting between the Macintosh
8 * character set and various other encodings. This includes dealing
9 * with ':' vs. '/' as the path-element separator.
12 #include <linux/types.h>
13 #include <linux/nls.h>
17 /*================ Global functions ================*/
22 * Given a 'Pascal String' (a string preceded by a length byte) in
23 * the Macintosh character set produce the corresponding filename using
24 * the 'trivial' name-mangling scheme, returning the length of the
25 * mangled filename. Note that the output string is not NULL
28 * The name-mangling works as follows:
29 * The character '/', which is illegal in Linux filenames is replaced
30 * by ':' which never appears in HFS filenames. All other characters
31 * are passed unchanged from input to output.
33 int hfs_mac2asc(struct super_block *sb, char *out, const struct hfs_name *in)
35 struct nls_table *nls_disk = HFS_SB(sb)->nls_disk;
36 struct nls_table *nls_io = HFS_SB(sb)->nls_io;
39 int srclen, dstlen, size;
44 dstlen = HFS_MAX_NAMELEN;
50 size = nls_disk->char2uni(src, srclen, &ch);
63 size = nls_io->uni2char(ch, dst, dstlen);
65 if (size == -ENAMETOOLONG)
77 *dst++ = (ch = *src++) == '/' ? ':' : ch;
86 * Given an ASCII string (not null-terminated) and its length,
87 * generate the corresponding filename in the Macintosh character set
88 * using the 'trivial' name-mangling scheme, returning the length of
89 * the mangled filename. Note that the output string is not NULL
92 * This routine is a inverse to hfs_mac2triv().
93 * A ':' is replaced by a '/'.
95 void hfs_asc2mac(struct super_block *sb, struct hfs_name *out, struct qstr *in)
97 struct nls_table *nls_disk = HFS_SB(sb)->nls_disk;
98 struct nls_table *nls_io = HFS_SB(sb)->nls_io;
101 int srclen, dstlen, size;
106 dstlen = HFS_NAMELEN;
111 size = nls_io->char2uni(src, srclen, &ch);
121 size = nls_disk->uni2char(ch, dst, dstlen);
123 if (size == -ENAMETOOLONG)
131 *dst++ = ch > 0xff ? '?' : ch;
140 while (--dstlen >= 0)
141 *dst++ = (ch = *src++) == ':' ? '/' : ch;
144 out->len = dst - (char *)out->name;
145 dstlen = HFS_NAMELEN - out->len;
146 while (--dstlen >= 0)