1 // SPDX-License-Identifier: GPL-2.0-or-later 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 2 /* 3 * Some of the source code in this file came 3 * Some of the source code in this file came from fs/cifs/uniupr.h 4 * Copyright (c) International Business Mach 4 * Copyright (c) International Business Machines Corp., 2000,2002 5 * 5 * 6 * Some of the source code in this file came 6 * Some of the source code in this file came from fs/cifs/cifs_unicode.c 7 * 7 * 8 * Copyright (c) International Business Mach 8 * Copyright (c) International Business Machines Corp., 2000,2009 9 * Modified by Steve French (sfrench@us.ibm. 9 * Modified by Steve French (sfrench@us.ibm.com) 10 * Modified by Namjae Jeon (linkinjeon@kerne 10 * Modified by Namjae Jeon (linkinjeon@kernel.org) 11 * 11 * 12 */ 12 */ 13 #include <linux/fs.h> 13 #include <linux/fs.h> 14 #include <linux/module.h> 14 #include <linux/module.h> 15 #include <linux/slab.h> 15 #include <linux/slab.h> 16 #include <linux/unaligned.h> 16 #include <linux/unaligned.h> 17 #include "nls_ucs2_utils.h" 17 #include "nls_ucs2_utils.h" 18 18 19 MODULE_DESCRIPTION("NLS UCS-2"); 19 MODULE_DESCRIPTION("NLS UCS-2"); 20 MODULE_LICENSE("GPL"); 20 MODULE_LICENSE("GPL"); 21 21 22 /* 22 /* 23 * Latin upper case 23 * Latin upper case 24 */ 24 */ 25 signed char NlsUniUpperTable[512] = { 25 signed char NlsUniUpperTable[512] = { 26 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 000-00f */ 27 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 010-01f */ 28 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 020-02f */ 29 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 030-03f */ 30 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 040-04f */ 31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 050-05f */ 32 0, -32, -32, -32, -32, -32, -32, -32, 32 0, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 33 -32, -32, -32, 33 -32, -32, -32, -32, -32, /* 060-06f */ 34 -32, -32, -32, -32, -32, -32, -32, -32 34 -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 35 -32, 0, 0, 0, 35 -32, 0, 0, 0, 0, 0, /* 070-07f */ 36 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 080-08f */ 37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 090-09f */ 38 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0a0-0af */ 39 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0b0-0bf */ 40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0c0-0cf */ 41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0d0-0df */ 42 -32, -32, -32, -32, -32, -32, -32, -32 42 -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 43 -32, -32, -32, -32, - 43 -32, -32, -32, -32, -32, -32, /* 0e0-0ef */ 44 -32, -32, -32, -32, -32, -32, -32, 0, 44 -32, -32, -32, -32, -32, -32, -32, 0, -32, -32, 45 -32, -32, -32, -32, - 45 -32, -32, -32, -32, -32, 121, /* 0f0-0ff */ 46 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 46 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 100-10f */ 47 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 47 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 110-11f */ 48 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 48 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 120-12f */ 49 0, 0, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0 49 0, 0, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1, 0, -1, 0, /* 130-13f */ 50 -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 0, 50 -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1, 0, -1, /* 140-14f */ 51 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 51 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 150-15f */ 52 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 52 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 160-16f */ 53 0, -1, 0, -1, 0, -1, 0, -1, 0, 0, -1, 53 0, -1, 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, -1, 0, -1, 0, /* 170-17f */ 54 0, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, 54 0, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, /* 180-18f */ 55 0, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 55 0, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, /* 190-19f */ 56 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0 56 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, /* 1a0-1af */ 57 -1, 0, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0 57 -1, 0, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, -1, 0, 0, /* 1b0-1bf */ 58 0, 0, 0, 0, 0, -1, -2, 0, -1, -2, 0, - 58 0, 0, 0, 0, 0, -1, -2, 0, -1, -2, 0, -1, -2, 0, -1, 0, /* 1c0-1cf */ 59 -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 59 -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -79, 0, -1, /* 1d0-1df */ 60 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 60 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e0-1ef */ 61 0, 0, -1, -2, 0, -1, 0, 0, 0, -1, 0, - 61 0, 0, -1, -2, 0, -1, 0, 0, 0, -1, 0, -1, 0, -1, 0, -1, /* 1f0-1ff */ 62 }; 62 }; 63 EXPORT_SYMBOL_GPL(NlsUniUpperTable); 63 EXPORT_SYMBOL_GPL(NlsUniUpperTable); 64 64 65 /* Upper case range - Greek */ 65 /* Upper case range - Greek */ 66 static signed char UniCaseRangeU03a0[47] = { 66 static signed char UniCaseRangeU03a0[47] = { 67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -3 67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -38, -37, -37, -37, /* 3a0-3af */ 68 0, -32, -32, -32, -32, -32, -32, -32, 68 0, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 69 -32, 69 -32, -32, -32, -32, /* 3b0-3bf */ 70 -32, -32, -31, -32, -32, -32, -32, -32 70 -32, -32, -31, -32, -32, -32, -32, -32, -32, -32, -32, -32, -64, 71 -63, -63, 71 -63, -63, 72 }; 72 }; 73 73 74 /* Upper case range - Cyrillic */ 74 /* Upper case range - Cyrillic */ 75 static signed char UniCaseRangeU0430[48] = { 75 static signed char UniCaseRangeU0430[48] = { 76 -32, -32, -32, -32, -32, -32, -32, -32 76 -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 77 -32, 77 -32, -32, -32, -32, /* 430-43f */ 78 -32, -32, -32, -32, -32, -32, -32, -32 78 -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 79 -32, 79 -32, -32, -32, -32, /* 440-44f */ 80 0, -80, -80, -80, -80, -80, -80, -80, 80 0, -80, -80, -80, -80, -80, -80, -80, -80, -80, -80, 81 -80, 81 -80, -80, 0, -80, -80, /* 450-45f */ 82 }; 82 }; 83 83 84 /* Upper case range - Extended cyrillic */ 84 /* Upper case range - Extended cyrillic */ 85 static signed char UniCaseRangeU0490[61] = { 85 static signed char UniCaseRangeU0490[61] = { 86 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 86 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 490-49f */ 87 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 87 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 4a0-4af */ 88 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 88 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 4b0-4bf */ 89 0, 0, -1, 0, -1, 0, 0, 0, -1, 0, 0, 0, 89 0, 0, -1, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 90 }; 90 }; 91 91 92 /* Upper case range - Extended latin and greek 92 /* Upper case range - Extended latin and greek */ 93 static signed char UniCaseRangeU1e00[509] = { 93 static signed char UniCaseRangeU1e00[509] = { 94 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 94 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e00-1e0f */ 95 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 95 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e10-1e1f */ 96 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 96 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e20-1e2f */ 97 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 97 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e30-1e3f */ 98 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 98 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e40-1e4f */ 99 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 99 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e50-1e5f */ 100 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 100 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e60-1e6f */ 101 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 101 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e70-1e7f */ 102 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 102 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e80-1e8f */ 103 0, -1, 0, -1, 0, -1, 0, 0, 0, 0, 0, -5 103 0, -1, 0, -1, 0, -1, 0, 0, 0, 0, 0, -59, 0, -1, 0, -1, /* 1e90-1e9f */ 104 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 104 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1ea0-1eaf */ 105 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 105 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1eb0-1ebf */ 106 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 106 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1ec0-1ecf */ 107 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 107 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1ed0-1edf */ 108 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 108 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1ee0-1eef */ 109 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 109 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, 0, 0, 0, 0, 0, /* 1ef0-1eff */ 110 8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 110 8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, /* 1f00-1f0f */ 111 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 111 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1f10-1f1f */ 112 8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 112 8, 8, 8, 8, 8, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, /* 1f20-1f2f */ 113 8, 8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/* 1fc0-1fcf */ 124 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 124 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1fd0-1fdf */ 125 8, 8, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 125 8, 8, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1fe0-1fef */ 126 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 126 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127 }; 127 }; 128 128 129 /* Upper case range - Wide latin */ 129 /* Upper case range - Wide latin */ 130 static signed char UniCaseRangeUff40[27] = { 130 static signed char UniCaseRangeUff40[27] = { 131 0, -32, -32, -32, -32, -32, -32, -32, 131 0, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 132 -32, -32, -32, -32, - 132 -32, -32, -32, -32, -32, /* ff40-ff4f */ 133 -32, -32, -32, -32, -32, -32, -32, -32 133 -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, -32, 134 }; 134 }; 135 135 136 /* 136 /* 137 * Upper Case Range 137 * Upper Case Range 138 */ 138 */ 139 const struct UniCaseRange NlsUniUpperRange[] = 139 const struct UniCaseRange NlsUniUpperRange[] = { 140 {0x03a0, 0x03ce, UniCaseRangeU03a0}, 140 {0x03a0, 0x03ce, UniCaseRangeU03a0}, 141 {0x0430, 0x045f, UniCaseRangeU0430}, 141 {0x0430, 0x045f, UniCaseRangeU0430}, 142 {0x0490, 0x04cc, UniCaseRangeU0490}, 142 {0x0490, 0x04cc, UniCaseRangeU0490}, 143 {0x1e00, 0x1ffc, UniCaseRangeU1e00}, 143 {0x1e00, 0x1ffc, UniCaseRangeU1e00}, 144 {0xff40, 0xff5a, UniCaseRangeUff40}, 144 {0xff40, 0xff5a, UniCaseRangeUff40}, 145 {0} 145 {0} 146 }; 146 }; 147 EXPORT_SYMBOL_GPL(NlsUniUpperRange); 147 EXPORT_SYMBOL_GPL(NlsUniUpperRange); 148 148
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.