From patchwork Thu Sep 5 19:02:44 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: 13792862 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0366417B4E5; Thu, 5 Sep 2024 19:03:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563014; cv=none; b=icMjfLKwBJJKPy3a4SCSGiiBo5rcQxHRPnrsg8liaszhgRAYnPnwqkgl+vZc3CShFH1XkFrVuvr3Qg/bT8dNEHYACGx/XGvFVzpeCAv0voJWVxlcYHXx9ggy6d3hk8EbjDiNfYT4Lu6LQ16ZleJx/rFcsKs1hKogqNg0tHJH4qM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563014; c=relaxed/simple; bh=JDDkfI5C/SzSPFtrnIr+Hv41Z4nJqWVVuGXk4VwNw9s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kARimN80JPIczCK4CoFIzZz0DALsd0yxCjj5igdRO4bOB+FQVL2GdDOrJf0SCZYSzx+BdIjhmaCNYc8nu6xqPX93j1L7eTIEZPsL7ND2BrOKGV1VJct4LjcJgamy5b7MRmywUv/pFNmXS3XUlsWFFDD4zioJctXsroosLrF/xEw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=llqAOrn8; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="llqAOrn8" 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=h3G2XLqID4r09rjc35sdSginc1+HQQOMXWwkAOpIqMQ=; b=llqAOrn8aL/qw69Wg5Ra8y+wWf JLvgMbLeG3fwUBfMqFMmxHUELEAwb/yKdLG0s7cwIM5u4hZ13DlnJ3Ne/o4dwd9YZRgmgi2JzUx0+ mKs2y/95FRbJkp4LA8WSU3G0MbiWhpFC2f6L2xY58X8km4ymyWjgVdTf3u9W/Cq0WqxPpS3GocjmJ 8eCWm9E5alS7ndthRRXK2xtzcPfSC3WqQKLufJAK9sr/4gOlF7irUB142rbeNm/5YK4zMYdHz1kPP C9UA87nr22EpbXDm1BhI1GM4C1oTQZLhwaxqOIlqOMDyLfo3ZL6DtOZeLTSzJfra76MOjXt/5CRiI wQid+hrQ==; 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 1smHlB-00A6Ho-3O; Thu, 05 Sep 2024 21:03:12 +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 v3 1/9] libfs: Create the helper function generic_ci_validate_strict_name() Date: Thu, 5 Sep 2024 16:02:44 -0300 Message-ID: <20240905190252.461639-2-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> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Create a helper function for filesystems do the checks required for casefold directories and strict encoding. Suggested-by: Gabriel Krisman Bertazi Signed-off-by: André Almeida --- Changes from v2: - Moved function to libfs and adpated its name - Wrapped at 72 chars column - Decomposed the big if (...) to be more clear --- fs/libfs.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 1 + 2 files changed, 39 insertions(+) diff --git a/fs/libfs.c b/fs/libfs.c index 8aa34870449f..99fb36b48708 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1928,6 +1928,44 @@ int generic_ci_match(const struct inode *parent, return !res; } EXPORT_SYMBOL(generic_ci_match); + +/** + * generic_ci_validate_strict_name - Check if a given name is suitable + * for a directory + * + * This functions checks if the proposed filename is valid for the + * parent directory. That means that only valid UTF-8 filenames will be + * accepted for casefold directories from filesystems created with the + * strict encoding flag. That also means that any name will be + * accepted for directories that doesn't have casefold enabled, or + * aren't being strict with the encoding. + * + * @dir: inode of the directory where the new file will be created + * @name: name of the new file + * + * Return: + * * True if the filename is suitable for this directory. It can be + * true if a given name is not suitable for a strict encoding + * directory, but the directory being used isn't strict + * * False if the filename isn't suitable for this directory. This only + * happens when a directory is casefolded and the filesystem is strict + * about its encoding. + */ +bool generic_ci_validate_strict_name(struct inode *dir, struct qstr *name) +{ + if (!IS_CASEFOLDED(dir) || !sb_has_strict_encoding(dir->i_sb)) + return true; + + /* + * A casefold dir must have a encoding set, unless the filesystem + * is corrupted + */ + if (WARN_ON_ONCE(!dir->i_sb->s_encoding)) + return true; + + return utf8_validate(dir->i_sb->s_encoding, name); +} +EXPORT_SYMBOL(generic_ci_validate_strict_name); #endif #ifdef CONFIG_FS_ENCRYPTION diff --git a/include/linux/fs.h b/include/linux/fs.h index fd34b5755c0b..937142950dfe 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3385,6 +3385,7 @@ extern int generic_ci_match(const struct inode *parent, const struct qstr *name, const struct qstr *folded_name, const u8 *de_name, u32 de_name_len); +bool generic_ci_validate_strict_name(struct inode *dir, struct qstr *name); static inline bool sb_has_encoding(const struct super_block *sb) { From patchwork Thu Sep 5 19:02:45 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: 13792864 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCB1617BEB0; Thu, 5 Sep 2024 19:03:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563016; cv=none; b=Do48L/Xhblex4Ngf0bka7zEQimWgRAUYYzK2ABCdHlLPVbjj3odlgfBFekni6cNOFgN9ljlpGDoZPlDOY982Ca3C7btjmskU/qze58BrT0hBorXX8BuhYgFjWjVxtHgarQynDrfoLkIEn5pLwqJtMUDGq73cFHoSk/w471e85L0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563016; c=relaxed/simple; bh=0taofh0Xk8e/xFeBuR+ZJrAFWG6Ywq1ifG5UXMsoJA8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=N7k0vhgKmXpBcJHH7grBNDA/Lw/sxn613j3IA6Z656Yjnh4H9JLPoP3qMdP1TYot5rGFxiWYuzzGScLCoeZZUg+kq7FYO97iBonO+duf4gtbFaxz5nr0XxLxGkzlrSn+Z0ASMnLeTeU8MqTWxMqmkJHjG0fiNlt0THgPIovVWno= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=k+yEejC8; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="k+yEejC8" 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=kxZabVtRIbsH5N40Gr/wp92cNKF1pfI7iuz0Er/EL18=; b=k+yEejC8Dmzzln9UhjVHcqVDCI U7faXjakSc/T/yJDWuATyjA6gekduJAOI1X9dqJVLke+YO2Cei9IR3XGwRAEXF1dJdJqQMqnJSqj4 IoNo7I8bJ+bp9s7CnWz8r9cyeOKWbx3NxipIJBcCURjTwl0so8rsLAMokS2bfXijHvkhlpGhxcohD XRp2OljVJlDaM+jjAi3iXWk/ZOTML8RaKnJevj+8BuxAxAJA0u+TzHHrUUxANXsbhBe9CHTMXBpiQ GtPqMmi+2k5jXIQ2N+u25g8aOBRov4Va8z+FkguqaHqHipidIdrHf6w+TEC1BV5cjahvsll5aES/2 YbosNfjw==; 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 1smHlF-00A6Ho-GC; Thu, 05 Sep 2024 21:03:17 +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 v3 2/9] ext4: Use generic_ci_validate_strict_name helper Date: Thu, 5 Sep 2024 16:02:45 -0300 Message-ID: <20240905190252.461639-3-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> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the helper function to check the requirements for casefold directories using strict encoding. Suggested-by: Gabriel Krisman Bertazi Signed-off-by: André Almeida Acked-by: Theodore Ts'o --- fs/ext4/namei.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 6a95713f9193..beca80e70b0c 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -2394,8 +2394,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, return -ENOKEY; #if IS_ENABLED(CONFIG_UNICODE) - if (sb_has_strict_encoding(sb) && IS_CASEFOLDED(dir) && - utf8_validate(sb->s_encoding, &dentry->d_name)) + if (!generic_ci_validate_strict_name(dir, &dentry->d_name)) return -EINVAL; #endif 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: 13792866 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 809B618D650; Thu, 5 Sep 2024 19:03:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563018; cv=none; b=Y/BYc/EkUuBGTw/fiRcBboVlyp5gls6yDxOm1Cl/7hk5vSYopB6zeteTI3Bh0//LDrV55gaH8P0VMbeKCyOpqFvHEPaCnzlxm4P9748DmEaiW7NHBuvoXmE2GSTCxxSOcPNUFkVWX4HPFHMTjDeCu2xMPQkfy2Mv5DSQhOEmJfQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563018; c=relaxed/simple; bh=ksiaxLkhvshrSVdbEgdTEeMtxc2jAfYrInCIWeLRs5M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VqVQ2I2XYP+l9pm7JIhCLjlezczSdEwUGSkYNB9QLe3fS7y6OJlefzFa35tDQ+WzUYy36/wfKmyBkbKQytsU9GssFo3iA6dt+doWoJbHRu557Du8tFlUVia8ZLfSENwdFZPB57BCDxQA4r0rN5sg39glRO/YDmaGCsOokPFszPU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=TcaijmN4; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="TcaijmN4" 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> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 */ From patchwork Thu Sep 5 19:02:47 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: 13792865 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCACB17B51A; Thu, 5 Sep 2024 19:03:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563016; cv=none; b=JkaiMTHnbv+xlUZLkGURAx7e532lv1Q0653Gis02Tm/jNavCHpGwhwZ0+ZyUuK3oRCJyS7+/2KxX2TRxzJUbhM5pzCqsy+zlm/u4+6X5ndG1w6sV/bYrkXbmyUbP00bR2jg2y10lb9KS4RY6X803BhlQsGKmC2qPc29TJupu9Ps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563016; c=relaxed/simple; bh=0ayzV8+fDZpvGn5mEUT1XYCyH/1u2eCNInzpL2N8O4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TcBuP5d5qwQ5PnDVwUS5AXyIGGue/RkAbIHEj3TvzCOu9H+M3JUa+dTT7pfgpB9Zu/nuHtHhe4v67POJOTunhXfVlJ3EgPhO76/YP86CNEW18rRRyNOoXK4RMmi3MDz+584bKLuGwy1nfuAuIFvdmPcSJHy44+LeMRDJ6MFFVzk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=hbeKl1QT; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="hbeKl1QT" 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=7BUAvvMuRU2tfo2IDkqAEnh0rC165iKKlWi/Zf6qiA4=; b=hbeKl1QTRIQB74KvSycQ2F2ZFI 6EfPYPIhY/kDzNhC98wdLPBaxCUHGO7YQWeSRu206BRnRY4OziReMSFa9WRpaSTikBw7d2jXLjfwr nTprejKDeitM+tSIEZhx2fICW04IwmW+fU43Zj738ANKXAnWQOgAZGu/wevvHpNtkqgvIVwpWgBLZ ZdqWoBif0OlbIyaMHRLkuCGA/93cKu/Is6K/FZyIKHbUW5sbcDVaAzQttKFFePbOWeMf/SGsQubuk g3gaYQ56XbCJ6j0nXmDVsOxjwOAJDtg+1amttVaH0F5VvFc65s2ObC6W5W2m8zfdlLd7ncHFNieAE HSjJ+DLQ==; 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 1smHlN-00A6Ho-RC; Thu, 05 Sep 2024 21:03:25 +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 4/9] unicode: Export latest available UTF-8 version number Date: Thu, 5 Sep 2024 16:02:47 -0300 Message-ID: <20240905190252.461639-5-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> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Export latest available UTF-8 version number so filesystems can easily load the newest one. Signed-off-by: André Almeida Acked-by: Gabriel Krisman Bertazi --- If this is the accepted way of doing that, I will also add something to checkpatch to warn that modifications at fs/unicode/utf8data.c likely need to change this define. Other ways to implement this: 1) Having a new arg for utf8_load() struct unicode_map *utf8_load(unsigned int version, bool latest) { um->tables = symbol_request(utf8_data_table); if (latest) { int i = um->tables->utf8agetab_size - 1; version = um->tables->utf8agetab[i] } } 2) Expose utf8agetab[] Having utf8agetab[] at include/linux/unicode.h will make easier to programmatically find out the latest version without the need to do a symbol_request/symbol_put of the whole utf8 table. --- fs/unicode/utf8-selftest.c | 3 --- include/linux/unicode.h | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/unicode/utf8-selftest.c b/fs/unicode/utf8-selftest.c index 600e15efe9ed..5ddaf27b21a6 100644 --- a/fs/unicode/utf8-selftest.c +++ b/fs/unicode/utf8-selftest.c @@ -17,9 +17,6 @@ static unsigned int failed_tests; static unsigned int total_tests; -/* Tests will be based on this version. */ -#define UTF8_LATEST UNICODE_AGE(12, 1, 0) - #define _test(cond, func, line, fmt, ...) do { \ total_tests++; \ if (!cond) { \ diff --git a/include/linux/unicode.h b/include/linux/unicode.h index f73a78655588..db043ea914fd 100644 --- a/include/linux/unicode.h +++ b/include/linux/unicode.h @@ -16,6 +16,8 @@ struct utf8data_table; ((unsigned int)(MIN) << UNICODE_MIN_SHIFT) | \ ((unsigned int)(REV))) +#define UTF8_LATEST UNICODE_AGE(12, 1, 0) + static inline u8 unicode_major(unsigned int age) { return (age >> UNICODE_MAJ_SHIFT) & 0xff; From patchwork Thu Sep 5 19:02:48 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: 13792867 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 047A81A42CF; Thu, 5 Sep 2024 19:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563020; cv=none; b=I5GtCV4hoox0vitauPgMy6V9OV/ol8FZGhgCdpsYbf3+pxC96S7KgRkNPzJDbKeyDHfG1Qu/DhMJK/KdIVc/aJ+QmxvQ8I2fDPtTVUNs8CuPWK1f0CeRJoFR71c9pIP/76pVG7262YQP3R6neLJung5hITtDIbMp3u6WRXh2woc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563020; c=relaxed/simple; bh=NYPZXgW6W7ny5HpwNbFP+O9dac2B0P2JjYmVcM4MlQQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=um6fG9t56tpE3E5kM1CuW+xs+OPGfj5FQReL/jU3+7S+1bW6PPLwKFo5juiseS5XCaoboEFhzbyONt9o3W6TJt8cZlA+8hjxfRl5GgqEo27ZBA1q2yOJtM3TNVFE7Qn6FYiJXVCYDJHip5lJnmLfTT6KBJ8EF/yftI4JCmHhdUo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=ZJghaA+j; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="ZJghaA+j" 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=09RjlXQlRYkuU224DyyX5hGaeh4dLRLLtcX5SDFSDN0=; b=ZJghaA+jVI7xvLO2YziWNskShX 87LUA2XkYooq3bZPKGSoYD5tloKq2MclVlntxHJslHNDeKX/iD/K2kgu3XG7t2uqpuHvYQ0ucO82U LliHgq6agb62p0rfBYgMSPxhhwOTW6v/7KOkaSsEmJFamtab29QMCgkORcdXuppFWpcbUr3ki8Faq MblpxRe1NSTRhC6GFxx9xyELWpjdG16psWeoWC4JtoP6doz7bx64aS4/xnZ9/DEz2FHllQXWu0jO1 9WobnQ1AolJBMzYeNRqaF0n5lurCWqveZ7dkrpjdjG93mPG8t6rhDDb+6oDgo6UY8LOENg1igrvzP y+ybT0cw==; 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 1smHlS-00A6Ho-0W; Thu, 05 Sep 2024 21:03:29 +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 5/9] libfs: Create the helper struct generic_ci_always_del_dentry_ops Date: Thu, 5 Sep 2024 16:02:48 -0300 Message-ID: <20240905190252.461639-6-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> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Create a helper to assign dentry_operations with the generic case insensitive functions plus setting .d_delete as always_delete_dentry. This is useful to in-memory casefold filesystems like tmpfs. Signed-off-by: André Almeida --- v3: New patch --- fs/libfs.c | 15 +++++++++++++++ include/linux/fs.h | 1 + 2 files changed, 16 insertions(+) diff --git a/fs/libfs.c b/fs/libfs.c index 99fb36b48708..58b39640b686 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1855,6 +1855,21 @@ static const struct dentry_operations generic_ci_dentry_ops = { #endif }; +/* + * Same as generic_ci_dentry_ops, but also set d_delete. Useful for in-memory + * casefold filesystems. + */ +const struct dentry_operations generic_ci_always_del_dentry_ops = { + .d_hash = generic_ci_d_hash, + .d_compare = generic_ci_d_compare, +#ifdef CONFIG_FS_ENCRYPTION + .d_revalidate = fscrypt_d_revalidate, +#endif + .d_delete = always_delete_dentry, +}; +EXPORT_SYMBOL(generic_ci_always_del_dentry_ops); + + /** * generic_ci_match() - Match a name (case-insensitively) with a dirent. * This is a filesystem helper for comparison with directory entries. diff --git a/include/linux/fs.h b/include/linux/fs.h index 937142950dfe..254a1dcf987b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3337,6 +3337,7 @@ extern int always_delete_dentry(const struct dentry *); extern struct inode *alloc_anon_inode(struct super_block *); extern int simple_nosetlease(struct file *, int, struct file_lease **, void **); extern const struct dentry_operations simple_dentry_operations; +extern const struct dentry_operations generic_ci_always_del_dentry_ops; extern struct dentry *simple_lookup(struct inode *, struct dentry *, unsigned int flags); extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *); From patchwork Thu Sep 5 19:02:49 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: 13792868 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CA481A7279; Thu, 5 Sep 2024 19:03:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563025; cv=none; b=gaLG+2uYXsKxe47hIkcdiWuerabQzr6wp4oGjJb/A4WZZFRRI7jIPikyarG45hyBXSixXD3L9QGL+BtJEHSKjHJNEjXznphuZau954+8o+LzF1yLKZyV5zcX19/2dwUMnCQx57oy6jwCQqC3H+1Qwot1krRdnVRfhzJQx/QW+ew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563025; c=relaxed/simple; bh=nHowrrVHa+XhQ3FqfDk+/Gjl455uB5B4EGoL0f3auUc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZE/mbRl9KQ3wuoAISCNWqb8JSUqPxXIYX4BTTp08FD/3WZ6GcWhr8dawVJRncU0lVcLR/y2llcYzO5x24sBX+w0l2tYdBqQiTxVTWlbw2ZeQ7jCEnkWt9SevKdGADXDIhIB6t9IrtW5NVdhvCcyTuk/Lvf3CMYdtht4RNl4E8EU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=Gwu+S2WV; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="Gwu+S2WV" 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=VmzlgsaYZjrrC3mQ36z6wkF/DubU3LiA5Bepzx0864k=; b=Gwu+S2WVVmZsGxvWLl052l/1q2 ltwU0NqVeVAHvuF2fa+ccjSMlRW1/+fl/1eN/6Uhmtl2GytsBpiHQtvU+Oow+lRmw65qbc37/GLKI EpfNSdteKTgZS9kAcMhehkpSuoXX9gcHHBNXH0pxrFmsdQbyf2ZHXfKfhqINt/lQTFvVmiXHH0im1 mI7rw2jvvohjfLB2GOI8sGUNPd08QRa1z7/FtLFANYvOrN4/29SG5zO8iyDvzVYhkoJ8l2Fj8qZEX ig8krXC81tItgy+rPSU/ButQMUqhAvqdhIW6l+kaVSFoNMv1PQvhQ2S5wntStcW/+6g6fzYWRczK3 0fHuQOpg==; 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 1smHlW-00A6Ho-6D; Thu, 05 Sep 2024 21:03:34 +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 6/9] tmpfs: Add casefold lookup support Date: Thu, 5 Sep 2024 16:02:49 -0300 Message-ID: <20240905190252.461639-7-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> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Enable casefold lookup in tmpfs, based on the encoding defined by userspace. That means that instead of comparing byte per byte a file name, it compares to a case-insensitive equivalent of the Unicode string. * Dcache handling There's a special need when dealing with case-insensitive dentries. First of all, we currently invalidated every negative casefold dentries. That happens because currently VFS code has no proper support to deal with that, giving that it could incorrectly reuse a previous filename for a new file that has a casefold match. For instance, this could happen: $ mkdir DIR $ rm -r DIR $ mkdir dir $ ls DIR/ And would be perceived as inconsistency from userspace point of view, because even that we match files in a case-insensitive manner, we still honor whatever is the initial filename. Along with that, tmpfs stores only the first equivalent name dentry used in the dcache, preventing duplications of dentries in the dcache. The d_compare() version for casefold files uses a normalized string, so the filename under lookup will be compared to another normalized string for the existing file, achieving a casefolded lookup. * Enabling casefold via mount options Most filesystems have their data stored in disk, so casefold option need to be enabled when building a filesystem on a device (via mkfs). However, as tmpfs is a RAM backed filesystem, there's no disk information and thus no mkfs to store information about casefold. For tmpfs, create casefold options for mounting. Userspace can then enable casefold support for a mount point using: $ mount -t tmpfs -o casefold=utf8-12.1.0 fs_name mount_dir/ Userspace must set what Unicode standard is aiming to. The available options depends on what the kernel Unicode subsystem supports. And for strict encoding: $ mount -t tmpfs -o casefold=utf8-12.1.0,strict_encoding fs_name mount_dir/ Strict encoding means that tmpfs will refuse to create invalid UTF-8 sequences. When this option is not enabled, any invalid sequence will be treated as an opaque byte sequence, ignoring the encoding thus not being able to be looked up in a case-insensitive way. Signed-off-by: André Almeida --- Changes from v2: - shmem_lookup() now sets d_ops - reworked shmem_parse_opt_casefold() - if `mount -o casefold` has no param, load latest UTF-8 version - using (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir) when possible --- mm/shmem.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 138 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 5a77acf6ac6a..6b61fc5dc0b1 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include "swap.h" static struct vfsmount *shm_mnt __ro_after_init; @@ -123,6 +125,8 @@ struct shmem_options { bool noswap; unsigned short quota_types; struct shmem_quota_limits qlimits; + struct unicode_map *encoding; + bool strict_encoding; #define SHMEM_SEEN_BLOCKS 1 #define SHMEM_SEEN_INODES 2 #define SHMEM_SEEN_HUGE 4 @@ -3427,6 +3431,10 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *dir, if (IS_ERR(inode)) return PTR_ERR(inode); + if (IS_ENABLED(CONFIG_UNICODE)) + if (!generic_ci_validate_strict_name(dir, &dentry->d_name)) + return -EINVAL; + error = simple_acl_create(dir, inode); if (error) goto out_iput; @@ -3442,7 +3450,12 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *dir, dir->i_size += BOGO_DIRENT_SIZE; inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); inode_inc_iversion(dir); - d_instantiate(dentry, inode); + + if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) + d_add(dentry, inode); + else + d_instantiate(dentry, inode); + dget(dentry); /* Extra count - pin the dentry in core */ return error; @@ -3533,7 +3546,10 @@ static int shmem_link(struct dentry *old_dentry, struct inode *dir, inc_nlink(inode); ihold(inode); /* New dentry reference */ dget(dentry); /* Extra pinning count for the created dentry */ - d_instantiate(dentry, inode); + if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) + d_add(dentry, inode); + else + d_instantiate(dentry, inode); out: return ret; } @@ -3553,6 +3569,14 @@ static int shmem_unlink(struct inode *dir, struct dentry *dentry) inode_inc_iversion(dir); drop_nlink(inode); dput(dentry); /* Undo the count from "create" - does all the work */ + + /* + * For now, VFS can't deal with case-insensitive negative dentries, so + * we invalidate them + */ + if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) + d_invalidate(dentry); + return 0; } @@ -3697,7 +3721,10 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, dir->i_size += BOGO_DIRENT_SIZE; inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); inode_inc_iversion(dir); - d_instantiate(dentry, inode); + if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) + d_add(dentry, inode); + else + d_instantiate(dentry, inode); dget(dentry); return 0; @@ -4050,6 +4077,9 @@ enum shmem_param { Opt_usrquota_inode_hardlimit, Opt_grpquota_block_hardlimit, Opt_grpquota_inode_hardlimit, + Opt_casefold_version, + Opt_casefold, + Opt_strict_encoding, }; static const struct constant_table shmem_param_enums_huge[] = { @@ -4081,9 +4111,62 @@ const struct fs_parameter_spec shmem_fs_parameters[] = { fsparam_string("grpquota_block_hardlimit", Opt_grpquota_block_hardlimit), fsparam_string("grpquota_inode_hardlimit", Opt_grpquota_inode_hardlimit), #endif + fsparam_string("casefold", Opt_casefold_version), + fsparam_flag ("casefold", Opt_casefold), + fsparam_flag ("strict_encoding", Opt_strict_encoding), {} }; +#if IS_ENABLED(CONFIG_UNICODE) +static int shmem_parse_opt_casefold(struct fs_context *fc, struct fs_parameter *param, + bool latest_version) +{ + struct shmem_options *ctx = fc->fs_private; + unsigned int maj = 0, min = 0, rev = 0, version = 0; + struct unicode_map *encoding; + char *version_str = param->string + 5; + int ret; + + if (latest_version) { + version = UTF8_LATEST; + } else { + if (strncmp(param->string, "utf8-", 5)) + return invalfc(fc, "Only UTF-8 encodings are supported " + "in the format: utf8-"); + + ret = utf8_parse_version(version_str, &maj, &min, &rev); + if (ret) + return invalfc(fc, "Invalid UTF-8 version: %s", version_str); + + version = UNICODE_AGE(maj, min, rev); + } + + encoding = utf8_load(version); + + if (IS_ERR(encoding)) { + if (latest_version) + return invalfc(fc, "Failed loading latest UTF-8 version"); + else + return invalfc(fc, "Failed loading UTF-8 version: %s", version_str); + } + + if (latest_version) + pr_info("tmpfs: Using the latest UTF-8 version available"); + else + pr_info("tmpfs: Using encoding provided by mount options: %s\n", param->string); + + ctx->encoding = encoding; + + return 0; +} +#else +static int shmem_parse_opt_casefold(struct fs_context *fc, struct fs_parameter *param, + bool latest_version) +{ + return invalfc(fc, "tmpfs: No kernel support for casefold filesystems\n"); +} +#endif + static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) { struct shmem_options *ctx = fc->fs_private; @@ -4242,6 +4325,13 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) "Group quota inode hardlimit too large."); ctx->qlimits.grpquota_ihardlimit = size; break; + case Opt_casefold_version: + return shmem_parse_opt_casefold(fc, param, false); + case Opt_casefold: + return shmem_parse_opt_casefold(fc, param, true); + case Opt_strict_encoding: + ctx->strict_encoding = true; + break; } return 0; @@ -4471,6 +4561,11 @@ static void shmem_put_super(struct super_block *sb) { struct shmem_sb_info *sbinfo = SHMEM_SB(sb); +#if IS_ENABLED(CONFIG_UNICODE) + if (sb->s_encoding) + utf8_unload(sb->s_encoding); +#endif + #ifdef CONFIG_TMPFS_QUOTA shmem_disable_quotas(sb); #endif @@ -4515,6 +4610,16 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) } sb->s_export_op = &shmem_export_ops; sb->s_flags |= SB_NOSEC | SB_I_VERSION; + +#if IS_ENABLED(CONFIG_UNICODE) + if (ctx->encoding) { + sb->s_encoding = ctx->encoding; + generic_set_sb_d_ops(sb); + if (ctx->strict_encoding) + sb->s_encoding_flags = SB_ENC_STRICT_MODE_FL; + } +#endif + #else sb->s_flags |= SB_NOUSER; #endif @@ -4704,11 +4809,38 @@ static const struct inode_operations shmem_inode_operations = { #endif }; +static struct dentry *shmem_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) +{ + const struct dentry_operations *d_ops = &simple_dentry_operations; + +#if IS_ENABLED(CONFIG_UNICODE) + if (dentry->d_sb->s_encoding) + d_ops = &generic_ci_always_del_dentry_ops; +#endif + + if (dentry->d_name.len > NAME_MAX) + return ERR_PTR(-ENAMETOOLONG); + + if (!dentry->d_sb->s_d_op) + d_set_d_op(dentry, d_ops); + + /* + * For now, VFS can't deal with case-insensitive negative dentries, so + * we prevent them from being created + */ + if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) + return NULL; + + d_add(dentry, NULL); + + return NULL; +} + static const struct inode_operations shmem_dir_inode_operations = { #ifdef CONFIG_TMPFS .getattr = shmem_getattr, .create = shmem_create, - .lookup = simple_lookup, + .lookup = shmem_lookup, .link = shmem_link, .unlink = shmem_unlink, .symlink = shmem_symlink, @@ -4791,6 +4923,8 @@ int shmem_init_fs_context(struct fs_context *fc) ctx->uid = current_fsuid(); ctx->gid = current_fsgid(); + ctx->encoding = NULL; + fc->fs_private = ctx; fc->ops = &shmem_fs_context_ops; return 0; From patchwork Thu Sep 5 19:02:50 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: 13792869 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 128EC1AAE1A; Thu, 5 Sep 2024 19:03:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563028; cv=none; b=QPaKignvrG9I0HKKzpE2qdB3kedu2Si9f228yim0Y9DZlyl+ZRs9jiszI8bcCSrcl4pBRP+HXOYHlLB5qE7zFcDl/2rYSAt1++XQ0LZm0NSniCfYM0bjbgHYU2ixSomJyY6ArTFzkf6wZWoujfDU1CYovVxPSd6t47UR88IUiCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563028; c=relaxed/simple; bh=udVdGInsZAbKFZEmGAi12TpwFH+Uj9R0zV/GtGqr7OY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CZWe/0W7jHQmXZ+6Lz7jUb1naB5KojqppKm/kqFOGY7EON819v6JsFq8kkfJXludQKmcCe78XzzB5BWU2ypH+VhxV/3bmzLdbcDrmGvr/BvjL4hwtexQWqDI9Mbgxk7JWNmrdaXpqeUTE8POkkPvqX9lS5ZfjkaYH71fQekoPq0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=qRDe7y/i; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="qRDe7y/i" 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=4vz8LJ8AGqtE46pXkxH06G/62SH6tsoXVW4UBJQz500=; b=qRDe7y/i3zJwIWrkmkWIlGSNG5 S8C/1KxCMXfvhhaAOkFX3VUMNClSZ9JflAyBEbAWNSt9LmkJunrXCJ38rnWCAI3AkrbzWvxFUbSmB dHaJKveIWlR4idWLWfU0B9NTBUxH4379FDaEvV3v7uNz0wht/K27+ttfz58v1GqRiMoerG5SLowVh 2Wlb+UhmxHeg+a0y9R4Nl1yT88f2AMWWVvksy2TJIWcOGGJoACJFsCmryE2FYHLXXx3FCuhhgCmVu KwLcBzQYqqKsXEV0Iuq84EY4KvQCcptkJ3q51oL+h/r4r4PaXqN95AQ9xJTeNPd/cAMDFK1FuCN4t 5nN+1DJw==; 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 1smHla-00A6Ho-Is; Thu, 05 Sep 2024 21:03:38 +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 7/9] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs Date: Thu, 5 Sep 2024 16:02:50 -0300 Message-ID: <20240905190252.461639-8-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> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Enable setting flag FS_CASEFOLD_FL for tmpfs directories, when tmpfs is mounted with casefold support. A special check is need for this flag, since it can't be set for non-empty directories. Signed-off-by: André Almeida --- Changes from v2: - Fixed bug when adding a non-casefold flag in a non-empty dir --- include/linux/shmem_fs.h | 6 ++-- mm/shmem.c | 70 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 1d06b1e5408a..8367ca2b99d9 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -42,10 +42,10 @@ struct shmem_inode_info { struct inode vfs_inode; }; -#define SHMEM_FL_USER_VISIBLE FS_FL_USER_VISIBLE +#define SHMEM_FL_USER_VISIBLE (FS_FL_USER_VISIBLE | FS_CASEFOLD_FL) #define SHMEM_FL_USER_MODIFIABLE \ - (FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL) -#define SHMEM_FL_INHERITED (FS_NODUMP_FL | FS_NOATIME_FL) + (FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL | FS_CASEFOLD_FL) +#define SHMEM_FL_INHERITED (FS_NODUMP_FL | FS_NOATIME_FL | FS_CASEFOLD_FL) struct shmem_quota_limits { qsize_t usrquota_bhardlimit; /* Default user quota block hard limit */ diff --git a/mm/shmem.c b/mm/shmem.c index 6b61fc5dc0b1..d38977fb2097 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2613,13 +2613,62 @@ static int shmem_file_open(struct inode *inode, struct file *file) #ifdef CONFIG_TMPFS_XATTR static int shmem_initxattrs(struct inode *, const struct xattr *, void *); +#if IS_ENABLED(CONFIG_UNICODE) +/* + * shmem_inode_casefold_flags - Deal with casefold file attribute flag + * + * The casefold file attribute needs some special checks. I can just be added to + * an empty dir, and can't be removed from a non-empty dir. + */ +static int shmem_inode_casefold_flags(struct inode *inode, unsigned int fsflags, + struct dentry *dentry, unsigned int *i_flags) +{ + unsigned int old = inode->i_flags; + struct super_block *sb = inode->i_sb; + + if (fsflags & FS_CASEFOLD_FL) { + if (!(old & S_CASEFOLD)) { + if (!sb->s_encoding) + return -EOPNOTSUPP; + + if (!S_ISDIR(inode->i_mode)) + return -ENOTDIR; + + if (dentry && !simple_empty(dentry)) + return -ENOTEMPTY; + } + + *i_flags = *i_flags | S_CASEFOLD; + } else if (old & S_CASEFOLD) { + if (dentry && !simple_empty(dentry)) + return -ENOTEMPTY; + } + + return 0; +} +#else +static int shmem_inode_casefold_flags(struct inode *inode, unsigned int fsflags, + struct dentry *dentry, unsigned int *i_flags) +{ + if (fsflags & FS_CASEFOLD_FL) + return -EOPNOTSUPP; + + return 0; +} +#endif + /* * chattr's fsflags are unrelated to extended attributes, * but tmpfs has chosen to enable them under the same config option. */ -static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags) +static int shmem_set_inode_flags(struct inode *inode, unsigned int fsflags, struct dentry *dentry) { unsigned int i_flags = 0; + int ret; + + ret = shmem_inode_casefold_flags(inode, fsflags, dentry, &i_flags); + if (ret) + return ret; if (fsflags & FS_NOATIME_FL) i_flags |= S_NOATIME; @@ -2630,10 +2679,12 @@ static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags) /* * But FS_NODUMP_FL does not require any action in i_flags. */ - inode_set_flags(inode, i_flags, S_NOATIME | S_APPEND | S_IMMUTABLE); + inode_set_flags(inode, i_flags, S_NOATIME | S_APPEND | S_IMMUTABLE | S_CASEFOLD); + + return 0; } #else -static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags) +static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags, struct dentry *dentry) { } #define shmem_initxattrs NULL @@ -2680,7 +2731,7 @@ static struct inode *__shmem_get_inode(struct mnt_idmap *idmap, info->fsflags = (dir == NULL) ? 0 : SHMEM_I(dir)->fsflags & SHMEM_FL_INHERITED; if (info->fsflags) - shmem_set_inode_flags(inode, info->fsflags); + shmem_set_inode_flags(inode, info->fsflags, NULL); INIT_LIST_HEAD(&info->shrinklist); INIT_LIST_HEAD(&info->swaplist); simple_xattrs_init(&info->xattrs); @@ -3789,16 +3840,23 @@ static int shmem_fileattr_set(struct mnt_idmap *idmap, { struct inode *inode = d_inode(dentry); struct shmem_inode_info *info = SHMEM_I(inode); + int ret, flags; if (fileattr_has_fsx(fa)) return -EOPNOTSUPP; if (fa->flags & ~SHMEM_FL_USER_MODIFIABLE) return -EOPNOTSUPP; - info->fsflags = (info->fsflags & ~SHMEM_FL_USER_MODIFIABLE) | + flags = (info->fsflags & ~SHMEM_FL_USER_MODIFIABLE) | (fa->flags & SHMEM_FL_USER_MODIFIABLE); - shmem_set_inode_flags(inode, info->fsflags); + ret = shmem_set_inode_flags(inode, flags, dentry); + + if (ret) + return ret; + + info->fsflags = flags; + inode_set_ctime_current(inode); inode_inc_iversion(inode); return 0; From patchwork Thu Sep 5 19:02:51 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: 13792870 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 453241AE026; Thu, 5 Sep 2024 19:03:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563031; cv=none; b=F08tlKHnjPCsMpbHno/4XrDOwL1I3oU/FcpI2liWu26PvG+iDRtpSHkW3FTkrWWfFqlMrFs+CsGEthsHHgfJUB4MzqcGnFA5hEWA7KHzxGCDnstf6SE3s4iew6tub3NGlMdc6VBzP/J5nilXwrGG7X5bLL2s6TUsTXJhLVEceKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563031; c=relaxed/simple; bh=hgYua/lefeXh9Gchs8o23DaNH5W4Qs3bm/egkRFy4bA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VnJDV08j2DQv59w4XMM+hYYCeBKr9lDbgKajgQmjaPQq+G0xiPQxiYMfdOIsD8vi8Us7f5EUz8O5U4QFNwvEJJ4jZ5IAGySHJBqhe40swGhGXn8tRXxeg6ppmVrddQpeQU2wOicyNjjfj5ZKabsvRuhTb7Z5VzoUzuFaYqBd5Os= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=cMdmt17L; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="cMdmt17L" 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=KEsDgLMnBuzjf05DHVHytHkrG5fKkqN0J3GYigoTn6k=; b=cMdmt17LxH6fIF2Ney+7Mz3URy yoTm3Z2zgH2eTdXtPjbR95NIg+/65TVK+up5hFhZk733HaUhGytIm+PmrIJ1ncgRoi9Fa084/9rFw j3nAj42fwCiSE055xv0oPPp0njfSppyno+UlAJy2ml3e4/aU4j9csmwDu/LfYKqrOTh6vwmdLch8H OzIYIupdckTH0rafY7vSmeNSQ5tbU13eeBol+Hc1tL6hzQnKczgzP5jzsAXfSMy9JpvmO5zmJRU/1 plfBBtyQUTA4Ciwlz+QQ/wuPK8oZ3j4Yl7mqpTqWGrrOrXYaC4xEU7ikVPFoFTlItGFjIVWjqvEVP 0Zf6alNQ==; 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 1smHle-00A6Ho-OV; Thu, 05 Sep 2024 21:03:42 +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 8/9] tmpfs: Expose filesystem features via sysfs Date: Thu, 5 Sep 2024 16:02:51 -0300 Message-ID: <20240905190252.461639-9-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> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Expose filesystem features through sysfs, so userspace can query if tmpfs support casefold. This follows the same setup as defined by ext4 and f2fs to expose casefold support to userspace. Signed-off-by: André Almeida --- mm/shmem.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/mm/shmem.c b/mm/shmem.c index d38977fb2097..5da90bdde4a5 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -5424,3 +5424,40 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, return page; } EXPORT_SYMBOL_GPL(shmem_read_mapping_page_gfp); + +#if defined(CONFIG_SYSFS) && defined(CONFIG_TMPFS) +#if IS_ENABLED(CONFIG_UNICODE) +static DEVICE_STRING_ATTR_RO(casefold, 0444, "supported"); +#endif + +static struct attribute *tmpfs_attributes[] = { +#if IS_ENABLED(CONFIG_UNICODE) + &dev_attr_casefold.attr.attr, +#endif + NULL +}; + +static const struct attribute_group tmpfs_attribute_group = { + .attrs = tmpfs_attributes, + .name = "features" +}; + +static struct kobject *tmpfs_kobj; + +static int __init tmpfs_sysfs_init(void) +{ + int ret; + + tmpfs_kobj = kobject_create_and_add("tmpfs", fs_kobj); + if (!tmpfs_kobj) + return -ENOMEM; + + ret = sysfs_create_group(tmpfs_kobj, &tmpfs_attribute_group); + if (ret) + kobject_put(tmpfs_kobj); + + return ret; +} + +fs_initcall(tmpfs_sysfs_init); +#endif /* CONFIG_SYSFS && CONFIG_TMPFS */ From patchwork Thu Sep 5 19:02:52 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: 13792871 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 493A418D633; Thu, 5 Sep 2024 19:03:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563037; cv=none; b=uuA4yNrABkKQiY4NUMfsKutOJFPgBiB1HVMWVsp3HQCWSOLZIqbGxQ8C28DQQs0IyG0Q3hRfGTtV4JUqZcZl2IYWiP9Fx1qrqGDlIyjKRkwvVww8b2z7phYg376n7FQKwILxyEL77VPJTF2OXZ3sKksKO7vBb85yI4JZKcTOwMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725563037; c=relaxed/simple; bh=w9njlXbTjKRFGbFKbv7kGAlfDQmuLVt42zz+nC9FzHY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P6/nAeyAEq0Y6GoV8NbZ2PMQ45DfXGRq0Wkw7uLgFG68Ok7EfXFmwtMybEiQxCNcUnFYjz73/ZHNV0213TdplDaKDmkbwah/XA5iir4p76PnbXhP7uyppiZV6Q9+MaxxzhkLQpOgpPnkEdF1fmEfOye9CiyW2A/0n2PMqusCPSQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=WdLwE6Cn; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="WdLwE6Cn" 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=/LWMOwEq5GUDt5NImZXWEjsD4awT5R9j9E8cdrJ7p4o=; b=WdLwE6CnNPUk/lsHJztjMUkO1P +tQrfJtNZbR2466KvpkhAb47I8QsJqk19D2JRASXbyOu98VInDhMDWQ59T+6tthxgIv2DV3PMZTGn 50S5rIaMFmmD6YrSxYF9uBN3+dJR/kHGxDWPFEGZLeyurkyEkWiEhU6HHQCvIjdoJZpC+/LAVS0iC iboVw7Uax+cEX+It6g/ziPM2e1sK+892Agovno4V+gWDpsL+DSvSchSEQdh0DFyXwj8xpAQ7jyobH fA61Fh/M1s2fyuoI72AvqlyV4W1Nw0byJx1aChWO4PtaufxCZptDFlTeEFBcjrfTpUhMqmpDsPsSf KPxrkOAg==; 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 1smHli-00A6Ho-U0; Thu, 05 Sep 2024 21:03:46 +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 9/9] docs: tmpfs: Add casefold options Date: Thu, 5 Sep 2024 16:02:52 -0300 Message-ID: <20240905190252.461639-10-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> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Document mounting options for casefold support in tmpfs. Signed-off-by: André Almeida --- Documentation/filesystems/tmpfs.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Documentation/filesystems/tmpfs.rst b/Documentation/filesystems/tmpfs.rst index 56a26c843dbe..636afd3eaf48 100644 --- a/Documentation/filesystems/tmpfs.rst +++ b/Documentation/filesystems/tmpfs.rst @@ -241,6 +241,27 @@ So 'mount -t tmpfs -o size=10G,nr_inodes=10k,mode=700 tmpfs /mytmpfs' will give you tmpfs instance on /mytmpfs which can allocate 10GB RAM/SWAP in 10240 inodes and it is only accessible by root. +tmpfs has the following mounting options for case-insensitive lookups support: + +================= ============================================================== +casefold Enable casefold support at this mount point using the given + argument as the encoding standard. Currently only UTF-8 + encodings are supported. If no argument is used, it will load + the latest UTF-8 encoding available. +strict_encoding Enable strict encoding at this mount point (disabled by + default). In this mode, the filesystem refuses to create file + and directory with names containing invalid UTF-8 characters. +================= ============================================================== + +Note that this option doesn't enable casefold by default; one needs to set +casefold flag per directory, setting the +F attribute in an empty directory. New +directories within a casefolded one will inherit the flag. + +Example:: + + $ mount -t tmpfs -o casefold=utf8-12.1.0,strict_enconding fs_name /mytmpfs + $ mount -t tmpfs -o casefold fs_name /mytmpfs + :Author: Christoph Rohland , 1.12.01 @@ -250,3 +271,5 @@ RAM/SWAP in 10240 inodes and it is only accessible by root. KOSAKI Motohiro, 16 Mar 2010 :Updated: Chris Down, 13 July 2020 +:Updated: + André Almeida, 23 Aug 2024