This source file includes following definitions.
- ntfs_utf8_wget
- ntfs_utf8_wput
- ntfs_utf8_wcmp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 #include <sys/cdefs.h>
44 #ifdef __KERNEL_RCSID
45 __KERNEL_RCSID(0, "$NetBSD: ntfs_conv.c,v 1.1 2002/12/23 17:38:32 jdolecek Exp $");
46 #endif
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/namei.h>
51 #include <sys/proc.h>
52 #include <sys/kernel.h>
53 #include <sys/vnode.h>
54 #include <sys/mount.h>
55 #include <sys/buf.h>
56 #include <sys/file.h>
57 #include <sys/malloc.h>
58 #include <sys/lock.h>
59 #if defined(__FreeBSD__)
60 #include <machine/clock.h>
61 #endif
62
63 #include <miscfs/specfs/specdev.h>
64
65
66 #if defined(__FreeBSD__) || defined(__NetBSD__)
67 #include <fs/ntfs/ntfs.h>
68 #include <fs/ntfs/ntfsmount.h>
69 #include <fs/ntfs/ntfs_inode.h>
70 #include <fs/ntfs/ntfs_vfsops.h>
71 #include <fs/ntfs/ntfs_subr.h>
72 #include <fs/ntfs/ntfs_compr.h>
73 #include <fs/ntfs/ntfs_ihash.h>
74 #else
75 #include <ntfs/ntfs.h>
76 #include <ntfs/ntfsmount.h>
77 #include <ntfs/ntfs_inode.h>
78 #include <ntfs/ntfs_vfsops.h>
79 #include <ntfs/ntfs_subr.h>
80 #include <ntfs/ntfs_compr.h>
81 #include <ntfs/ntfs_ihash.h>
82 #endif
83
84
85
86 static const int _utf_count[16] = {
87 1, 1, 1, 1, 1, 1, 1, 1,
88 0, 0, 0, 0, 2, 2, 3, 0,
89 };
90
91
92
93
94
95 wchar
96 ntfs_utf8_wget(const char **str)
97 {
98 int c;
99 wchar rune = 0;
100 const char *s = *str;
101
102 c = _utf_count[(s[0] >> 4) & 0xf];
103 if (c == 0) {
104 c = 1;
105 goto encoding_error;
106 }
107
108 switch (c) {
109 case 1:
110 rune = s[0] & 0xff;
111 break;
112 case 2:
113 if ((s[1] & 0xc0) != 0x80)
114 goto encoding_error;
115 rune = ((s[0] & 0x1F) << 6) | (s[1] & 0x3F);
116 break;
117 case 3:
118 if ((s[1] & 0xC0) != 0x80 || (s[2] & 0xC0) != 0x80)
119 goto encoding_error;
120 rune = ((s[0] & 0x1F) << 12) | ((s[1] & 0x3F) << 6)
121 | (s[2] & 0x3F);
122 break;
123 }
124
125 encoding_error:
126 *str = *str + c;
127 return rune;
128 }
129
130
131
132
133
134
135 int
136 ntfs_utf8_wput(char *s, size_t n, wchar wc)
137 {
138 if (wc & 0xf800) {
139 if (n < 3) {
140
141 ddprintf(("ntfs_utf8_wput: need 3 bytes\n"));
142 return 0;
143 }
144
145 s[0] = 0xE0 | ((wc >> 12) & 0x0F);
146 s[1] = 0x80 | ((wc >> 6) & 0x3F);
147 s[2] = 0x80 | ((wc) & 0x3F);
148 return 3;
149 } else {
150 if (wc & 0x0780) {
151 if (n < 2) {
152
153 ddprintf(("ntfs_utf8_wput: need 2 bytes\n"));
154 return 0;
155 }
156
157 s[0] = 0xC0 | ((wc >> 6) & 0x1F);
158 s[1] = 0x80 | ((wc) & 0x3F);
159 return 2;
160 } else {
161 if (n < 1) {
162
163 ddprintf(("ntfs_utf8_wput: need 1 byte\n"));
164 return 0;
165 }
166
167 s[0] = wc;
168 return 1;
169 }
170 }
171 }
172
173
174
175
176
177 int
178 ntfs_utf8_wcmp(wchar wc1, wchar wc2)
179 {
180
181
182 if (wc1 == wc2)
183 return 0;
184 else
185 return (int) wc1 - (int) wc2;
186 }