[linux-cifs-client] [PATCH 1/3] cifs: Introduce helper to compute
length of nls string in bytes
Günter Kukkukk
linux at kukkukk.com
Wed Apr 22 00:25:05 GMT 2009
Am Dienstag, 21. April 2009 schrieb Suresh Jayaraman:
> Though the consensus is that we need a generalised helper to handle
> unicode string buffers so that other filesystems could consume, we would
> need a cifs helper like this in the interim, given the number of
> discussions/reviews and bug reports. cifs could easily replace this with
> generic helpers once such helper is in place.
>
>
> Signed-off-by: Suresh Jayaraman <sjayaraman at suse.de>
> ---
> fs/cifs/cifs_unicode.h | 27 +++++++++++++++++++++++++++
> 1 files changed, 27 insertions(+), 0 deletions(-)
>
> diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h
> index 14eb9a2..8ab332b 100644
> --- a/fs/cifs/cifs_unicode.h
> +++ b/fs/cifs/cifs_unicode.h
> @@ -159,6 +159,33 @@ UniStrnlen(const wchar_t *ucs1, int maxlen)
> }
>
> /*
> + * UniStrnlenBytes: Return the length of a NLS string in bytes. Also, populates
> + * 'nchars' with the length of string in 16 bit Unicode chars.
> + */
> +static inline size_t
> +UniStrnlenBytes(const wchar_t *str, int maxlen, int *nchars,
> + const struct nls_table *codepage)
> +{
> + int nc;
> + size_t nbytes = 0;
> + char buf[NLS_MAX_CHARSET_SIZE]; /* enough for one char at a time */
> +
> + *nchars = 0;
> + while (*str++ && maxlen) {
> + nc = codepage->uni2char(*str, buf, NLS_MAX_CHARSET_SIZE);
> + if (nc > 0)
> + nbytes += nc;
> + else
> + nbytes += 1; /* for '?' */
> + (*nchars)++;
> + if (*nchars >= maxlen)
> + break;
> + }
> +
> + return nbytes;
> +}
> +
> +/*
> * UniStrncat: Concatenate length limited string
> */
> static inline wchar_t *
during cleanup of the unicode related stuff we should also have a look
at functions currently located in misc.c
- cifs_convertUCSpath()
- cifsConvertToUCS()
At the moment cifs_convertUCSpath() contains the following check:
...
/* make sure we do not overrun callers allocated temp buffer */
if (j >= (2 * NAME_MAX))
break;
...
Probably both functions should be moved away from misc.c.
Cheers, Günter
More information about the linux-cifs-client
mailing list