xref: /linux-6.15/include/linux/unicode.h (revision 6ca99ce7)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_UNICODE_H
3 #define _LINUX_UNICODE_H
4 
5 #include <linux/init.h>
6 #include <linux/dcache.h>
7 
8 struct utf8data;
9 
10 #define UNICODE_MAJ_SHIFT		16
11 #define UNICODE_MIN_SHIFT		8
12 
13 #define UNICODE_AGE(MAJ, MIN, REV)			\
14 	(((unsigned int)(MAJ) << UNICODE_MAJ_SHIFT) |	\
15 	 ((unsigned int)(MIN) << UNICODE_MIN_SHIFT) |	\
16 	 ((unsigned int)(REV)))
17 
18 static inline u8 unicode_major(unsigned int age)
19 {
20 	return (age >> UNICODE_MAJ_SHIFT) & 0xff;
21 }
22 
23 static inline u8 unicode_minor(unsigned int age)
24 {
25 	return (age >> UNICODE_MIN_SHIFT) & 0xff;
26 }
27 
28 static inline u8 unicode_rev(unsigned int age)
29 {
30 	return age & 0xff;
31 }
32 
33 /*
34  * Two normalization forms are supported:
35  * 1) NFDI
36  *   - Apply unicode normalization form NFD.
37  *   - Remove any Default_Ignorable_Code_Point.
38  * 2) NFDICF
39  *   - Apply unicode normalization form NFD.
40  *   - Remove any Default_Ignorable_Code_Point.
41  *   - Apply a full casefold (C + F).
42  */
43 enum utf8_normalization {
44 	UTF8_NFDI = 0,
45 	UTF8_NFDICF,
46 	UTF8_NMAX,
47 };
48 
49 struct unicode_map {
50 	unsigned int version;
51 	const struct utf8data *ntab[UTF8_NMAX];
52 };
53 
54 int utf8_validate(const struct unicode_map *um, const struct qstr *str);
55 
56 int utf8_strncmp(const struct unicode_map *um,
57 		 const struct qstr *s1, const struct qstr *s2);
58 
59 int utf8_strncasecmp(const struct unicode_map *um,
60 		 const struct qstr *s1, const struct qstr *s2);
61 int utf8_strncasecmp_folded(const struct unicode_map *um,
62 			    const struct qstr *cf,
63 			    const struct qstr *s1);
64 
65 int utf8_normalize(const struct unicode_map *um, const struct qstr *str,
66 		   unsigned char *dest, size_t dlen);
67 
68 int utf8_casefold(const struct unicode_map *um, const struct qstr *str,
69 		  unsigned char *dest, size_t dlen);
70 
71 int utf8_casefold_hash(const struct unicode_map *um, const void *salt,
72 		       struct qstr *str);
73 
74 struct unicode_map *utf8_load(unsigned int version);
75 void utf8_unload(struct unicode_map *um);
76 
77 #endif /* _LINUX_UNICODE_H */
78