From patchwork Thu Oct 17 21:14:14 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: 13840842 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 B3A5FD3C537 for ; Thu, 17 Oct 2024 21:15:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F1226B008A; Thu, 17 Oct 2024 17:15:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A0B96B008C; Thu, 17 Oct 2024 17:15:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34B866B0093; Thu, 17 Oct 2024 17:15:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 15D2D6B008A for ; Thu, 17 Oct 2024 17:15:22 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9C043C13D8 for ; Thu, 17 Oct 2024 21:15:09 +0000 (UTC) X-FDA: 82684349412.20.3B5344A Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf15.hostedemail.com (Postfix) with ESMTP id D3834A000C for ; Thu, 17 Oct 2024 21:15:09 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b="Ch/ina8f"; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf15.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729199672; a=rsa-sha256; cv=none; b=ywPdyVvNqILXHF5sygu13tbNWfcVE9d5UyoAA9cWS3iu/HTWUq+Ni4VfjSoSQG6QVDs2Rb zet6jyXw16hJmCm/bWzZij3FhpVv6atuJZQWfd5TGMHe7mc1ykCf6d4RfQeZXDK3eI4M5r WETjhOwqEmaTnjBiH8uZrcX6JSWLtNE= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b="Ch/ina8f"; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf15.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=1729199671; 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=3ku7uHREd9TqwUoNgzm9qg5Yozv8tHKkG1t8H5hSVpQKEZVpX9QtmSg7/aqYReFmg5qXG3 r1+vneYkOWQ+aOAyIIMXoIKJNGCdGmiSAsFu8Ssvs9bT0tV7PFxGVQuaM6QV6TUmSgxdq6 nGVTyHHGuC77AlzsYzjmjF5KoRoD1Ps= 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=Ch/ina8fAml8InT0NVCX2DBY8h pa6eegyvu0qxYudH8yTysmj3p4gd31TtL9/xp3NxbgchJT+eo+GlC9YBVP3ABWpiH+glVwMbz65Cw xbelbkrCShVcpQluewnb3W2K1rRHvwayLGRPJCRV+41KO7Ia8Iy+SAdastYYvqgFwPcnswfaD6owN 7RgtrPBiqAdTnTaJQ/rAqvgXL3Yiy8W1Ym1HQJfsF8M3JpjFFrx6Lwd6e4WS9l/ydo7HHxqaErBbb BACW6ehubHrqCdeucIisxBtMssjQBfeHg9rNV8elevORxoa9M4yqSdFdtLyG0+11Bh7F4qP+UMK/g ZMN4WwbA==; Received: from [179.118.186.49] (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 1t1Xpj-00Bnlc-Cp; Thu, 17 Oct 2024 23:14:59 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 17 Oct 2024 18:14:14 -0300 Subject: [PATCH v7 4/9] unicode: Recreate utf8_parse_version() MIME-Version: 1.0 Message-Id: <20241017-tonyk-tmpfs-v7-4-a9c056f8391f@igalia.com> References: <20241017-tonyk-tmpfs-v7-0-a9c056f8391f@igalia.com> In-Reply-To: <20241017-tonyk-tmpfs-v7-0-a9c056f8391f@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-Rspam-User: X-Rspamd-Queue-Id: D3834A000C X-Rspamd-Server: rspam01 X-Stat-Signature: ogk5krmp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LjyTaD6Dy5NqTJgE+jsPOPz93Ocjeo7L1wsrfoXorQXkRl7zjyrCq8PIRkiZmgghQIlQeLngUAuy99l/xKJuGf5LjOS7vQMMZszMJhRzzTGTg5r8kGMg72aYoRSlKeapcYmvrInqPGooDK5HG0Wf2wZZoTVgExLohdUB+HSUl0Wz9ihLjNRo+iQyKC3lXnRX37frtkkZQQuh9BOV/XIYmBSqjww0stFsHRVl+3/7ig49kMFgZky/Ys5pAjpDJxoA+MlVvSK2UvQr+DD3RyyvvZpV9LVhqYpMjc40EvGxtYvXymklvS2NA3788sfING+5Tkl9V7/rYqMnX+2vSBsCqdNxl7mVeIvHd8ed+/JCV/3EppyVhgEZReqHrk3SBDev6eThF3Wjbo61vkd0eu3ClaMgFD+lDMo8c= 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 */