From patchwork Tue Jul 3 17:06:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 938833 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=collabora.co.uk Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41KrF531tzz9s3C for ; Wed, 4 Jul 2018 03:08:57 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934241AbeGCRIM (ORCPT ); Tue, 3 Jul 2018 13:08:12 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:33436 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933677AbeGCRIK (ORCPT ); Tue, 3 Jul 2018 13:08:10 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id D17AA289317 From: Gabriel Krisman Bertazi To: tytso@mit.edu Cc: linux-ext4@vger.kernel.org, darrick.wong@oracle.com, kernel@collabora.com, Gabriel Krisman Bertazi Subject: [PATCH 16/20] nls: ascii: Support casefold and normalization operations Date: Tue, 3 Jul 2018 13:06:56 -0400 Message-Id: <20180703170700.9306-17-krisman@collabora.co.uk> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180703170700.9306-1-krisman@collabora.co.uk> References: <20180703170700.9306-1-krisman@collabora.co.uk> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Normalization is identity, but casefold can be implemented with toupper or tolower, and we have no specification on that. We should be safe, as long as it is constant. Signed-off-by: Gabriel Krisman Bertazi --- fs/nls/nls_ascii.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/fs/nls/nls_ascii.c b/fs/nls/nls_ascii.c index 2f4826478d3d..40b8e7acfe1e 100644 --- a/fs/nls/nls_ascii.c +++ b/fs/nls/nls_ascii.c @@ -12,6 +12,7 @@ #include #include #include +#include static const wchar_t charset2uni[256] = { /* 0x00*/ @@ -152,11 +153,43 @@ static unsigned char charset_toupper(const struct nls_table *table, return charset2upper[c]; } +/* Ascii casefold can be defined as either to lower or to upper. As long + * as it is stable. */ +static int ascii_casefold(const struct nls_table *charset, + const unsigned char *str, size_t len, + unsigned char *dest, size_t dlen) +{ + unsigned int i; + + if (dlen < len) + return -EINVAL; + + for (i = 0; i < len; i++) + dest[i] = charset_tolower(charset, str[i]); + + return 0; +} + +/* Ascii normalization is identity. */ +static int ascii_normalize(const struct nls_table *charset, + const unsigned char *str, size_t len, + unsigned char *dest, size_t dlen) +{ + if (dlen < len) + return -EINVAL; + + memcpy(dest, str, len); + + return 0; +} + static const struct nls_ops charset_ops = { .lowercase = charset_toupper, .uppercase = charset_tolower, .uni2char = uni2char, .char2uni = char2uni, + .casefold = ascii_casefold, + .normalize = ascii_normalize, }; static struct nls_charset nls_charset;