From patchwork Thu Feb 8 06:43:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 13549386 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CB1F5C48260 for ; Thu, 8 Feb 2024 06:45:25 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rXyA0-0005oO-S1; Thu, 08 Feb 2024 06:45:25 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rXy9x-0005oI-Mf for linux-f2fs-devel@lists.sourceforge.net; Thu, 08 Feb 2024 06:45:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: 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=xXPbqW22ufCYPMcR0RGf+Y2TegYtOwxWcO5QDFW/A4M=; b=kVaLA+tGMuVwGohDN8onABNFgp I59Ip1eouISByovWZxlbuNsF1pbaCI3nRiHaRV/P/Hef1DYto4/z//iwQIvb+OpvNmJY5g2r+bNTT EsWGPreNyWsypGd4igvu8elejGPXNc1JqW+OBslzgCtpT9er0Jh++Qu14ldCwXY7C7xk=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: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=xXPbqW22ufCYPMcR0RGf+Y2TegYtOwxWcO5QDFW/A4M=; b=g7Ep0orBpm/hJ3RzwLSiYDPM0l POAvsXaR4whWpIAIqNBan3AQyYcOaa/hQzYF6Txhm/Ew8KtsrL9ftoHphgEaGqHtDmPmORU79djlt jMGiJRqfUI40n+A0GfOfAx7RIZJFhfcMPaWSF93WDnB10sqFCnePuaB+5G28O1WuMWGM=; Received: from madrid.collaboradmins.com ([46.235.227.194]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rXy9w-0000tg-Ny for linux-f2fs-devel@lists.sourceforge.net; Thu, 08 Feb 2024 06:45:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1707374710; bh=z2xXaS0+/d8JUZt7vHBl6tVYdew9NWG64RIjh0LO0O8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L2FWO1LtN1PJ9pspTv+w5NTJ8ASxKkSRc7w5HoQhJXqyhSkESPoR8jl6ocuGtMjKR TqMZJ0xmxKipeCK7KtmlppU1i59jlzFX7+yap0fPtsG4RrRcYKXpjJOnwiwuChi5UJ 8A7z52mgd4k5pxn13ni9wMsqod4lTyqeOxmaRsw246lmF3TYnHXc4TfYDWmHUbHuFM IlQmaug+CBKMkc93ggU2Ra9rH6M/bQu5p3WKVzo9bWaDGjaW8P0yJoN42OZWnfILjm 4CmObalmGnHkTFIMsX40xRQEWqmaXE0CK+n6itHLYXdzY6DsJ3OqR365RDCR3/xkAq 9/w+6/FM2ratQ== Received: from eugen-station.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 0A2253782098; Thu, 8 Feb 2024 06:45:05 +0000 (UTC) To: tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org, chao@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Date: Thu, 8 Feb 2024 08:43:32 +0200 Message-Id: <20240208064334.268216-2-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208064334.268216-1-eugen.hristev@collabora.com> References: <20240208064334.268216-1-eugen.hristev@collabora.com> MIME-Version: 1.0 X-Headers-End: 1rXy9w-0000tg-Ny Subject: [f2fs-dev] [RESEND PATCH v9 1/3] libfs: Introduce case-insensitive string comparison helper X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Eugen Hristev via Linux-f2fs-devel From: Eugen Hristev Reply-To: Eugen Hristev Cc: jack@suse.cz, Eric Biggers , linux-kernel@vger.kernel.org, eugen.hristev@collabora.com, linux-fsdevel@vger.kernel.org, kernel@collabora.com, Gabriel Krisman Bertazi Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Gabriel Krisman Bertazi generic_ci_match can be used by case-insensitive filesystems to compare strings under lookup with dirents in a case-insensitive way. This function is currently reimplemented by each filesystem supporting casefolding, so this reduces code duplication in filesystem-specific code. Reviewed-by: Eric Biggers Signed-off-by: Gabriel Krisman Bertazi Signed-off-by: Eugen Hristev --- fs/libfs.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 4 +++ 2 files changed, 72 insertions(+) diff --git a/fs/libfs.c b/fs/libfs.c index bb18884ff20e..f80cb982ac89 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1773,6 +1773,74 @@ static const struct dentry_operations generic_ci_dentry_ops = { .d_hash = generic_ci_d_hash, .d_compare = generic_ci_d_compare, }; + +/** + * generic_ci_match() - Match a name (case-insensitively) with a dirent. + * @parent: Inode of the parent of the dirent under comparison + * @name: name under lookup. + * @folded_name: Optional pre-folded name under lookup + * @de_name: Dirent name. + * @de_name_len: dirent name length. + * + * + * Test whether a case-insensitive directory entry matches the filename + * being searched. If @folded_name is provided, it is used instead of + * recalculating the casefold of @name. + * + * Return: > 0 if the directory entry matches, 0 if it doesn't match, or + * < 0 on error. + */ +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) +{ + const struct super_block *sb = parent->i_sb; + const struct unicode_map *um = sb->s_encoding; + struct fscrypt_str decrypted_name = FSTR_INIT(NULL, de_name_len); + struct qstr dirent = QSTR_INIT(de_name, de_name_len); + int res, match = false; + + if (IS_ENCRYPTED(parent)) { + const struct fscrypt_str encrypted_name = + FSTR_INIT((u8 *) de_name, de_name_len); + + if (WARN_ON_ONCE(!fscrypt_has_encryption_key(parent))) + return -EINVAL; + + decrypted_name.name = kmalloc(de_name_len, GFP_KERNEL); + if (!decrypted_name.name) + return -ENOMEM; + res = fscrypt_fname_disk_to_usr(parent, 0, 0, &encrypted_name, + &decrypted_name); + if (res < 0) + goto out; + dirent.name = decrypted_name.name; + dirent.len = decrypted_name.len; + } + + if (folded_name->name) + res = utf8_strncasecmp_folded(um, folded_name, &dirent); + else + res = utf8_strncasecmp(um, name, &dirent); + + if (!res) + match = true; + else if (res < 0 && !sb_has_strict_encoding(sb)) { + /* + * In non-strict mode, fallback to a byte comparison if + * the names have invalid characters. + */ + res = 0; + match = ((name->len == dirent.len) && + !memcmp(name->name, dirent.name, dirent.len)); + } + +out: + kfree(decrypted_name.name); + return (res >= 0) ? match : res; +} +EXPORT_SYMBOL(generic_ci_match); #endif #ifdef CONFIG_FS_ENCRYPTION diff --git a/include/linux/fs.h b/include/linux/fs.h index 820b93b2917f..7af691ff8d44 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3296,6 +3296,10 @@ extern int generic_file_fsync(struct file *, loff_t, loff_t, int); extern int generic_check_addressable(unsigned, u64); extern void generic_set_encrypted_ci_d_ops(struct dentry *dentry); +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); static inline bool sb_has_encoding(const struct super_block *sb) { From patchwork Thu Feb 8 06:43:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 13549385 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0FF94C4828F for ; Thu, 8 Feb 2024 06:45:25 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rXy9z-0003ca-QX; Thu, 08 Feb 2024 06:45:24 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rXy9x-0003cS-Mm for linux-f2fs-devel@lists.sourceforge.net; Thu, 08 Feb 2024 06:45:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: 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=oktS/MBFoF+x9yONCrKAEawd+NT7G/N3oFpCIujtcCI=; b=TXuzPWdlWqUE+DT6+KlpRTJ4Kl h7qCOjsaVb2a5+Hr/k6+7dZrwKXdrfVmQmxJIKwn2/z4XJvgiwmpmuZy8gLRg+AKWkB3DlYFGsPPc Ila5fJGBn4tCQsznxeNCBoFd8/BlkrlEaA5nrysaouzzbBdp3qKxrbAwLD8ZFelpkUdI=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: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=oktS/MBFoF+x9yONCrKAEawd+NT7G/N3oFpCIujtcCI=; b=hdVHCyW+oFGB4e7+m2Ol2sNSQQ KdcJoGfS+8d9dC0BwAlwgqZ1pWYWaSAgTL6qPbQbg+FR1Lpzq3O6ca1/OfzOtz17TRGVXspFplMuW hYIZ00urqRdedDlb1C4rY8MSJFYdvZSsgPrVs9/qG2oNqqJWIpvxNDKgZrEFYdE/lXFI=; Received: from madrid.collaboradmins.com ([46.235.227.194]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rXy9w-0000te-Id for linux-f2fs-devel@lists.sourceforge.net; Thu, 08 Feb 2024 06:45:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1707374715; bh=Hp90mLjR44WCv/VB4t8dflfSiAXrxxn0/qF/zsP/e4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=3nAZAaTwuFf2q5gXCNHeCNCGTmxQ3C/coSm+Lcy/qdtQj0ylbb4TZx4r23V6rJk7g GhKRj7k6zfHnPUTAVVGXboIjVn7QH60EaqnGmZgK6SfH4RV8oSSPqKwUP7HDBSTtIM xm7SIFBppiQV/gBe8VDbHy5DLwlivR5P5763D5Ogy7Hnh63zeTmRFteABDwRcWW/QP /tt8Ah4m3/QQFbNBt9976OmfoExk1efCCHCxb+Jq51cTqy7b5XXAArKm8/TvrqSGgd IVl2iDwDXThXyw7RcAr4mvPPPmZucHd93lGWLP9OcZXVelpAEa2ddbWj8hmzMfA8lJ xbspGvXB+KRrg== Received: from eugen-station.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madrid.collaboradmins.com (Postfix) with ESMTPSA id E600D3782099; Thu, 8 Feb 2024 06:45:10 +0000 (UTC) To: tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org, chao@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Date: Thu, 8 Feb 2024 08:43:33 +0200 Message-Id: <20240208064334.268216-3-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208064334.268216-1-eugen.hristev@collabora.com> References: <20240208064334.268216-1-eugen.hristev@collabora.com> MIME-Version: 1.0 X-Headers-End: 1rXy9w-0000te-Id Subject: [f2fs-dev] [RESEND PATCH v9 2/3] ext4: Reuse generic_ci_match for ci comparisons X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Eugen Hristev via Linux-f2fs-devel From: Eugen Hristev Reply-To: Eugen Hristev Cc: jack@suse.cz, linux-kernel@vger.kernel.org, eugen.hristev@collabora.com, linux-fsdevel@vger.kernel.org, kernel@collabora.com, Gabriel Krisman Bertazi Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Gabriel Krisman Bertazi Instead of reimplementing ext4_match_ci, use the new libfs helper. It also adds a comment explaining why fname->cf_name.name must be checked prior to the encryption hash optimization, because that tripped me before. Signed-off-by: Gabriel Krisman Bertazi Signed-off-by: Eugen Hristev --- fs/ext4/namei.c | 91 +++++++++++++++---------------------------------- 1 file changed, 27 insertions(+), 64 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index e554c5a62ba9..6e7af8dc4dde 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1390,58 +1390,6 @@ static void dx_insert_block(struct dx_frame *frame, u32 hash, ext4_lblk_t block) } #if IS_ENABLED(CONFIG_UNICODE) -/* - * Test whether a case-insensitive directory entry matches the filename - * being searched for. If quick is set, assume the name being looked up - * is already in the casefolded form. - * - * Returns: 0 if the directory entry matches, more than 0 if it - * doesn't match or less than zero on error. - */ -static int ext4_ci_compare(const struct inode *parent, const struct qstr *name, - u8 *de_name, size_t de_name_len, bool quick) -{ - const struct super_block *sb = parent->i_sb; - const struct unicode_map *um = sb->s_encoding; - struct fscrypt_str decrypted_name = FSTR_INIT(NULL, de_name_len); - struct qstr entry = QSTR_INIT(de_name, de_name_len); - int ret; - - if (IS_ENCRYPTED(parent)) { - const struct fscrypt_str encrypted_name = - FSTR_INIT(de_name, de_name_len); - - decrypted_name.name = kmalloc(de_name_len, GFP_KERNEL); - if (!decrypted_name.name) - return -ENOMEM; - ret = fscrypt_fname_disk_to_usr(parent, 0, 0, &encrypted_name, - &decrypted_name); - if (ret < 0) - goto out; - entry.name = decrypted_name.name; - entry.len = decrypted_name.len; - } - - if (quick) - ret = utf8_strncasecmp_folded(um, name, &entry); - else - ret = utf8_strncasecmp(um, name, &entry); - if (ret < 0) { - /* Handle invalid character sequence as either an error - * or as an opaque byte sequence. - */ - if (sb_has_strict_encoding(sb)) - ret = -EINVAL; - else if (name->len != entry.len) - ret = 1; - else - ret = !!memcmp(name->name, entry.name, entry.len); - } -out: - kfree(decrypted_name.name); - return ret; -} - int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname, struct ext4_filename *name) { @@ -1503,20 +1451,35 @@ static bool ext4_match(struct inode *parent, #if IS_ENABLED(CONFIG_UNICODE) if (IS_CASEFOLDED(parent) && (!IS_ENCRYPTED(parent) || fscrypt_has_encryption_key(parent))) { - if (fname->cf_name.name) { - if (IS_ENCRYPTED(parent)) { - if (fname->hinfo.hash != EXT4_DIRENT_HASH(de) || - fname->hinfo.minor_hash != - EXT4_DIRENT_MINOR_HASH(de)) { + int ret; - return false; - } - } - return !ext4_ci_compare(parent, &fname->cf_name, - de->name, de->name_len, true); + /* + * Just checking IS_ENCRYPTED(parent) below is not + * sufficient to decide whether one can use the hash for + * skipping the string comparison, because the key might + * have been added right after + * ext4_fname_setup_ci_filename(). In this case, a hash + * mismatch will be a false negative. Therefore, make + * sure cf_name was properly initialized before + * considering the calculated hash. + */ + if (IS_ENCRYPTED(parent) && fname->cf_name.name && + (fname->hinfo.hash != EXT4_DIRENT_HASH(de) || + fname->hinfo.minor_hash != EXT4_DIRENT_MINOR_HASH(de))) + return false; + + ret = generic_ci_match(parent, fname->usr_fname, + &fname->cf_name, de->name, + de->name_len); + if (ret < 0) { + /* + * Treat comparison errors as not a match. The + * only case where it happens is on a disk + * corruption or ENOMEM. + */ + return false; } - return !ext4_ci_compare(parent, fname->usr_fname, de->name, - de->name_len, false); + return ret; } #endif From patchwork Thu Feb 8 06:43:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 13549387 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7AF7AC4828F for ; Thu, 8 Feb 2024 06:45:35 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rXyAA-0005oq-6i; Thu, 08 Feb 2024 06:45:34 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rXyA8-0005ok-67 for linux-f2fs-devel@lists.sourceforge.net; Thu, 08 Feb 2024 06:45:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: 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=mUH8Ldjjxi8it9eaRNAUP8jiOKNg7HpR2OKWq4ySMwo=; b=T0bDAhI9osD4ohGLRkY4HwXrFM iE79VRBjqQN1HXjf1Kzwsmb25esp36G9qnHjXSwEPtVKsUI4Y7bg/poGqeO/I9Y4sJtkdtT1UV7RX lTm5PxG9Z5sG3bIRi+soHu8TqgzwmgqJWIzTYiBDqZ0mymzhbyRTgI/TaEuk4shvCSOA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: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=mUH8Ldjjxi8it9eaRNAUP8jiOKNg7HpR2OKWq4ySMwo=; b=X4FveVxk6kxJioiaTNfH3QZ6D7 gpVSncIkNF8fB8rNNcsz7cviZR5th+MjyKcMnTtpJerNrMC/sh+44saS1hLk5qYr9/LYb4VaA8Evx dv1oLcsK2ZTDc3QRy/93nqP+buwsFBr7wlVAQaHxzj0vIg7vjT2Y39kOWkuGIdXjPTQs=; Received: from madrid.collaboradmins.com ([46.235.227.194]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rXyA7-0000u8-6l for linux-f2fs-devel@lists.sourceforge.net; Thu, 08 Feb 2024 06:45:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1707374720; bh=dzKZXblpWESFyKaff5lcUS9bN5Ok7BHsB49SOtV2pf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YLefnevkX12McBubm6n8iAgtkkqHcuSUHXRwwCg4xv5p+x3/OA76gR/Sy9izDrlwA eQCfcsm/M2L1fey/OZ4V3jbXIFyyHuRd5a5rkxfClZ2HKILxe8Ms5j7bblCr/R00BR lNnsG4ywbanfvoCLURrmjz+TRTnXvJ9OSOGlo/b5pDVftSrhYxeK4txDnikr5viC7f O7vgvvJ5UP1DV+wP+pTtr3LWGZZarcAB6MCUbyS4hiTWA6xHEW6BNGhB/lTdXhJZ+Y YtOkANP22Fnv/0fwTvwP+Vuhej0K8oTTuJYjiQvuid6iXi2vdQ+3M6o8LbSJKxAJk6 lqYeaoM7gfrWQ== Received: from eugen-station.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madrid.collaboradmins.com (Postfix) with ESMTPSA id B8564378045F; Thu, 8 Feb 2024 06:45:15 +0000 (UTC) To: tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org, chao@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Date: Thu, 8 Feb 2024 08:43:34 +0200 Message-Id: <20240208064334.268216-4-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208064334.268216-1-eugen.hristev@collabora.com> References: <20240208064334.268216-1-eugen.hristev@collabora.com> MIME-Version: 1.0 X-Headers-End: 1rXyA7-0000u8-6l Subject: [f2fs-dev] [RESEND PATCH v9 3/3] f2fs: Reuse generic_ci_match for ci comparisons X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Eugen Hristev via Linux-f2fs-devel From: Eugen Hristev Reply-To: Eugen Hristev Cc: jack@suse.cz, Eric Biggers , linux-kernel@vger.kernel.org, eugen.hristev@collabora.com, linux-fsdevel@vger.kernel.org, kernel@collabora.com, Gabriel Krisman Bertazi Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Gabriel Krisman Bertazi Now that ci_match is part of libfs, make f2fs reuse it instead of having a different implementation. Reviewed-by: Chao Yu Reviewed-by: Eric Biggers Signed-off-by: Gabriel Krisman Bertazi Signed-off-by: Eugen Hristev --- fs/f2fs/dir.c | 58 ++++----------------------------------------------- 1 file changed, 4 insertions(+), 54 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index f5b65cf36393..7953322b9b9e 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -185,58 +185,6 @@ static struct f2fs_dir_entry *find_in_block(struct inode *dir, return f2fs_find_target_dentry(&d, fname, max_slots); } -#if IS_ENABLED(CONFIG_UNICODE) -/* - * Test whether a case-insensitive directory entry matches the filename - * being searched for. - * - * Returns 1 for a match, 0 for no match, and -errno on an error. - */ -static int f2fs_match_ci_name(const struct inode *dir, const struct qstr *name, - const u8 *de_name, u32 de_name_len) -{ - const struct super_block *sb = dir->i_sb; - const struct unicode_map *um = sb->s_encoding; - struct fscrypt_str decrypted_name = FSTR_INIT(NULL, de_name_len); - struct qstr entry = QSTR_INIT(de_name, de_name_len); - int res; - - if (IS_ENCRYPTED(dir)) { - const struct fscrypt_str encrypted_name = - FSTR_INIT((u8 *)de_name, de_name_len); - - if (WARN_ON_ONCE(!fscrypt_has_encryption_key(dir))) - return -EINVAL; - - decrypted_name.name = kmalloc(de_name_len, GFP_KERNEL); - if (!decrypted_name.name) - return -ENOMEM; - res = fscrypt_fname_disk_to_usr(dir, 0, 0, &encrypted_name, - &decrypted_name); - if (res < 0) - goto out; - entry.name = decrypted_name.name; - entry.len = decrypted_name.len; - } - - res = utf8_strncasecmp_folded(um, name, &entry); - /* - * In strict mode, ignore invalid names. In non-strict mode, - * fall back to treating them as opaque byte sequences. - */ - if (res < 0 && !sb_has_strict_encoding(sb)) { - res = name->len == entry.len && - memcmp(name->name, entry.name, name->len) == 0; - } else { - /* utf8_strncasecmp_folded returns 0 on match */ - res = (res == 0); - } -out: - kfree(decrypted_name.name); - return res; -} -#endif /* CONFIG_UNICODE */ - static inline int f2fs_match_name(const struct inode *dir, const struct f2fs_filename *fname, const u8 *de_name, u32 de_name_len) @@ -245,8 +193,10 @@ static inline int f2fs_match_name(const struct inode *dir, #if IS_ENABLED(CONFIG_UNICODE) if (fname->cf_name.name) - return f2fs_match_ci_name(dir, &fname->cf_name, - de_name, de_name_len); + return generic_ci_match(dir, fname->usr_fname, + &fname->cf_name, + de_name, de_name_len); + #endif f.usr_fname = fname->usr_fname; f.disk_name = fname->disk_name;