1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) International Business Machines Corp., 2000-2004
7 #include <linux/slab.h>
8 #include "jfs_incore.h"
9 #include "jfs_filsys.h"
10 #include "jfs_unicode.h"
11 #include "jfs_debug.h"
14 * NAME: jfs_strfromUCS()
16 * FUNCTION: Convert little-endian unicode string to character string
19 int jfs_strfromUCS_le(char *to
, const __le16
* from
,
20 int len
, struct nls_table
*codepage
)
24 static int warn_again
= 5; /* Only warn up to 5 times total */
25 int warn
= !!warn_again
; /* once per string */
28 for (i
= 0; (i
< len
) && from
[i
]; i
++) {
31 codepage
->uni2char(le16_to_cpu(from
[i
]),
33 NLS_MAX_CHARSET_SIZE
);
40 for (i
= 0; (i
< len
) && from
[i
]; i
++) {
41 if (unlikely(le16_to_cpu(from
[i
]) & 0xff00)) {
47 "non-latin1 character 0x%x found in JFS file name\n",
48 le16_to_cpu(from
[i
]));
50 "mount with iocharset=utf8 to access\n");
55 to
[i
] = (char) (le16_to_cpu(from
[i
]));
64 * NAME: jfs_strtoUCS()
66 * FUNCTION: Convert character string to unicode string
69 static int jfs_strtoUCS(wchar_t * to
, const unsigned char *from
, int len
,
70 struct nls_table
*codepage
)
76 for (i
= 0; len
&& *from
; i
++, from
+= charlen
, len
-= charlen
)
78 charlen
= codepage
->char2uni(from
, len
, &to
[i
]);
80 jfs_err("jfs_strtoUCS: char2uni returned %d.",
82 jfs_err("charset = %s, char = 0x%x",
83 codepage
->charset
, *from
);
88 for (i
= 0; (i
< len
) && from
[i
]; i
++)
89 to
[i
] = (wchar_t) from
[i
];
99 * FUNCTION: Allocate and translate to unicode string
102 int get_UCSname(struct component_name
* uniName
, struct dentry
*dentry
)
104 struct nls_table
*nls_tab
= JFS_SBI(dentry
->d_sb
)->nls_tab
;
105 int length
= dentry
->d_name
.len
;
107 if (length
> JFS_NAME_MAX
)
108 return -ENAMETOOLONG
;
111 kmalloc_array(length
+ 1, sizeof(wchar_t), GFP_NOFS
);
113 if (uniName
->name
== NULL
)
116 uniName
->namlen
= jfs_strtoUCS(uniName
->name
, dentry
->d_name
.name
,
119 if (uniName
->namlen
< 0) {
120 kfree(uniName
->name
);
121 return uniName
->namlen
;