Skip to content

Commit de54845

Browse files
Dr. David Alan GilbertSteve French
authored andcommitted
fs/smb/client: Use common code in client
Now we've got the common code, use it for the client as well. Note there's a change here where we're using the server version of UniStrcat now which had different types (__le16 vs wchar_t) but it's not interpreting the value other than checking for 0, however we do need casts to keep sparse happy. Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org> Reviewed-by: Dave Kleikamp <dave.kleikamp@oracle.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 089f7f5 commit de54845

File tree

5 files changed

+4
-405
lines changed

5 files changed

+4
-405
lines changed

fs/smb/client/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ config CIFS
33
tristate "SMB3 and CIFS support (advanced network filesystem)"
44
depends on INET
55
select NLS
6+
select NLS_UCS2_UTILS
67
select CRYPTO
78
select CRYPTO_MD5
89
select CRYPTO_SHA256

fs/smb/client/cifs_unicode.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <linux/slab.h>
99
#include "cifs_fs_sb.h"
1010
#include "cifs_unicode.h"
11-
#include "cifs_uniupr.h"
1211
#include "cifspdu.h"
1312
#include "cifsglob.h"
1413
#include "cifs_debug.h"

fs/smb/client/cifs_unicode.h

Lines changed: 1 addition & 279 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,7 @@
2121
#include <asm/byteorder.h>
2222
#include <linux/types.h>
2323
#include <linux/nls.h>
24-
25-
/*
26-
* Windows maps these to the user defined 16 bit Unicode range since they are
27-
* reserved symbols (along with \ and /), otherwise illegal to store
28-
* in filenames in NTFS
29-
*/
30-
#define UNI_ASTERISK (__u16) ('*' + 0xF000)
31-
#define UNI_QUESTION (__u16) ('?' + 0xF000)
32-
#define UNI_COLON (__u16) (':' + 0xF000)
33-
#define UNI_GRTRTHAN (__u16) ('>' + 0xF000)
34-
#define UNI_LESSTHAN (__u16) ('<' + 0xF000)
35-
#define UNI_PIPE (__u16) ('|' + 0xF000)
36-
#define UNI_SLASH (__u16) ('\\' + 0xF000)
24+
#include "../../nls/nls_ucs2_utils.h"
3725

