blob: fb9720abbadd64ff572f58b4533302247347e50c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/hfs/trans.c
3 *
4 * Copyright (C) 1995-1997 Paul H. Hargrove
5 * This file may be distributed under the terms of the GNU General Public License.
6 *
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.
10 */
11
12#include "hfs_fs.h"
13
14/*================ Global functions ================*/
15
16/*
17 * hfs_mac2triv()
18 *
19 * Given a 'Pascal String' (a string preceded by a length byte) in
20 * the Macintosh character set produce the corresponding filename using
21 * the 'trivial' name-mangling scheme, returning the length of the
22 * mangled filename. Note that the output string is not NULL
23 * terminated.
24 *
25 * The name-mangling works as follows:
26 * The character '/', which is illegal in Linux filenames is replaced
27 * by ':' which never appears in HFS filenames. All other characters
28 * are passed unchanged from input to output.
29 */
30int hfs_mac2triv(char *out, const struct hfs_name *in)
31{
32 const char *p;
33 char c;
34 int i, len;
35
36 len = in->len;
37 p = in->name;
38 for (i = 0; i < len; i++) {
39 c = *p++;
40 *out++ = c == '/' ? ':' : c;
41 }
42 return i;
43}
44
45/*
46 * hfs_triv2mac()
47 *
48 * Given an ASCII string (not null-terminated) and its length,
49 * generate the corresponding filename in the Macintosh character set
50 * using the 'trivial' name-mangling scheme, returning the length of
51 * the mangled filename. Note that the output string is not NULL
52 * terminated.
53 *
54 * This routine is a inverse to hfs_mac2triv().
55 * A ':' is replaced by a '/'.
56 */
57void hfs_triv2mac(struct hfs_name *out, struct qstr *in)
58{
59 const char *src;
60 char *dst, c;
61 int i, len;
62
63 out->len = len = min((unsigned int)HFS_NAMELEN, in->len);
64 src = in->name;
65 dst = out->name;
66 for (i = 0; i < len; i++) {
67 c = *src++;
68 *dst++ = c == ':' ? '/' : c;
69 }
70 for (; i < HFS_NAMELEN; i++)
71 *dst++ = 0;
72}