From patchwork Wed Oct 2 23:44:38 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: 13820557 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 15546CF8547 for ; Wed, 2 Oct 2024 23:45:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A87846B04EB; Wed, 2 Oct 2024 19:45:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A37D96B04EC; Wed, 2 Oct 2024 19:45:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9006C6B04ED; Wed, 2 Oct 2024 19:45:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 67DE56B04EB for ; Wed, 2 Oct 2024 19:45:26 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0E64B140C5C for ; Wed, 2 Oct 2024 23:45:26 +0000 (UTC) X-FDA: 82630296252.11.7D94622 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf08.hostedemail.com (Postfix) with ESMTP id 5C14116001C for ; Wed, 2 Oct 2024 23:45:24 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=rEN9q944; spf=pass (imf08.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=1727912553; 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=HCbVqueHUmSSCcT+A2gsLYEdLj0anlbi7vfWbqjQz7g=; b=gutwd4V1TBJkkEdGYQzYjgORtBy376QgGdpMQwFiudlJlT/hUDZU0A7D8kJzU1tQwRX1Xt S1AMC+goAaGBjgA4apUowJR9jtgVAMrddBM2Bi56Zi1PraeNRmJyL5gpgFnp9p9mHcu+Hx XsRz0kPmli9QUQJr3QiTsWtfbCDo11c= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=rEN9q944; spf=pass (imf08.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=1727912553; a=rsa-sha256; cv=none; b=lltAnJkAyahWqEZ4F+LGpsiANYLDobKyNk6263/WlUI3f1Sx9amyMKBf4vYDI5ciCPvnPs X5pcqDaS9iLNIDxbk41gSYJsgUFtZMW0o0sAows/pw4Tkqt1UiOYvvY2hrHAIAjkMpuC/0 cvl7JSXD+Iaxi6kxQWsdqYOlMIseQtc= 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=HCbVqueHUmSSCcT+A2gsLYEdLj0anlbi7vfWbqjQz7g=; b=rEN9q9445fHCa6+Cu5k/ZNfA6l rUVf5HN05YiPW6LBeSVDHVW4yadCX1//v6PcFQTA/Mu90qZhR7Kx2QsPMNbrNzyHSUt4N8NcoKeY7 WDaRV9YyJxmiKIQKzgH4Tqf6xY2PfLxyrL1xu+3E+lHnOktCjoFwrwW0u+T+Dm6IIp3tyD2xekUbA ppP90YeCpxXhbXEgPg7bO0JT0sxAzzCV9SfZH9N9JKBfMt7feJ+oUh9ehxpd5ETYEhNy9ULePV+4s oCrLHrmwF0ZREkJLY1US/OZkYXFek93sSO42K+dxBJIzW+OHd0L33CVG8dyiqCs0qBtz3j5HTqmPQ O0FJJMEQ==; Received: from [187.57.199.212] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sw91w-0045tc-Bz; Thu, 03 Oct 2024 01:45:16 +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?= , Gabriel Krisman Bertazi Subject: [PATCH v5 04/10] unicode: Recreate utf8_parse_version() Date: Wed, 2 Oct 2024 20:44:38 -0300 Message-ID: <20241002234444.398367-5-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002234444.398367-1-andrealmeid@igalia.com> References: <20241002234444.398367-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 5C14116001C X-Stat-Signature: wh3kq74197wkwkwb6n6nog8huc7boum9 X-Rspam-User: X-HE-Tag: 1727912724-382732 X-HE-Meta: U2FsdGVkX19mBzmV4Vawp4lZ2IcO6ho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Lh5UBIXnSYNfRgwuXsuyeEXBwN+PN9iVSHlfFkEZweWj7nqMLMv5YRDB3TTQt6zslNVrBNd/cxB0AMh7YrXdD6A3ONQdakhwiyY+o7fCOtUmLsXX+o7FyoYOWbgvtR2f7RNtWoJxblSZz6RXGxyLHCHr5Q4dPBt6TpNzNlNSUGwt5E1lHCPG/2JDCsnXfXl+5wxGMQmjeVGJVU6enbXBE5Asy6HWlAf7nyGHFA3Cbl2HGIlihwIW/N8s+wO5WUVnSqm39Ta 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 0400824ef493..6fc9ab8667e6 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 0c0ab04e84ee..5e6b212a2aed 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 */