3826
/*
3927
* Macs use an older "SFM" mapping of the symbols above. Fortunately it does
@@ -66,22 +54,6 @@
6654
#define SFM_MAP_UNI_RSVD 1
6755
#define SFU_MAP_UNI_RSVD 2
6856

69-
/* Just define what we want from uniupr.h. We don't want to define the tables
70-
* in each source file.
71-
*/
72-
#ifndef UNICASERANGE_DEFINED
73-
struct UniCaseRange {
74-
wchar_t start;
75-
wchar_t end;
76-
signed char *table;
77-
};
78-
#endif /* UNICASERANGE_DEFINED */
79-
80-
#ifndef UNIUPR_NOUPPER
81-
extern signed char CifsUniUpperTable[512];
82-
extern const struct UniCaseRange CifsUniUpperRange[];
83-
#endif /* UNIUPR_NOUPPER */
84-
8557
#ifdef __KERNEL__
8658
int cifs_from_utf16(char *to, const __le16 *from, int tolen, int fromlen,
8759
const struct nls_table *cp, int map_type);
@@ -101,254 +73,4 @@ extern __le16 *cifs_strndup_to_utf16(const char *src, const int maxlen,
10173

10274
wchar_t cifs_toupper(wchar_t in);
10375

104-
/*
105-
* UniStrcat: Concatenate the second string to the first
106-
*
107-
* Returns:
108-
* Address of the first string
109-
*/
110-
static inline __le16 *
111-
UniStrcat(__le16 *ucs1, const __le16 *ucs2)
112-
{
113-
__le16 *anchor = ucs1; /* save a pointer to start of ucs1 */
114-
115-
while (*ucs1++) ; /* To end of first string */
116-
ucs1--; /* Return to the null */
117-
while ((*ucs1++ = *ucs2++)) ; /* copy string 2 over */
118-
return anchor;
119-
}
120-
121-
/*
122-
* UniStrchr: Find a character in a string
123-
*
124-
* Returns:
125-
* Address of first occurrence of character in string
126-
* or NULL if the character is not in the string
127-
*/
128-
static inline wchar_t *
129-
UniStrchr(const wchar_t *ucs, wchar_t uc)
130-
{
131-
while ((*ucs != uc) && *ucs)
132-
ucs++;
133-
134-
if (*ucs == uc)
135-
return (wchar_t *) ucs;
136-
return NULL;
137-
}
138-
139-
/*
140-
* UniStrcmp: Compare two strings
141-
*
142-
* Returns:
143-
* < 0: First string is less than second
144-
* = 0: Strings are equal
145-
* > 0: First string is greater than second
146-
*/
147-
static inline int
148-
UniStrcmp(const wchar_t *ucs1, const wchar_t *ucs2)
149-
{
150-
while ((*ucs1 == *ucs2) && *ucs1) {
151-
ucs1++;
152-
ucs2++;
153-
}
154-
return (int) *ucs1 - (int) *ucs2;
155-
}
156-
157-
/*
158-
* UniStrcpy: Copy a string
159-
*/
160-
static inline wchar_t *
161-
UniStrcpy(wchar_t *ucs1, const wchar_t *ucs2)
162-
{
163-
wchar_t *anchor = ucs1; /* save the start of result string */
164-
165-
while ((*ucs1++ = *ucs2++)) ;
166-
return anchor;
167-
}
168-
169-
/*
170-
* UniStrlen: Return the length of a string (in 16 bit Unicode chars not bytes)
171-
*/
172-
static inline size_t
173-
UniStrlen(const wchar_t *ucs1)
174-
{
175-
int i = 0;
176-
177-
while (*ucs1++)
178-
i++;
179-
return i;
180-
}
181-
182-
/*
183-
* UniStrnlen: Return the length (in 16 bit Unicode chars not bytes) of a
184-
* string (length limited)
185-
*/
186-
static inline size_t
187-
UniStrnlen(const wchar_t *ucs1, int maxlen)
188-
{
189-
int i = 0;
190-
191-
while (*ucs1++) {
192-
i++;
193-
if (i >= maxlen)
194-
break;
195-
}
196-
return i;
197-
}
198-
199-
/*
200-
* UniStrncat: Concatenate length limited string
201-
*/
202-
static inline wchar_t *
203-
UniStrncat(wchar_t *ucs1, const wchar_t *ucs2, size_t n)
204-
{
205-
wchar_t *anchor = ucs1; /* save pointer to string 1 */
206-
207-
while (*ucs1++) ;
208-
ucs1--; /* point to null terminator of s1 */
209-
while (n-- && (*ucs1 = *ucs2)) { /* copy s2 after s1 */
210-
ucs1++;
211-
ucs2++;
212-
}
213-
*ucs1 = 0; /* Null terminate the result */
214-
return (anchor);
215-
}
216-
217-
/*
218-
* UniStrncmp: Compare length limited string
219-
*/
220-
static inline int
221-
UniStrncmp(const wchar_t *ucs1, const wchar_t *ucs2, size_t n)
222-
{
223-
if (!n)
224-
return 0; /* Null strings are equal */
225-
while ((*ucs1 == *ucs2) && *ucs1 && --n) {
226-
ucs1++;
227-
ucs2++;
228-
}
229-
return (int) *ucs1 - (int) *ucs2;
230-
}
231-
232-
/*
233-
* UniStrncmp_le: Compare length limited string - native to little-endian
234-
*/
235-
static inline int
236-
UniStrncmp_le(const wchar_t *ucs1, const wchar_t *ucs2, size_t n)
237-
{
238-
if (!n)
239-
return 0; /* Null strings are equal */
240-
while ((*ucs1 == __le16_to_cpu(*ucs2)) && *ucs1 && --n) {
241-
ucs1++;
242-
ucs2++;
243-
}
244-
return (int) *ucs1 - (int) __le16_to_cpu(*ucs2);
245-
}
246-
247-
/*
248-
* UniStrncpy: Copy length limited string with pad
249-
*/
250-
static inline wchar_t *
251-
UniStrncpy(wchar_t *ucs1, const wchar_t *ucs2, size_t n)
252-
{
253-
wchar_t *anchor = ucs1;
254-
255-
while (n-- && *ucs2) /* Copy the strings */
256-
*ucs1++ = *ucs2++;
257-
258-
n++;
259-
while (n--) /* Pad with nulls */
260-
*ucs1++ = 0;
261-
return anchor;
262-
}
263-
264-
/*
265-
* UniStrncpy_le: Copy length limited string with pad to little-endian
266-
*/
267-
static inline wchar_t *
268-
UniStrncpy_le(wchar_t *ucs1, const wchar_t *ucs2, size_t n)
269-
{
270-
wchar_t *anchor = ucs1;
271-
272-
while (n-- && *ucs2) /* Copy the strings */
273-
*ucs1++ = __le16_to_cpu(*ucs2++);
274-
275-
n++;
276-
while (n--) /* Pad with nulls */
277-
*ucs1++ = 0;
278-
return anchor;
279-
}
280-
281-
/*
282-
* UniStrstr: Find a string in a string
283-
*
284-
* Returns:
285-
* Address of first match found
286-
* NULL if no matching string is found
287-
*/
288-
static inline wchar_t *
289-
UniStrstr(const wchar_t *ucs1, const wchar_t *ucs2)
290-
{
291-
const wchar_t *anchor1 = ucs1;
292-
const wchar_t *anchor2 = ucs2;
293-
294-
while (*ucs1) {
295-
if (*ucs1 == *ucs2) {
296-
/* Partial match found */
297-
ucs1++;
298-
ucs2++;
299-
} else {
300-
if (!*ucs2) /* Match found */
301-
return (wchar_t *) anchor1;
302-
ucs1 = ++anchor1; /* No match */
303-
ucs2 = anchor2;
304-
}
305-
}
306-
307-
if (!*ucs2) /* Both end together */
308-
return (wchar_t *) anchor1; /* Match found */
309-
return NULL; /* No match */
310-
}
311-
312-
#ifndef UNIUPR_NOUPPER
313-
/*
314-
* UniToupper: Convert a unicode character to upper case
315-
*/
316-
static inline wchar_t
317-
UniToupper(register wchar_t uc)
318-
{
319-
register const struct UniCaseRange *rp;
320-
321-
if (uc < sizeof(CifsUniUpperTable)) {
322-
/* Latin characters */
323-
return uc + CifsUniUpperTable[uc]; /* Use base tables */
324-
} else {
325-
rp = CifsUniUpperRange; /* Use range tables */
326-
while (rp->start) {
327-
if (uc < rp->start) /* Before start of range */
328-
return uc; /* Uppercase = input */
329-
if (uc <= rp->end) /* In range */
330-
return uc + rp->table[uc - rp->start];
331-
rp++; /* Try next range */
332-
}
333-
}
334-
return uc; /* Past last range */
335-
}
336-
337-
/*
338-
* UniStrupr: Upper case a unicode string
339-
*/
340-
static inline __le16 *
341-
UniStrupr(register __le16 *upin)
342-
{
343-
register __le16 *up;
344-
345-
up = upin;
346-
while (*up) { /* For all characters */
347-
*up = cpu_to_le16(UniToupper(le16_to_cpu(*up)));
348-
up++;
349-
}
350-
return upin; /* Return input pointer */
351-
}
352-
#endif /* UNIUPR_NOUPPER */
353-
35476
#endif /* _CIFS_UNICODE_H */

0 commit comments

Comments
 (0)