From patchwork Wed Sep 11 14:44:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 13800719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91F9BEE49BE for ; Wed, 11 Sep 2024 14:45:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E45C940052; Wed, 11 Sep 2024 10:45:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3936E940053; Wed, 11 Sep 2024 10:45:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20DC5940052; Wed, 11 Sep 2024 10:45:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id F2CF6940053 for ; Wed, 11 Sep 2024 10:45:33 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A9F421A148C for ; Wed, 11 Sep 2024 14:45:33 +0000 (UTC) X-FDA: 82552730946.22.D3831D7 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf09.hostedemail.com (Postfix) with ESMTP id F292E140013 for ; Wed, 11 Sep 2024 14:45:31 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=mL80uITq; spf=pass (imf09.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com; dmarc=pass (policy=none) header.from=igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726065828; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=WN3J9Ey5243Buto3KVkQAnNnAuXnNzeuNPoBKu1Uxzk=; b=iI4iIV8E0ejDPqhOAyA+ad0wLb+UVI9bcdWj8iErL9QaChCNVhrRuAfzjcjnc264cXgd9O gaURb3k9IDOgYH/HjhcjWBw36ZLGhU8wB91hGQEfOlDhr1yxcedf31Cmitakxb/2MHbDFD Lj/XaM0oW/LQZaumKIi1XKBhVlHs/Ug= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726065828; a=rsa-sha256; cv=none; b=OCdzyeya66VWZq2pXof2wuLVSmX6iMQ1795sge0f3jglbboO9BCDm4Zo3oQ/jv2gjSd038 mweuUxTaIWWCSsQCba2EMVglisXPFUn1QMKre9QiILG2f83pZlawvoGAzhsLX7N14Vyf88 3OQ5USo2PqS+YchPaNE1mBZekEeDW58= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=mL80uITq; spf=pass (imf09.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com; dmarc=pass (policy=none) header.from=igalia.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=WN3J9Ey5243Buto3KVkQAnNnAuXnNzeuNPoBKu1Uxzk=; b=mL80uITqrstdF/YOk+k9aSonku pXo5DDt06puEPHzWWm9fxQlUUhbeyg1ua0cn56u0HI5O0R2+eVN3TMcCfmpONscPwSMntpWPX+52K jT+CxL9RyLFn4NI0o3CNt/2y9revtz7hXPKfb7sD54PF/d2PJOcjE/oUxmbFbuirS1uxn5vrHN8gU tLXxQ8L/rc57Kf+IpTunNBFBtWr3rp88g10exMPPRHM0bYkPLh3DhC6NgDEeefO3LdsDZT7uw1tbp 31DW/eEiPk1KLMosg20VA+XJpE3X598rr/3orHXs0/woYyja/KIVxOQ3dPtyVOlXtTh185I5y92tx f2LiS5cA==; Received: from [177.172.122.98] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1soOay-00CTwi-8f; Wed, 11 Sep 2024 16:45:24 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Daniel Rosenberg , smcv@collabora.com, Christoph Hellwig , Theodore Ts'o , =?utf-8?q?An?= =?utf-8?q?dr=C3=A9_Almeida?= Subject: [PATCH v4 03/10] unicode: Recreate utf8_parse_version() Date: Wed, 11 Sep 2024 11:44:55 -0300 Message-ID: <20240911144502.115260-4-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911144502.115260-1-andrealmeid@igalia.com> References: <20240911144502.115260-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: F292E140013 X-Stat-Signature: u7a5jkyq7bmt8mbro3uk7y9q8cy6h761 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1726065931-399033 X-HE-Meta: U2FsdGVkX1+oC3p+2HW+f3yD4/+pebY8F73sMJvp3Eg5rTCGLYE07bd0ED28GtxCDZrBsDvFSlJSjg3PBrM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9Qbktr4W8gZ9dgARz9u+2toDdqWFPXrnVYPjW2FPtIpepYg8I7fmoYu3a1eX7pPv6fcpYiXoqPmn/BcF4klTkA9w0CrVqNpFP7wv1fjFErAeeR1igdbZ2F62mBnlNrh1DPFPviS5aKg6tUZMAyGUcqSJirMGZdzHPb27CzSMDtwB2F9z23RoghY2Ok76/4d2YphGlk985N755TRZjFQmlc7rRFnfOr5SN46t0SjAP X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: All filesystems that currently support UTF-8 casefold can fetch the UTF-8 version from the filesystem metadata stored on disk. They can get the data stored and directly match it to a integer, so they can skip the string parsing step, which motivated the removal of this function in the first place. However, for tmpfs, the only way to tell the kernel which UTF-8 version we are about to use is via mount options, using a string. Re-introduce utf8_parse_version() to be used by tmpfs. This version differs from the original by skipping the intermediate step of copying the version string to an auxiliary string before calling match_token(). This versions calls match_token() in the argument string. The paramenters are simpler now as well. utf8_parse_version() was created by 9d53690f0d4 ("unicode: implement higher level API for string handling") and later removed by 49bd03cc7e9 ("unicode: pass a UNICODE_AGE() tripple to utf8_load"). Signed-off-by: André Almeida Reviewed-by: Theodore Ts'o Reviewed-by: Gabriel Krisman Bertazi --- Changes from v3: - Return version on the return value, instead of returning version at function args. --- fs/unicode/utf8-core.c | 26 ++++++++++++++++++++++++++ include/linux/unicode.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/fs/unicode/utf8-core.c b/fs/unicode/utf8-core.c index 0400824ef493..6fc9ab8667e6 100644 --- a/fs/unicode/utf8-core.c +++ b/fs/unicode/utf8-core.c @@ -214,3 +214,29 @@ void utf8_unload(struct unicode_map *um) } EXPORT_SYMBOL(utf8_unload); +/** + * utf8_parse_version - Parse a UTF-8 version number from a string + * + * @version: input string + * + * Returns the parsed version on success, negative code on error + */ +int utf8_parse_version(char *version) +{ + substring_t args[3]; + unsigned int maj, min, rev; + static const struct match_token token[] = { + {1, "%d.%d.%d"}, + {0, NULL} + }; + + if (match_token(version, token, args) != 1) + return -EINVAL; + + if (match_int(&args[0], &maj) || match_int(&args[1], &min) || + match_int(&args[2], &rev)) + return -EINVAL; + + return UNICODE_AGE(maj, min, rev); +} +EXPORT_SYMBOL(utf8_parse_version); diff --git a/include/linux/unicode.h b/include/linux/unicode.h index 4d39e6e11a95..12face04c763 100644 --- a/include/linux/unicode.h +++ b/include/linux/unicode.h @@ -76,4 +76,6 @@ int utf8_casefold_hash(const struct unicode_map *um, const void *salt, struct unicode_map *utf8_load(unsigned int version); void utf8_unload(struct unicode_map *um); +int utf8_parse_version(char *version); + #endif /* _LINUX_UNICODE_H */