aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2009-04-30 06:46:32 -0400
committerSteve French <sfrench@us.ibm.com>2009-04-30 11:45:00 -0400
commit69f801fcaa03be83d58c564f00913b7c172808e4 (patch)
tree35e359acc85bef8669b001ccb412afb96d256a82 /fs
parent7fabf0c9479fef9fdb9528a5fbdb1cb744a744a4 (diff)
cifs: add new function to get unicode string length in bytes
Working in units of words means we do a lot of unnecessary conversion back and forth. Standardize on bytes instead since that's more useful for allocating buffers and such. Also, remove hostlen_fromUCS since the new function has a similar purpose. Signed-off-by: Jeff Layton <jlayton@redhat.com> Acked-by: Suresh Jayaraman <sjayaraman@suse.de> Signed-off-by: Steve French <sfrench@us.ibm.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/cifs/cifs_unicode.c31
-rw-r--r--fs/cifs/cifs_unicode.h2
-rw-r--r--fs/cifs/cifssmb.c25
3 files changed, 35 insertions, 23 deletions
diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c
index 8389f359b03d..614512573c67 100644
--- a/fs/cifs/cifs_unicode.c
+++ b/fs/cifs/cifs_unicode.c
@@ -26,6 +26,37 @@
26#include "cifs_debug.h" 26#include "cifs_debug.h"
27 27
28/* 28/*
29 * cifs_ucs2_bytes - how long will a string be after conversion?
30 * @ucs - pointer to input string
31 * @maxbytes - don't go past this many bytes of input string
32 * @codepage - destination codepage
33 *
34 * Walk a ucs2le string and return the number of bytes that the string will
35 * be after being converted to the given charset, not including any null
36 * termination required. Don't walk past maxbytes in the source buffer.
37 */
38int
39cifs_ucs2_bytes(const __le16 *from, int maxbytes,
40 const struct nls_table *codepage)
41{
42 int i;
43 int charlen, outlen = 0;
44 int maxwords = maxbytes / 2;
45 char tmp[NLS_MAX_CHARSET_SIZE];
46
47 for (i = 0; from[i] && i < maxwords; i++) {
48 charlen = codepage->uni2char(le16_to_cpu(from[i]), tmp,
49 NLS_MAX_CHARSET_SIZE);
50 if (charlen > 0)
51 outlen += charlen;
52 else
53 outlen++;
54 }
55
56 return outlen;
57}
58
59/*
29 * cifs_mapchar - convert a little-endian char to proper char in codepage 60 * cifs_mapchar - convert a little-endian char to proper char in codepage
30 * @target - where converted character should be copied 61 * @target - where converted character should be copied
31 * @src_char - 2 byte little-endian source character 62 * @src_char - 2 byte little-endian source character
diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h
index 6aa6533e49fa..1857f5ff9337 100644
--- a/fs/cifs/cifs_unicode.h
+++ b/fs/cifs/cifs_unicode.h
@@ -74,6 +74,8 @@ extern struct UniCaseRange UniLowerRange[];
74#ifdef __KERNEL__ 74#ifdef __KERNEL__
75int cifs_from_ucs2(char *to, const __le16 *from, int tolen, int fromlen, 75int cifs_from_ucs2(char *to, const __le16 *from, int tolen, int fromlen,
76 const struct nls_table *codepage, bool mapchar); 76 const struct nls_table *codepage, bool mapchar);
77int cifs_ucs2_bytes(const __le16 *from, int maxbytes,
78 const struct nls_table *codepage);
77int cifs_strfromUCS_le(char *, const __le16 *, int, const struct nls_table *); 79int cifs_strfromUCS_le(char *, const __le16 *, int, const struct nls_table *);
78int cifs_strtoUCS(__le16 *, const char *, int, const struct nls_table *); 80int cifs_strtoUCS(__le16 *, const char *, int, const struct nls_table *);
79#endif 81#endif
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index a02c43b3faf5..cadacae46b82 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -3928,27 +3928,6 @@ GetInodeNumOut:
3928 return rc; 3928 return rc;
3929} 3929}
3930 3930
3931/* computes length of UCS string converted to host codepage
3932 * @src: UCS string
3933 * @maxlen: length of the input string in UCS characters
3934 * (not in bytes)
3935 *
3936 * return: size of input string in host codepage
3937 */
3938static int hostlen_fromUCS(const __le16 *src, const int maxlen,
3939 const struct nls_table *nls_codepage) {
3940 int i;
3941 int hostlen = 0;
3942 char to[4];
3943 int charlen;
3944 for (i = 0; (i < maxlen) && src[i]; ++i) {
3945 charlen = nls_codepage->uni2char(le16_to_cpu(src[i]),
3946 to, NLS_MAX_CHARSET_SIZE);
3947 hostlen += charlen > 0 ? charlen : 1;
3948 }
3949 return hostlen;
3950}
3951
3952/* parses DFS refferal V3 structure 3931/* parses DFS refferal V3 structure
3953 * caller is responsible for freeing target_nodes 3932 * caller is responsible for freeing target_nodes
3954 * returns: 3933 * returns:
@@ -4016,8 +3995,8 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
4016 GFP_KERNEL); 3995 GFP_KERNEL);
4017 cifsConvertToUCS((__le16 *) tmp, searchName, 3996 cifsConvertToUCS((__le16 *) tmp, searchName,
4018 PATH_MAX, nls_codepage, remap); 3997 PATH_MAX, nls_codepage, remap);
4019 node->path_consumed = hostlen_fromUCS(tmp, 3998 node->path_consumed = cifs_ucs2_bytes(tmp,
4020 le16_to_cpu(pSMBr->PathConsumed)/2, 3999 le16_to_cpu(pSMBr->PathConsumed),
4021 nls_codepage); 4000 nls_codepage);
4022 kfree(tmp); 4001 kfree(tmp);
4023 } else 4002 } else