linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chung-Chiang Cheng <shepjeng@gmail.com>
To: christian.brauner@ubuntu.com, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: cccheng@synology.com
Subject: [PATCH] hfsplus: prevent negative dentries when casefolded
Date: Sat, 17 Apr 2021 01:20:12 +0800	[thread overview]
Message-ID: <20210416172012.8667-1-cccheng@synology.com> (raw)

hfsplus uses the case-insensitive filenames by default, but VFS negative
dentries are incompatible with case-insensitive. For example, the
following instructions will get a cached filename 'aaa' which isn't
expected. There is no such problem in macOS.

  touch aaa
  rm aaa
  touch AAA

This patch just takes the same approach as ext4 and f2fs to prevent
negative dentries for this issue.

Signed-off-by: Chung-Chiang Cheng <cccheng@synology.com>
---
 fs/hfsplus/dir.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
index 03e6c046faf4..fcab8f09b6af 100644
--- a/fs/hfsplus/dir.c
+++ b/fs/hfsplus/dir.c
@@ -121,6 +121,9 @@ static struct dentry *hfsplus_lookup(struct inode *dir, struct dentry *dentry,
 	if (S_ISREG(inode->i_mode))
 		HFSPLUS_I(inode)->linkid = linkid;
 out:
+	/* Prevent the negative dentry in the casefolded form from being cached */
+	if (!inode && test_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags))
+		return NULL;
 	return d_splice_alias(inode, dentry);
 fail:
 	hfs_find_exit(&fd);
@@ -407,6 +410,12 @@ static int hfsplus_unlink(struct inode *dir, struct dentry *dentry)
 		sbi->file_count--;
 	inode->i_ctime = current_time(inode);
 	mark_inode_dirty(inode);
+
+	/* VFS negative dentries are incompatible with encoding and
+	 * case-insensitiveness
+	 */
+	if (test_bit(HFSPLUS_SB_CASEFOLD, &sbi->flags))
+		d_invalidate(dentry);
 out:
 	mutex_unlock(&sbi->vh_mutex);
 	return res;
@@ -429,6 +438,12 @@ static int hfsplus_rmdir(struct inode *dir, struct dentry *dentry)
 	inode->i_ctime = current_time(inode);
 	hfsplus_delete_inode(inode);
 	mark_inode_dirty(inode);
+
+	/* VFS negative dentries are incompatible with encoding and
+	 * case-insensitiveness
+	 */
+	if (test_bit(HFSPLUS_SB_CASEFOLD, &sbi->flags))
+		d_invalidate(dentry);
 out:
 	mutex_unlock(&sbi->vh_mutex);
 	return res;
-- 
2.25.1


             reply	other threads:[~2021-04-16 17:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16 17:20 Chung-Chiang Cheng [this message]
2021-04-16 17:35 ` [PATCH] hfsplus: prevent negative dentries when casefolded Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210416172012.8667-1-cccheng@synology.com \
    --to=shepjeng@gmail.com \
    --cc=cccheng@synology.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).