From patchwork Mon Sep 2 22:55:06 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: 13787774 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 D2F44CD3420 for ; Mon, 2 Sep 2024 22:55:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13A7E6B038C; Mon, 2 Sep 2024 18:55:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09E138D0118; Mon, 2 Sep 2024 18:55:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA9308D0117; Mon, 2 Sep 2024 18:55:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CE5F26B03D9 for ; Mon, 2 Sep 2024 18:55:46 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 806721C4D00 for ; Mon, 2 Sep 2024 22:55:46 +0000 (UTC) X-FDA: 82521307092.21.B6A617D Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf04.hostedemail.com (Postfix) with ESMTP id CE48B40005 for ; Mon, 2 Sep 2024 22:55:44 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b="rvUoE5U/"; spf=pass (imf04.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=1725317650; 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=f1lkFnBhu2A4rfcTTwgMOmoFrMOxofOkPfLVQlrRaOA=; b=S3cg7R3Bl82q/zfsGFft6NpGQkwiqicH7uwgyyw576ohQKOgGW9Czy9uuAC338Z6FdFDg3 NXO/QbDcMagL+9Yr0JDWcXTi6t01iYyBvmoUsCDH8eJfw1jUl2ZiFNHyLN68lIPCi1fDTQ VQFGqhLtozFYo+UIiVrzRCiKuoXqOmQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725317650; a=rsa-sha256; cv=none; b=ZTtXFbFA/WXMPb5eUQ4uQpx2xpn4mW3ez+PkbalPDT+2f+s4m8sipBBnQamAvb0PkyRXYL 8abiesKT5qiGJX8p/R7b/FhfA/tXJ/ltkTyvX8QUQzOjg2nKZFDjTTzaYGG5CYqFcuqTaA 0Z3xDzlOKg3PjwfWiavFRtemx0LyRqo= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b="rvUoE5U/"; spf=pass (imf04.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=f1lkFnBhu2A4rfcTTwgMOmoFrMOxofOkPfLVQlrRaOA=; b=rvUoE5U/5H5F4Qjp3s3lJnTsn/ gzTbW9mJkx6r+0MShBqi3wVhPGdxQrANKTSmWFvZKfVKg9xssWGHCAXlZBGtKQJV1wQJCHk8LbE6+ NIxBpTIsFfFkg1v3+V/a2uuCXZcl5duORJE3e91+Dz5/fhljpmco9eZJPP7e+pYT+hKekoPCebAH1 BBiwH+/wuuWQGGDusD2FC70/3WQE2UDEZCbF1f3wGwiS+XRCDJF+IbLjC3fdJhzTOW5889k2ZEN7D RAWlAK+yPhDtNhxnXakQ/bI3iM39s0C8slryFhW4nP4TXYhH5RNPPb0b5AWlS2DkGbDQynrzO5CV7 iWIVDPaQ==; 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 1slFxQ-008VrL-EL; Tue, 03 Sep 2024 00:55:36 +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 , =?utf-8?q?Andr=C3=A9_Almeida?= Subject: [PATCH v2 4/8] unicode: Recreate utf8_parse_version() Date: Mon, 2 Sep 2024 19:55:06 -0300 Message-ID: <20240902225511.757831-5-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240902225511.757831-1-andrealmeid@igalia.com> References: <20240902225511.757831-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Stat-Signature: gkgciz8ma4449ked4uof7cjzkbagqpgi X-Rspamd-Queue-Id: CE48B40005 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1725317744-617050 X-HE-Meta: U2FsdGVkX1/YsNyQdh63r++5aFvXXpsIyD+jEdXcfCQ6oWjPT4FkVo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qA3o7FUdDpIfT2kGF2mEeuFFFsdtdWsWRmoM5Mq36bTi+c6PvWwoqmU2VuFu+0ALpPK1jseeW4Xy71TAjPO5bgUKNqmng98Nlgl7/kuljfuTc1Ksawe+qU25Wm9gDYXCMpdw7HIAfVSRbNT8ns6sHCoLbBsWZkzw+SjvbCA6mAuht9P9ABzeh6MPe7/1xqmZhyikynYZPnrd/RKKdb9P5u+1/OJKE6tpuOMNZhLYtPg1OFVgtJWI4F 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. 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 --- fs/unicode/utf8-core.c | 30 ++++++++++++++++++++++++++++++ include/linux/unicode.h | 3 +++ 2 files changed, 33 insertions(+) diff --git a/fs/unicode/utf8-core.c b/fs/unicode/utf8-core.c index 4966e175ed71..3e8afd637b28 100644 --- a/fs/unicode/utf8-core.c +++ b/fs/unicode/utf8-core.c @@ -240,3 +240,33 @@ bool utf8_check_strict_name(struct inode *dir, struct qstr *d_name) utf8_validate(dir->i_sb->s_encoding, d_name)); } EXPORT_SYMBOL(utf8_check_strict_name); + +/** + * utf8_parse_version - Parse a UTF-8 version number from a string + * + * @version: input string + * @maj: output major version number + * @min: output minor version number + * @rev: output minor revision number + * + * Returns 0 on success, negative code on error + */ +int utf8_parse_version(char *version, unsigned int *maj, + unsigned int *min, unsigned int *rev) +{ + substring_t args[3]; + 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 0; +} +EXPORT_SYMBOL(utf8_parse_version); diff --git a/include/linux/unicode.h b/include/linux/unicode.h index fb56fb5e686c..724db2cd709d 100644 --- a/include/linux/unicode.h +++ b/include/linux/unicode.h @@ -78,4 +78,7 @@ void utf8_unload(struct unicode_map *um); bool utf8_check_strict_name(struct inode *dir, struct qstr *d_name); +int utf8_parse_version(char *version, unsigned int *maj, unsigned int *min, + unsigned int *rev); + #endif /* _LINUX_UNICODE_H */