xref: /linux/fs/smb/client/cifs_unicode.h (revision 1fd1dc41724319406b0aff221a352a400b0ddfc5)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * cifs_unicode:  Unicode kernel case support
4  *
5  * Function:
6  *     Convert a unicode character to upper or lower case using
7  *     compressed tables.
8  *
9  *   Copyright (c) International Business Machines  Corp., 2000,2009
10  *
11  * Notes:
12  *     These APIs are based on the C library functions.  The semantics
13  *     should match the C functions but with expanded size operands.
14  *
15  *     The upper/lower functions are based on a table created by mkupr.
16  *     This is a compressed table of upper and lower case conversion.
17  */
18 #ifndef _CIFS_UNICODE_H
19 #define _CIFS_UNICODE_H
20 
21 #include <asm/byteorder.h>
22 #include <linux/types.h>
23 #include <linux/nls.h>
24 #include "../../nls/nls_ucs2_utils.h"
25 #include "cifsglob.h"
26 
27 /*
28  * Macs use an older "SFM" mapping of the symbols above. Fortunately it does
29  * not conflict (although almost does) with the mapping above.
30  */
31 
32 #define SFM_DOUBLEQUOTE ((__u16) 0xF020)
33 #define SFM_ASTERISK    ((__u16) 0xF021)
34 #define SFM_QUESTION    ((__u16) 0xF025)
35 #define SFM_COLON       ((__u16) 0xF022)
36 #define SFM_GRTRTHAN    ((__u16) 0xF024)
37 #define SFM_LESSTHAN    ((__u16) 0xF023)
38 #define SFM_PIPE        ((__u16) 0xF027)
39 #define SFM_SLASH       ((__u16) 0xF026)
40 #define SFM_SPACE	((__u16) 0xF028)
41 #define SFM_PERIOD	((__u16) 0xF029)
42 
43 /*
44  * Mapping mechanism to use when one of the seven reserved characters is
45  * encountered.  We can only map using one of the mechanisms at a time
46  * since otherwise readdir could return directory entries which we would
47  * not be able to open
48  *
49  * NO_MAP_UNI_RSVD  = do not perform any remapping of the character
50  * SFM_MAP_UNI_RSVD = map reserved characters using SFM scheme (MAC compatible)
51  * SFU_MAP_UNI_RSVD = map reserved characters ala SFU ("mapchars" option)
52  *
53  */
54 #define NO_MAP_UNI_RSVD		0
55 #define SFM_MAP_UNI_RSVD	1
56 #define SFU_MAP_UNI_RSVD	2
57 
58 int cifs_from_utf16(char *to, const __le16 *from, int tolen, int fromlen,
59 		    const struct nls_table *codepage, int map_type);
60 int cifs_utf16_bytes(const __le16 *from, int maxbytes,
61 		     const struct nls_table *codepage);
62 int cifs_strtoUTF16(__le16 *to, const char *from, int len,
63 		    const struct nls_table *codepage);
64 char *cifs_strndup_from_utf16(const char *src, const int maxlen,
65 			      const bool is_unicode,
66 			      const struct nls_table *codepage);
67 int cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
68 		       const struct nls_table *cp, int map_chars);
69 __le16 *cifs_strndup_to_utf16(const char *src, const int maxlen,
70 			      int *utf16_len, const struct nls_table *cp,
71 			      int remap);
72 wchar_t cifs_toupper(wchar_t in);
73 
74 static inline int cifs_remap(const struct cifs_sb_info *cifs_sb)
75 {
76 	unsigned int sbflags = cifs_sb_flags(cifs_sb);
77 
78 	if (sbflags & CIFS_MOUNT_MAP_SFM_CHR)
79 		return SFM_MAP_UNI_RSVD;
80 	if (sbflags & CIFS_MOUNT_MAP_SPECIAL_CHR)
81 		return SFU_MAP_UNI_RSVD;
82 
83 	return NO_MAP_UNI_RSVD;
84 }
85 
86 #endif /* _CIFS_UNICODE_H */
87