2 * linux/fs/isofs/joliet.c
4 * (C) 1996 Gordon Chaffee
6 * Joliet: Microsoft's Unicode extensions to iso9660
9 #include <linux/types.h>
10 #include <linux/nls.h>
14 * Convert Unicode 16 to UTF8 or ASCII.
17 uni16_to_x8(unsigned char *ascii, u16 *uni, int len, struct nls_table *nls)
25 while ((ch = get_unaligned(ip)) && len) {
28 if ((llen = nls->uni2char(ch, op, NLS_MAX_CHARSET_SIZE)) > 0)
40 /* Convert big endian wide character string to utf8 */
42 wcsntombs_be(__u8 *s, const __u8 *pwcs, int inlen, int maxlen)
51 while ((*ip || ip[1]) && (maxlen > 0) && (inlen > 0)) {
52 c = (*ip << 8) | ip[1];
54 size = utf8_wctomb(op, c, maxlen);
56 /* Ignore character and move on */
72 get_joliet_filename(struct iso_directory_record * de, unsigned char *outname, struct inode * inode)
75 struct nls_table *nls;
76 unsigned char len = 0;
78 utf8 = ISOFS_SB(inode->i_sb)->s_utf8;
79 nls = ISOFS_SB(inode->i_sb)->s_nls_iocharset;
82 len = wcsntombs_be(outname, de->name,
83 de->name_len[0] >> 1, PAGE_SIZE);
85 len = uni16_to_x8(outname, (u16 *) de->name,
86 de->name_len[0] >> 1, nls);
88 if ((len > 2) && (outname[len-2] == ';') && (outname[len-1] == '1')) {
93 * Windows doesn't like periods at the end of a name,
96 while (len >= 2 && (outname[len-1] == '.')) {