From patchwork Thu Oct 10 19:39:39 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: 13830983 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 CBBF7D24447 for ; Thu, 10 Oct 2024 19:41:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2AF5F6B0089; Thu, 10 Oct 2024 15:41:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 261786B008A; Thu, 10 Oct 2024 15:41:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1028C6B008C; Thu, 10 Oct 2024 15:41:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E3B396B0089 for ; Thu, 10 Oct 2024 15:41:31 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 561F31A046A for ; Thu, 10 Oct 2024 19:41:25 +0000 (UTC) X-FDA: 82658711982.21.484314E Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf07.hostedemail.com (Postfix) with ESMTP id 789904000E for ; Thu, 10 Oct 2024 19:41:27 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=DAwZ5BTr; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf07.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728589138; 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=xvtpXgeaP5+3Qey4SeTiBPWN2JmcKdnKWOsB+lrnGJo=; b=U8MuxS9hRY8PT2j0fweP/Mxx5ntKviWVYKOJtD1VageOK6kTJv7IYqzQO6rZlCu0IjNA7w ad10ASzmFNVWdRJciEMStLp8Rp6Ty/m8oq28H6261Di9fRe/01+TmP5pcyocuHzV1YKzIq IwwqDG3URQOpALPb5EGP2aFzWQbLtzs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728589138; a=rsa-sha256; cv=none; b=szLM0ugTZGRKhaNBsPwBeJBkBdaQBN5R3h52QXy97W9ghr97ChLhIvXVNF7g05QLTNXITf w2eG22qHErMYnfwISDXgfOAMeO6jsjkF3x9W2Fn5JpC1zKIWsMucK9ALak1UCkr1w1LA9Z X1BMMryY6FkYkpquq4UG8vxlpdg1G+k= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=DAwZ5BTr; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf07.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: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=xvtpXgeaP5+3Qey4SeTiBPWN2JmcKdnKWOsB+lrnGJo=; b=DAwZ5BTrIxiW5InqyottPfBJ6H GOXT5VcX3s+KAchFmfi/4sOsDev0Nd6Wjml60PP2IP+OqHdXhJsk3obIdbu9VBk5Uo0ud+8+MVW4O qQecqteTmktYmhDBsFkHZqESd8rZ3wofZeMJTkXdN4AFjU95K4g3H7rz3YGMqRFj3W8PTPGMtkKHP N3Sr7D900/vDB9fM/xwTYhr32dyJiEBcmxx//4MIPAkAN2Dm5A1sT9lL4o0+NDjmbNT62tfUSJVvq kaj1lZQkAIhaY2L2XYTzy3A4uck3TW56R9Lu1Rpw+bmoUBUTy032CVfBydcIb0tO2eTES/dkAeyf/ VGG7orQQ==; Received: from [187.57.199.212] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1syz2C-007SHz-CH; Thu, 10 Oct 2024 21:41:16 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Oct 2024 16:39:39 -0300 Subject: [PATCH v6 04/10] unicode: Recreate utf8_parse_version() MIME-Version: 1.0 Message-Id: <20241010-tonyk-tmpfs-v6-4-79f0ae02e4c8@igalia.com> References: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> In-Reply-To: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> To: Gabriel Krisman Bertazi , Alexander Viro , Christian Brauner , Jan Kara , Theodore Ts'o , Andreas Dilger , Hugh Dickins , Andrew Morton , Jonathan Corbet , smcv@collabora.com Cc: kernel-dev@igalia.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Almeid?= =?utf-8?q?a?= , Gabriel Krisman Bertazi X-Mailer: b4 0.14.2 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 789904000E X-Stat-Signature: d3xi3jkt6ddfa19do4odja6wtnbz1hrg X-Rspam-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JeMGT8HjKnVXW2+B1GFoZWYCGLHYGd8DVLrqgdmX5Mw7C9Tx2uUW2Cou6hHlvjgwxnk8AEHR3jzuT/Fb0r5zfxeP+pdpYCvfwoyjCFFjRl7avxUwKlHCNDsfJbxzHNY+rNhrbRxO6JUNHaTpvXX2vH9X9J+/esYI2WpDHOmzSN7fLVjy5yWvQDByCLWgL0OejgECu5d5Q+9/loYza2fNxh6r5MYjnTeThxC2tJXp36hjnFiP058zthLbTzMQ3J4PVmT3bD6S/CNXsOb27fBOzRngFdJdrlsPrzXefIEDXAn432koRa8inAFJ7UFwwxA7d0h++NsGz8/+D1q 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 8395066341a437d0c20d6ab49b0a022eac7eec5c..7f7cb14e01ce8aa87d14dffdd767f63a90cf11f7 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 0c0ab04e84ee80227f9390ad0498f21a7ab7d34b..5e6b212a2aedab7ebf4363083339f4c5e9b82f8f 100644 --- a/include/linux/unicode.h +++ b/include/linux/unicode.h @@ -78,4 +78,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 */