2 * Copyright (c) International Business Machines Corp., 2000-2002
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12 * the GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/slab.h>
21 #include "jfs_types.h"
22 #include "jfs_filsys.h"
23 #include "jfs_unicode.h"
24 #include "jfs_debug.h"
27 * NAME: jfs_strfromUCS()
29 * FUNCTION: Convert little-endian unicode string to character string
32 int jfs_strfromUCS_le(char *to, const wchar_t * from, /* LITTLE ENDIAN */
33 int len, struct nls_table *codepage)
38 for (i = 0; (i < len) && from[i]; i++) {
41 codepage->uni2char(le16_to_cpu(from[i]), &to[outlen],
42 NLS_MAX_CHARSET_SIZE);
50 jEVENT(0, ("jfs_strfromUCS returning %d - '%s'\n", outlen, to));
55 * NAME: jfs_strtoUCS()
57 * FUNCTION: Convert character string to unicode string
60 int jfs_strtoUCS(wchar_t * to,
61 const char *from, int len, struct nls_table *codepage)
66 jEVENT(0, ("jfs_strtoUCS - '%s'\n", from));
68 for (i = 0; len && *from; i++, from += charlen, len -= charlen) {
69 charlen = codepage->char2uni(from, len, &to[i]);
71 jERROR(1, ("jfs_strtoUCS: char2uni returned %d.\n",
73 jERROR(1, ("charset = %s, char = 0x%x\n",
74 codepage->charset, (unsigned char) *from));
75 to[i] = 0x003f; /* a question mark */
80 jEVENT(0, (" returning %d\n", i));
89 * FUNCTION: Allocate and translate to unicode string
92 int get_UCSname(struct component_name * uniName, struct dentry *dentry,
93 struct nls_table *nls_tab)
95 int length = dentry->d_name.len;
97 if (length > JFS_NAME_MAX)
101 kmalloc((length + 1) * sizeof(wchar_t), GFP_NOFS);
103 if (uniName->name == NULL)
106 uniName->namlen = jfs_strtoUCS(uniName->name, dentry->d_name.name,