OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [fs/] [isofs/] [joliet.c] - Blame information for rev 1775

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1628 jcastillo
/*
2
 *  linux/fs/isofs/joliet.c
3
 *
4
 *  (C) 1996 Gordon Chaffee
5
 *
6
 *  Joliet: Microsoft's Unicode extensions to iso9660
7
 */
8
 
9
#include <linux/string.h>
10
#include <linux/nls.h>
11
#include <linux/malloc.h>
12
#include <linux/iso_fs.h>
13
 
14
/*
15
 * Convert Unicode 16 to UTF8 or ascii.
16
 */
17
static int
18
uni16_to_x8(unsigned char *ascii, unsigned char *uni, int len,
19
            struct nls_table *nls)
20
{
21
        unsigned char *ip, *op;
22
        unsigned char ch, cl;
23
        unsigned char *uni_page;
24
 
25
        ip = uni;
26
        op = ascii;
27
 
28
        while ((*ip || ip[1]) && len) {
29
                ch = *ip++;
30
                cl = *ip++;
31
 
32
                uni_page = nls->page_uni2charset[ch];
33
                if (uni_page && uni_page[cl]) {
34
                        *op++ = uni_page[cl];
35
                } else {
36
                        *op++ = '?';
37
                }
38
                len--;
39
        }
40
        *op = 0;
41
        return (op - ascii);
42
}
43
 
44
/* Convert big endian wide character string to utf8 */
45
static int
46
wcsntombs_be(__u8 *s, const __u8 *pwcs, int inlen, int maxlen)
47
{
48
        const __u8 *ip;
49
        __u8 *op;
50
        int size;
51
        __u16 c;
52
 
53
        op = s;
54
        ip = pwcs;
55
        while ((*ip || ip[1]) && (maxlen > 0) && (inlen > 0)) {
56
                c = (*ip << 8) | ip[1];
57
                if (c > 0x7f) {
58
                        size = utf8_wctomb(op, c, maxlen);
59
                        if (size == -1) {
60
                                /* Ignore character and move on */
61
                                maxlen--;
62
                        } else {
63
                                op += size;
64
                                maxlen -= size;
65
                        }
66
                } else {
67
                        *op++ = (__u8) c;
68
                }
69
                ip += 2;
70
                inlen--;
71
        }
72
        return (op - s);
73
}
74
 
75
int
76
get_joliet_filename(struct iso_directory_record * de, struct inode * inode,
77
                    unsigned char *outname)
78
{
79
        unsigned char utf8;
80
        struct nls_table *nls;
81
        unsigned char len = 0;
82
        int i;
83
        char c;
84
 
85
        utf8 = inode->i_sb->u.isofs_sb.s_utf8;
86
        nls = inode->i_sb->u.isofs_sb.s_nls_iocharset;
87
 
88
        if (utf8) {
89
                len = wcsntombs_be(outname, de->name,
90
                                   de->name_len[0] >> 1, PAGE_SIZE);
91
        } else {
92
                len = uni16_to_x8(outname, de->name,
93
                                  de->name_len[0] >> 1, nls);
94
        }
95
        if ((len > 2) && (outname[len-2] == ';') && (outname[len-1] == '1')) {
96
                len -= 2;
97
        }
98
 
99
        /*
100
         * Windows doesn't like periods at the end of a name
101
         */
102
        while (len >= 2 && (outname[len-1] == '.')) {
103
                len--;
104
        }
105
 
106
        if (inode->i_sb->u.isofs_sb.s_name_check == 'r') {
107
               for (i = 0; i < len; i++) {
108
                       c = outname[i];
109
                       /* lower case */
110
                       if (c >= 'A' && c <= 'Z') c |= 0x20;
111
                       if (c == ';') c = '.';
112
                       outname[i] = c;
113
               }
114
        }
115
 
116
        return len;
117
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.