Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  *  linux/fs/isofs/joliet.c
0004  *
0005  *  (C) 1996 Gordon Chaffee
0006  *
0007  *  Joliet: Microsoft's Unicode extensions to iso9660
0008  */
0009 
0010 #include <linux/types.h>
0011 #include <linux/nls.h>
0012 #include "isofs.h"
0013 
0014 /*
0015  * Convert Unicode 16 to UTF-8 or ASCII.
0016  */
0017 static int
0018 uni16_to_x8(unsigned char *ascii, __be16 *uni, int len, struct nls_table *nls)
0019 {
0020     __be16 *ip, ch;
0021     unsigned char *op;
0022 
0023     ip = uni;
0024     op = ascii;
0025 
0026     while ((ch = get_unaligned(ip)) && len) {
0027         int llen;
0028         llen = nls->uni2char(be16_to_cpu(ch), op, NLS_MAX_CHARSET_SIZE);
0029         if (llen > 0)
0030             op += llen;
0031         else
0032             *op++ = '?';
0033         ip++;
0034 
0035         len--;
0036     }
0037     *op = 0;
0038     return (op - ascii);
0039 }
0040 
0041 int
0042 get_joliet_filename(struct iso_directory_record * de, unsigned char *outname, struct inode * inode)
0043 {
0044     struct nls_table *nls;
0045     unsigned char len = 0;
0046 
0047     nls = ISOFS_SB(inode->i_sb)->s_nls_iocharset;
0048 
0049     if (!nls) {
0050         len = utf16s_to_utf8s((const wchar_t *) de->name,
0051                 de->name_len[0] >> 1, UTF16_BIG_ENDIAN,
0052                 outname, PAGE_SIZE);
0053     } else {
0054         len = uni16_to_x8(outname, (__be16 *) de->name,
0055                 de->name_len[0] >> 1, nls);
0056     }
0057     if ((len > 2) && (outname[len-2] == ';') && (outname[len-1] == '1'))
0058         len -= 2;
0059 
0060     /*
0061      * Windows doesn't like periods at the end of a name,
0062      * so neither do we
0063      */
0064     while (len >= 2 && (outname[len-1] == '.'))
0065         len--;
0066 
0067     return len;
0068 }