From patchwork Thu Sep 5 19:02:46 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: 13792875 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 0AB1FCE7A81 for ; Thu, 5 Sep 2024 19:03:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5DA86B008A; Thu, 5 Sep 2024 15:03:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC76F6B008C; Thu, 5 Sep 2024 15:03:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E9546B0092; Thu, 5 Sep 2024 15:03:31 -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 69FAA6B008A for ; Thu, 5 Sep 2024 15:03:31 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 27587A0A00 for ; Thu, 5 Sep 2024 19:03:31 +0000 (UTC) X-FDA: 82531608222.17.132C813 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf27.hostedemail.com (Postfix) with ESMTP id 7003F4001B for ; Thu, 5 Sep 2024 19:03:29 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=TcaijmN4; spf=pass (imf27.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=1725562913; 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=tVBWjPD7yJZ2Jv4Hj8dGRTMW1PUSv84Vy9Hq+Ex8cOI=; b=tYV4+B9SlCty9V3/tlqPjbKsngcGT2d3e+nKGCtY6o/TAzjFECfdGSaTmd5F6JmIRcnc8F wOEdK2yKcErgpJe0AB6dbZhA+21k6lv9YvSArvkmaW5InzAwrVdGwcurlB/B6fi9BPnaW+ 2mgvbo6k9NLIct5VyZH1nm5WIiQpE3M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725562913; a=rsa-sha256; cv=none; b=uLBJF/toWAqP7NnWB6Lgg6BdOLzrIvidxYRGUcIsSCxfnmFfn5ds2ZD/ZL5jVwK+OXBqZt n974E3Huo8I2ZbXQu6rY+9kl2GTYLc4mA1Qtcd06Aht3eebD31m/jkAbLCipNPecdY0wFI ox4Hnh5pCue52rBmcbEk2RS0ri3YfHA= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=TcaijmN4; spf=pass (imf27.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=tVBWjPD7yJZ2Jv4Hj8dGRTMW1PUSv84Vy9Hq+Ex8cOI=; b=TcaijmN4jyzvbsdVRqO6qPj+vY OPY5Nf7mWWGvh5fEp3M1mdqp/qR9GBJ12dJNPwHFu4XeYq99FxVYg1TpbZcwlhAUdHcFclOQsqWRD HHCcoITUOXgtdWO+WY4nw+67HVcOpJ2P75SXw/yrbFKwN6xJpKmVTHwKQ4/J13LaQBOF699W3Z8ea N6Sne7+xlLjSgWx9A30JetvaDwJZKcSJ1KlGdQkMyuab2UpQzB9L377G4YTy/sxoNXUvZBQddlIA0 NS06H3r8a9FEIMmAXbYaWkk6fbbnFkEZ41HJX4vodT6lpixEyfuF+KXMg7pXZQ91WxIqyzOkUZOdk zvTcfYNw==; 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 1smHlJ-00A6Ho-Lf; Thu, 05 Sep 2024 21:03:21 +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 v3 3/9] unicode: Recreate utf8_parse_version() Date: Thu, 5 Sep 2024 16:02:46 -0300 Message-ID: <20240905190252.461639-4-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240905190252.461639-1-andrealmeid@igalia.com> References: <20240905190252.461639-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7003F4001B X-Stat-Signature: ts7twnmhexdahq5yjp9no4dq3bca4g5n X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725563009-495396 X-HE-Meta: U2FsdGVkX1+83JCgVY/JMIuL26nHl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WlYLh+rJcoboG3wjIsJbJogDRC+BvVHfNxnA5wgNP5/Ypicyaai6zMNTf5BqC+jdDzcptuhk2MZNpf0po3+eJ3GSZtmyqvaiBErEQQUAy6sOqBjHg6eA6Ok5AGBvJO4aYFLfDyunoohHRDFrUBDbnrbJlyWbxcWuQxvDgfsNPJ0IKkcTsuAxjnRT6zOzaMCKZr5ovQJRYkfrW9ulnz7fNJJRAf5JYPmZnHQ6aQRGi/8qBM8mNiRI7V9HEjnE= 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 | 29 +++++++++++++++++++++++++++++ include/linux/unicode.h | 3 +++ 2 files changed, 32 insertions(+) diff --git a/fs/unicode/utf8-core.c b/fs/unicode/utf8-core.c index 0400824ef493..2e852075c6d8 100644 --- a/fs/unicode/utf8-core.c +++ b/fs/unicode/utf8-core.c @@ -214,3 +214,32 @@ 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 + * @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 4d39e6e11a95..f73a78655588 100644 --- a/include/linux/unicode.h +++ b/include/linux/unicode.h @@ -76,4 +76,7 @@ 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, unsigned int *maj, unsigned int *min, + unsigned int *rev); + #endif /* _LINUX_UNICODE_H */