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

TOMOYO Linux Cross Reference
Linux/fs/jfs/jfs_unicode.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  *   Copyright (C) International Business Machines Corp., 2000-2004
  4  */
  5 
  6 #include <linux/fs.h>
  7 #include <linux/slab.h>
  8 #include "jfs_incore.h"
  9 #include "jfs_filsys.h"
 10 #include "jfs_unicode.h"
 11 #include "jfs_debug.h"
 12 
 13 /*
 14  * NAME:        jfs_strfromUCS()
 15  *
 16  * FUNCTION:    Convert little-endian unicode string to character string
 17  *
 18  */
 19 int jfs_strfromUCS_le(char *to, const __le16 * from,
 20                       int len, struct nls_table *codepage)
 21 {
 22         int i;
 23         int outlen = 0;
 24         static int warn_again = 5;      /* Only warn up to 5 times total */
 25         int warn = !!warn_again;        /* once per string */
 26 
 27         if (codepage) {
 28                 for (i = 0; (i < len) && from[i]; i++) {
 29                         int charlen;
 30                         charlen =
 31                             codepage->uni2char(le16_to_cpu(from[i]),
 32                                                &to[outlen],
 33                                                NLS_MAX_CHARSET_SIZE);
 34                         if (charlen > 0)
 35                                 outlen += charlen;
 36                         else
 37                                 to[outlen++] = '?';
 38                 }
 39         } else {
 40                 for (i = 0; (i < len) && from[i]; i++) {
 41                         if (unlikely(le16_to_cpu(from[i]) & 0xff00)) {
 42                                 to[i] = '?';
 43                                 if (unlikely(warn)) {
 44                                         warn--;
 45                                         warn_again--;
 46                                         printk(KERN_ERR
 47                         "non-latin1 character 0x%x found in JFS file name\n",
 48                                                le16_to_cpu(from[i]));
 49                                         printk(KERN_ERR
 50                                 "mount with iocharset=utf8 to access\n");
 51                                 }
 52 
 53                         }
 54                         else
 55                                 to[i] = (char) (le16_to_cpu(from[i]));
 56                 }
 57                 outlen = i;
 58         }
 59         to[outlen] = 0;
 60         return outlen;
 61 }
 62 
 63 /*
 64  * NAME:        jfs_strtoUCS()
 65  *
 66  * FUNCTION:    Convert character string to unicode string
 67  *
 68  */
 69 static int jfs_strtoUCS(wchar_t * to, const unsigned char *from, int len,
 70                 struct nls_table *codepage)
 71 {
 72         int charlen;
 73         int i;
 74 
 75         if (codepage) {
 76                 for (i = 0; len && *from; i++, from += charlen, len -= charlen)
 77                 {
 78                         charlen = codepage->char2uni(from, len, &to[i]);
 79                         if (charlen < 1) {
 80                                 jfs_err("jfs_strtoUCS: char2uni returned %d.",
 81                                         charlen);
 82                                 jfs_err("charset = %s, char = 0x%x",
 83                                         codepage->charset, *from);
 84                                 return charlen;
 85                         }
 86                 }
 87         } else {
 88                 for (i = 0; (i < len) && from[i]; i++)
 89                         to[i] = (wchar_t) from[i];
 90         }
 91 
 92         to[i] = 0;
 93         return i;
 94 }
 95 
 96 /*
 97  * NAME:        get_UCSname()
 98  *
 99  * FUNCTION:    Allocate and translate to unicode string
100  *
101  */
102 int get_UCSname(struct component_name * uniName, struct dentry *dentry)
103 {
104         struct nls_table *nls_tab = JFS_SBI(dentry->d_sb)->nls_tab;
105         int length = dentry->d_name.len;
106 
107         if (length > JFS_NAME_MAX)
108                 return -ENAMETOOLONG;
109 
110         uniName->name =
111             kmalloc_array(length + 1, sizeof(wchar_t), GFP_NOFS);
112 
113         if (uniName->name == NULL)
114                 return -ENOMEM;
115 
116         uniName->namlen = jfs_strtoUCS(uniName->name, dentry->d_name.name,
117                                        length, nls_tab);
118 
119         if (uniName->namlen < 0) {
120                 kfree(uniName->name);
121                 return uniName->namlen;
122         }
123 
124         return 0;
125 }
126 

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

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php