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