From patchwork Mon Oct 21 16:37:20 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: 13844441 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 68DBED15DBC for ; Mon, 21 Oct 2024 16:38:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DF706B0096; Mon, 21 Oct 2024 12:38:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 917FE6B0098; Mon, 21 Oct 2024 12:38:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7917C6B0099; Mon, 21 Oct 2024 12:38:00 -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 50ABC6B0096 for ; Mon, 21 Oct 2024 12:38:00 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7FDF2AB04B for ; Mon, 21 Oct 2024 16:37:29 +0000 (UTC) X-FDA: 82698165606.01.8A9374E Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf28.hostedemail.com (Postfix) with ESMTP id 72766C001B for ; Mon, 21 Oct 2024 16:37:43 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=TWyfiSiM; spf=pass (imf28.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=1729528628; 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=f0Y7Y/uPKqBCqjpYYwcqgiCfV5r72iZCst4Cn1CiEyljPZVo91WBLRFBe7eTROwxmoWe/o Z7q80EUOttafEKK5p60oilxCuQVK7g8sLmBcQAB/FviY9VyHomh1toWni+vWRWcwzceVDD TvDDFISNlKRioz9Qtd1tCvuh0eV9bcU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=TWyfiSiM; spf=pass (imf28.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729528628; a=rsa-sha256; cv=none; b=IGKb4Xa4UWUGuKv8LLrUvKsHygdoA5T05kvfBOHZiNCegya7m6SKhYl60GJIHP60K12um/ 7+AfoB9yLv+n+3PjXHIubQ96BqTlb2zzekZfNdjlE8vxApxL//urAqc3hVqdP+i4XfGf3J hH1B9n1mkHLvju7/ZlAWRs+6CQ/7xHY= 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=TWyfiSiMpn2JY+LAKRTmhYlWm0 ctHt/AVzOxuRttTp1AjNMOv8enBzWmA/p0TaQJBuTdFZTN3bH0P/LlKL2UzpIqu1cJJescJqSlQtw FjGjK+HFZ0K8aXxXh63UIjs4icp1ME5rw4sXMVwMZvcTvbbRApgXEqqATGFCekTNnRmakbdodbfv9 ZAsvZI3iSsDSEmgCa6fdNlbMkB9tDqjqFJFF+/byI9/Zj/IueginCoUSXBYTHQApbzfG+L0VEW6me LloWvz/NEwxuQognsc29f3R/4/h90YVP0wjNItE+1r9uzMKRgZjUQ0Kclk6q7Ci5lnnqH5+ydInM5 riVbX8WA==; Received: from [191.204.195.205] (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 1t2vPo-00DECf-2D; Mon, 21 Oct 2024 18:37:56 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Mon, 21 Oct 2024 13:37:20 -0300 Subject: [PATCH v8 4/9] unicode: Recreate utf8_parse_version() MIME-Version: 1.0 Message-Id: <20241021-tonyk-tmpfs-v8-4-f443d5814194@igalia.com> References: <20241021-tonyk-tmpfs-v8-0-f443d5814194@igalia.com> In-Reply-To: <20241021-tonyk-tmpfs-v8-0-f443d5814194@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-Stat-Signature: ejgpe7yh1u9nec7j5ufuwnhjfgayhzcp X-Rspamd-Queue-Id: 72766C001B X-Rspamd-Server: rspam11 X-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axuZPsUrodQpXu0hGMg1FXsi8cwjiC0ghn2adswo/a6jxkiE3pECocpCsA9nBYxhq13VyESNQA04PKg/2PhsGffynxnMcXBPIOTTA1v3+/pBg0wjEwqxHr20xbyMjnTnrw0pN6zSRo7aCiYXT0O3ppxt0AZpLApuz+2o9uJjEaB3Tkw8O5sJZtaE9SrZ/0phQ14uSn01Enad4AjMXv4vwQB9//R3AnANxXdm0mlnUv51MQOBA19wruR1JDcAEjkPY1OpMK5Qqn9eP0ZhmXYQUiwnTICpYGQtcmYts6v/Z1vbpgtn2XKU+lbkyunsQ2WcyQByrVK2vEsgCW8Mx/4FO/7duaOn1eX1/bYG6/i54otFyftCnw8uaKvau6VP+1Eid0oP6odgkD7bhMw= 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 */