2 * Copyright (C) International Business Machines Corp., 2000-2004
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_incore.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 __le16
* from
,
33 int len
, struct nls_table
*codepage
)
37 static int warn_again
= 5; /* Only warn up to 5 times total */
38 int warn
= !!warn_again
; /* once per string */
41 for (i
= 0; (i
< len
) && from
[i
]; i
++) {
44 codepage
->uni2char(le16_to_cpu(from
[i
]),
46 NLS_MAX_CHARSET_SIZE
);
53 for (i
= 0; (i
< len
) && from
[i
]; i
++) {
54 if (unlikely(le16_to_cpu(from
[i
]) & 0xff00)) {
60 "non-latin1 character 0x%x found in JFS file name\n",
61 le16_to_cpu(from
[i
]));
63 "mount with iocharset=utf8 to access\n");
68 to
[i
] = (char) (le16_to_cpu(from
[i
]));
77 * NAME: jfs_strtoUCS()
79 * FUNCTION: Convert character string to unicode string
82 static int jfs_strtoUCS(wchar_t * to
, const unsigned char *from
, int len
,
83 struct nls_table
*codepage
)
89 for (i
= 0; len
&& *from
; i
++, from
+= charlen
, len
-= charlen
)
91 charlen
= codepage
->char2uni(from
, len
, &to
[i
]);
93 jfs_err("jfs_strtoUCS: char2uni returned %d.",
95 jfs_err("charset = %s, char = 0x%x",
96 codepage
->charset
, *from
);
101 for (i
= 0; (i
< len
) && from
[i
]; i
++)
102 to
[i
] = (wchar_t) from
[i
];
110 * NAME: get_UCSname()
112 * FUNCTION: Allocate and translate to unicode string
115 int get_UCSname(struct component_name
* uniName
, struct dentry
*dentry
)
117 struct nls_table
*nls_tab
= JFS_SBI(dentry
->d_sb
)->nls_tab
;
118 int length
= dentry
->d_name
.len
;
120 if (length
> JFS_NAME_MAX
)
121 return -ENAMETOOLONG
;
124 kmalloc((length
+ 1) * sizeof(wchar_t), GFP_NOFS
);
126 if (uniName
->name
== NULL
)
129 uniName
->namlen
= jfs_strtoUCS(uniName
->name
, dentry
->d_name
.name
,
132 if (uniName
->namlen
< 0) {
133 kfree(uniName
->name
);
134 return uniName
->namlen
;
This page took 0.033553 seconds and 5 git commands to generate.