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