~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/fs/isofs/joliet.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  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, u16 *uni, int len, struct nls_table *nls)
 19 {
 20         wchar_t *ip;
 21         unsigned char *op;
 22 
 23         ip = uni;
 24         op = ascii;
 25 
 26         while (*ip && len) {
 27                 int llen;
 28                 wchar_t ch = be16_to_cpu(*ip);
 29                 if ((llen = nls->uni2char(ch, op, NLS_MAX_CHARSET_SIZE)) > 0)
 30                         op += llen;
 31                 else
 32                         *op++ = '?';
 33                 ip++;
 34 
 35                 len--;
 36         }
 37         *op = 0;
 38         return (op - ascii);
 39 }
 40 
 41 /* Convert big endian wide character string to utf8 */
 42 static int
 43 wcsntombs_be(__u8 *s, const __u8 *pwcs, int inlen, int maxlen)
 44 {
 45         const __u8 *ip;
 46         __u8 *op;
 47         int size;
 48         __u16 c;
 49 
 50         op = s;
 51         ip = pwcs;
 52         while ((*ip || ip[1]) && (maxlen > 0) && (inlen > 0)) {
 53                 c = (*ip << 8) | ip[1];
 54                 if (c > 0x7f) {
 55                         size = utf8_wctomb(op, c, maxlen);
 56                         if (size == -1) {
 57                                 /* Ignore character and move on */
 58                                 maxlen--;
 59                         } else {
 60                                 op += size;
 61                                 maxlen -= size;
 62                         }
 63                 } else {
 64                         *op++ = (__u8) c;
 65                 }
 66                 ip += 2;
 67                 inlen--;
 68         }
 69         return (op - s);
 70 }
 71 
 72 int
 73 get_joliet_filename(struct iso_directory_record * de, unsigned char *outname, struct inode * inode)
 74 {
 75         unsigned char utf8;
 76         struct nls_table *nls;
 77         unsigned char len = 0;
 78 
 79         utf8 = inode->i_sb->u.isofs_sb.s_utf8;
 80         nls = inode->i_sb->u.isofs_sb.s_nls_iocharset;
 81 
 82         if (utf8) {
 83                 len = wcsntombs_be(outname, de->name,
 84                                    de->name_len[0] >> 1, PAGE_SIZE);
 85         } else {
 86                 len = uni16_to_x8(outname, (u16 *) de->name,
 87                                   de->name_len[0] >> 1, nls);
 88         }
 89         if ((len > 2) && (outname[len-2] == ';') && (outname[len-1] == '1')) {
 90                 len -= 2;
 91         }
 92 
 93         /*
 94          * Windows doesn't like periods at the end of a name,
 95          * so neither do we
 96          */
 97         while (len >= 2 && (outname[len-1] == '.')) {
 98                 len--;
 99         }
100 
101         return len;
102 }
103 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.