2 * linux/fs/isofs/joliet.c
4 * (C) 1996 Gordon Chaffee
6 * Joliet: Microsoft's Unicode extensions to iso9660
9 #include <linux/string.h>
10 #include <linux/nls.h>
12 #include <linux/iso_fs.h>
13 #include <asm/unaligned.h>
16 * Convert Unicode 16 to UTF8 or ASCII.
19 uni16_to_x8(unsigned char *ascii, u16 *uni, int len, struct nls_table *nls)
27 while ((ch = get_unaligned(ip)) && len) {
30 if ((llen = nls->uni2char(ch, op, NLS_MAX_CHARSET_SIZE)) > 0)
42 /* Convert big endian wide character string to utf8 */
44 wcsntombs_be(__u8 *s, const __u8 *pwcs, int inlen, int maxlen)
53 while ((*ip || ip[1]) && (maxlen > 0) && (inlen > 0)) {
54 c = (*ip << 8) | ip[1];
56 size = utf8_wctomb(op, c, maxlen);
58 /* Ignore character and move on */
74 get_joliet_filename(struct iso_directory_record * de, unsigned char *outname, struct inode * inode)
77 struct nls_table *nls;
78 unsigned char len = 0;
80 utf8 = ISOFS_SB(inode->i_sb)->s_utf8;
81 nls = ISOFS_SB(inode->i_sb)->s_nls_iocharset;
84 len = wcsntombs_be(outname, de->name,
85 de->name_len[0] >> 1, PAGE_SIZE);
87 len = uni16_to_x8(outname, (u16 *) de->name,
88 de->name_len[0] >> 1, nls);
90 if ((len > 2) && (outname[len-2] == ';') && (outname[len-1] == '1')) {
95 * Windows doesn't like periods at the end of a name,
98 while (len >= 2 && (outname[len-1] == '.')) {