From mboxrd@z Thu Jan 1 00:00:00 1970 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 D3357EEB59D for ; Thu, 12 Sep 2024 19:16:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 70FBE6B0093; Thu, 12 Sep 2024 15:16:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E6836B0096; Thu, 12 Sep 2024 15:16:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5AE726B009A; Thu, 12 Sep 2024 15:16:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3B7206B0093 for ; Thu, 12 Sep 2024 15:16:30 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E337F40432 for ; Thu, 12 Sep 2024 19:16:29 +0000 (UTC) X-FDA: 82557042498.09.E2A5615 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by imf25.hostedemail.com (Postfix) with ESMTP id D5D0DA000E for ; Thu, 12 Sep 2024 19:16:27 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=krisman.be header.s=gm1 header.b=ZULENZAD; spf=pass (imf25.hostedemail.com: domain of gabriel@krisman.be designates 217.70.183.194 as permitted sender) smtp.mailfrom=gabriel@krisman.be; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726168534; a=rsa-sha256; cv=none; b=Zd/bTJecl3ZXdJH9hSyrDdGfx5biJUNyd+/4WTNxZPQ51WbqsucGdwN3OIgv45+Vr6S5NA PcoPSmkML9mxgT/aV3/zGauTgkqqJELEO4C+vBA/iF+hol5mX7KaPIMyi40tas7Vug8oBh vvzaV49V1NEw82Fxe4tzjLjJQ3lt4P0= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=krisman.be header.s=gm1 header.b=ZULENZAD; spf=pass (imf25.hostedemail.com: domain of gabriel@krisman.be designates 217.70.183.194 as permitted sender) smtp.mailfrom=gabriel@krisman.be; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726168534; 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=EhVEzySNXDFTJF7lljGKHlz+SIBbvJp0eSgo4Oo37/k=; b=yhiKRmyt+Dh5aPDwigKP4PHxkur6YhoCQTZIOJbaGsRbKB2XQidID8OZ6v8/2hbWDwyfST Vu3Y1PsmVzM790X4Wtq3fIKqFXuv0ftAT6MU2L44nN6j6pbAEwOxnKJ54e/Yst4xEr4hpd zwC7wqCdPGwB5DvkRFDDZRaixWFcgqM= Received: by mail.gandi.net (Postfix) with ESMTPSA id 9DF8040004; Thu, 12 Sep 2024 19:16:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=krisman.be; s=gm1; t=1726168586; h=from:from: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; bh=EhVEzySNXDFTJF7lljGKHlz+SIBbvJp0eSgo4Oo37/k=; b=ZULENZADwMpQGMgo4yZ/4tnPL8DAAPc85CMRm+8URvtrlmis1HLvsdb5KjgeIqxhaeG9/C JRcRYXRX8ehBz+0sfUrBhShbZACnMVTrlZUscCt3wkIFykU+TeDlsEeYvFcdCX8GXR2rHd pdNVvQ425fwCgSGRb4lrXz/ZEXpt+dFFTh49dFocTy4Hf1Kt9BYKJeHXVux4VocdHNoRiw ZiflCt4/ukJ7sHIXTDxIoQDOo2iCpUBgWZ2KCvzmqcZj1xUpGTbZ0sB0GSFfYKNp2eCQW/ gA3b6y8yXZPcgI1HghtM3KB7Pt6wPFhwONjA/U9NDBlf6Dhu1IQbvCuXpyHBZw== From: Gabriel Krisman Bertazi To: =?utf-8?Q?Andr=C3=A9?= Almeida Cc: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , 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 Subject: Re: [PATCH v4 01/10] libfs: Create the helper function generic_ci_validate_strict_name() In-Reply-To: <20240911144502.115260-2-andrealmeid@igalia.com> (=?utf-8?Q?=22Andr=C3=A9?= Almeida"'s message of "Wed, 11 Sep 2024 11:44:53 -0300") References: <20240911144502.115260-1-andrealmeid@igalia.com> <20240911144502.115260-2-andrealmeid@igalia.com> User-Agent: Gnus/5.13 (Gnus v5.13) Date: Thu, 12 Sep 2024 15:16:22 -0400 Message-ID: <87a5gck7i1.fsf@mailhost.krisman.be> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: gabriel@krisman.be X-Stat-Signature: 56k54dij7wbus37beb7yogupwhuq4sc9 X-Rspamd-Queue-Id: D5D0DA000E X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1726168587-680179 X-HE-Meta: U2FsdGVkX1+8V6vt2aDNuv7bTmRFWu5DYORP3q6jIA6H7sp9JKOepeZ5gW4XoG+r5MXXMdJxDn+JiIka+dSe8scCq7qQj1L328u7Z6hrffvP0sLEGLIlQ7ojU5NAQ5KfTMxF+Igs3RLIpWlCAhh1oIzKlcwXNJCQh8jhH3JnqrrTB8qftuUioBhoDYk2t26WZ7t9Vuk0hL+q/14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qMrdxt0KmmdTz/Bb+KdNqE/DhOynaUcS7e3KNCg8Z340+ImEpAmzBX6g== 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: Andr=C3=A9 Almeida writes: > 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=C3=A9 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 *nam= e) > +{ > + 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 >=20=20 > #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 *par= ent, > 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 *nam= e); As mentioned in the other patch, please make this an inline helper. But also, the declaration needs to be guarded by CONFIG_UNICODE. >=20=20 > static inline bool sb_has_encoding(const struct super_block *sb) > { --=20 Gabriel Krisman Bertazi