Blame view
fs/isofs/joliet.c
1.33 KB
1da177e4c
|
1 2 3 4 5 6 7 |
/* * linux/fs/isofs/joliet.c * * (C) 1996 Gordon Chaffee * * Joliet: Microsoft's Unicode extensions to iso9660 */ |
94f2f7157
|
8 |
#include <linux/types.h> |
1da177e4c
|
9 |
#include <linux/nls.h> |
94f2f7157
|
10 |
#include "isofs.h" |
1da177e4c
|
11 12 |
/* |
4de151d8c
|
13 |
* Convert Unicode 16 to UTF-8 or ASCII. |
1da177e4c
|
14 15 |
*/ static int |
d02d48d86
|
16 |
uni16_to_x8(unsigned char *ascii, __be16 *uni, int len, struct nls_table *nls) |
1da177e4c
|
17 |
{ |
d02d48d86
|
18 |
__be16 *ip, ch; |
1da177e4c
|
19 20 21 22 23 24 25 |
unsigned char *op; ip = uni; op = ascii; while ((ch = get_unaligned(ip)) && len) { int llen; |
d02d48d86
|
26 27 |
llen = nls->uni2char(be16_to_cpu(ch), op, NLS_MAX_CHARSET_SIZE); if (llen > 0) |
1da177e4c
|
28 29 30 31 32 33 34 35 36 37 |
op += llen; else *op++ = '?'; ip++; len--; } *op = 0; return (op - ascii); } |
1da177e4c
|
38 39 40 41 42 43 44 45 46 47 48 |
int get_joliet_filename(struct iso_directory_record * de, unsigned char *outname, struct inode * inode) { unsigned char utf8; struct nls_table *nls; unsigned char len = 0; utf8 = ISOFS_SB(inode->i_sb)->s_utf8; nls = ISOFS_SB(inode->i_sb)->s_nls_iocharset; if (utf8) { |
74675a585
|
49 50 51 |
len = utf16s_to_utf8s((const wchar_t *) de->name, de->name_len[0] >> 1, UTF16_BIG_ENDIAN, outname, PAGE_SIZE); |
1da177e4c
|
52 |
} else { |
d02d48d86
|
53 |
len = uni16_to_x8(outname, (__be16 *) de->name, |
c3ed85a36
|
54 |
de->name_len[0] >> 1, nls); |
1da177e4c
|
55 |
} |
c3ed85a36
|
56 |
if ((len > 2) && (outname[len-2] == ';') && (outname[len-1] == '1')) |
1da177e4c
|
57 |
len -= 2; |
1da177e4c
|
58 59 60 61 62 |
/* * Windows doesn't like periods at the end of a name, * so neither do we */ |
c3ed85a36
|
63 |
while (len >= 2 && (outname[len-1] == '.')) |
1da177e4c
|
64 |
len--; |
1da177e4c
|
65 66 67 |
return len; } |