diff options
author | Pavel Shilovsky <piastry@etersoft.ru> | 2011-12-26 13:58:46 -0500 |
---|---|---|
committer | Pavel Shilovsky <pshilovsky@samba.org> | 2012-07-24 13:55:05 -0400 |
commit | 2503a0dba989486c59523a947a1dcb50ad90fee9 (patch) | |
tree | 1e79a740d744cee1a1981e4d0a355303ffc9a4d2 /fs/cifs/cifs_unicode.c | |
parent | 68889f269b16a11866f4ec71e8177bdd0c184a3f (diff) |
CIFS: Add SMB2 support for is_path_accessible
that needs for a successful mount through SMB2 protocol.
Signed-off-by: Pavel Shilovsky <piastry@etersoft.ru>
Signed-off-by: Steve French <smfrench@gmail.com>
Diffstat (limited to 'fs/cifs/cifs_unicode.c')
-rw-r--r-- | fs/cifs/cifs_unicode.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c index 97c1d4210869..7dab9c04ad52 100644 --- a/fs/cifs/cifs_unicode.c +++ b/fs/cifs/cifs_unicode.c | |||
@@ -330,3 +330,64 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen, | |||
330 | ctoUTF16_out: | 330 | ctoUTF16_out: |
331 | return i; | 331 | return i; |
332 | } | 332 | } |
333 | |||
334 | #ifdef CONFIG_CIFS_SMB2 | ||
335 | /* | ||
336 | * cifs_local_to_utf16_bytes - how long will a string be after conversion? | ||
337 | * @from - pointer to input string | ||
338 | * @maxbytes - don't go past this many bytes of input string | ||
339 | * @codepage - source codepage | ||
340 | * | ||
341 | * Walk a string and return the number of bytes that the string will | ||
342 | * be after being converted to the given charset, not including any null | ||
343 | * termination required. Don't walk past maxbytes in the source buffer. | ||
344 | */ | ||
345 | |||
346 | static int | ||
347 | cifs_local_to_utf16_bytes(const char *from, int len, | ||
348 | const struct nls_table *codepage) | ||
349 | { | ||
350 | int charlen; | ||
351 | int i; | ||
352 | wchar_t wchar_to; | ||
353 | |||
354 | for (i = 0; len && *from; i++, from += charlen, len -= charlen) { | ||
355 | charlen = codepage->char2uni(from, len, &wchar_to); | ||
356 | /* Failed conversion defaults to a question mark */ | ||
357 | if (charlen < 1) | ||
358 | charlen = 1; | ||
359 | } | ||
360 | return 2 * i; /* UTF16 characters are two bytes */ | ||
361 | } | ||
362 | |||
363 | /* | ||
364 | * cifs_strndup_to_utf16 - copy a string to wire format from the local codepage | ||
365 | * @src - source string | ||
366 | * @maxlen - don't walk past this many bytes in the source string | ||
367 | * @utf16_len - the length of the allocated string in bytes (including null) | ||
368 | * @cp - source codepage | ||
369 | * @remap - map special chars | ||
370 | * | ||
371 | * Take a string convert it from the local codepage to UTF16 and | ||
372 | * put it in a new buffer. Returns a pointer to the new string or NULL on | ||
373 | * error. | ||
374 | */ | ||
375 | __le16 * | ||
376 | cifs_strndup_to_utf16(const char *src, const int maxlen, int *utf16_len, | ||
377 | const struct nls_table *cp, int remap) | ||
378 | { | ||
379 | int len; | ||
380 | __le16 *dst; | ||
381 | |||
382 | len = cifs_local_to_utf16_bytes(src, maxlen, cp); | ||
383 | len += 2; /* NULL */ | ||
384 | dst = kmalloc(len, GFP_KERNEL); | ||
385 | if (!dst) { | ||
386 | *utf16_len = 0; | ||
387 | return NULL; | ||
388 | } | ||
389 | cifsConvertToUTF16(dst, src, strlen(src), cp, remap); | ||
390 | *utf16_len = len; | ||
391 | return dst; | ||
392 | } | ||
393 | #endif /* CONFIG_CIFS_SMB2 */ | ||