This patch fixes q->unplug_thresh condition check in
[linux-2.6/openmoko-kernel/knife-kernel.git] / fs / hfs / trans.c
blobfb9720abbadd64ff572f58b4533302247347e50c
1 /*
2 * linux/fs/hfs/trans.c
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 "hfs_fs.h"
14 /*================ Global functions ================*/
17 * hfs_mac2triv()
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.
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.
30 int hfs_mac2triv(char *out, const struct hfs_name *in)
32 const char *p;
33 char c;
34 int i, len;
36 len = in->len;
37 p = in->name;
38 for (i = 0; i < len; i++) {
39 c = *p++;
40 *out++ = c == '/' ? ':' : c;
42 return i;
46 * hfs_triv2mac()
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.
54 * This routine is a inverse to hfs_mac2triv().
55 * A ':' is replaced by a '/'.
57 void hfs_triv2mac(struct hfs_name *out, struct qstr *in)
59 const char *src;
60 char *dst, c;
61 int i, len;
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;
70 for (; i < HFS_NAMELEN; i++)
71 *dst++ = 0;