From patchwork Tue Apr 21 12:24:38 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suresh Jayaraman X-Patchwork-Id: 19164 Received: from lists.samba.org (mail.samba.org [66.70.73.150]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n3LCPHWX019987 for ; Tue, 21 Apr 2009 12:25:18 GMT Received: from dp.samba.org (localhost [127.0.0.1]) by lists.samba.org (Postfix) with ESMTP id 00536163C29 for ; Tue, 21 Apr 2009 12:24:55 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on dp.samba.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=3.8 tests=AWL, BAYES_00 autolearn=ham version=3.1.7 X-Original-To: linux-cifs-client@lists.samba.org Delivered-To: linux-cifs-client@lists.samba.org Received: from victor.provo.novell.com (victor.provo.novell.com [137.65.250.26]) by lists.samba.org (Postfix) with ESMTP id BE018163B27 for ; Tue, 21 Apr 2009 12:24:36 +0000 (GMT) Received: from [192.168.2.100] (prv-ext-foundry1.gns.novell.com [137.65.251.240]) by victor.provo.novell.com with ESMTP (TLS encrypted); Tue, 21 Apr 2009 06:24:52 -0600 Message-ID: <49EDBB06.3060409@suse.de> Date: Tue, 21 Apr 2009 17:54:38 +0530 From: Suresh Jayaraman User-Agent: Thunderbird 2.0.0.19 (X11/20081227) MIME-Version: 1.0 To: Steve French X-Enigmail-Version: 0.95.7 Cc: linux-cifs-client@lists.samba.org, Jeff Layton , =?UTF-8?B?R8O8bnRlciBLdWtrdWtr?= Subject: [linux-cifs-client] [PATCH 1/3] cifs: Introduce helper to compute length of nls string in bytes X-BeenThere: linux-cifs-client@lists.samba.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: The Linux CIFS VFS client List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-cifs-client-bounces+patchwork-cifs-client=patchwork.kernel.org@lists.samba.org Errors-To: linux-cifs-client-bounces+patchwork-cifs-client=patchwork.kernel.org@lists.samba.org 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 --- 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 *