linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hfsplus: prevent negative dentries when casefolded
@ 2021-04-16 17:20 Chung-Chiang Cheng
  2021-04-16 17:35 ` Al Viro
  0 siblings, 1 reply; 2+ messages in thread
From: Chung-Chiang Cheng @ 2021-04-16 17:20 UTC (permalink / raw)
  To: christian.brauner, linux-fsdevel, linux-kernel; +Cc: cccheng

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] hfsplus: prevent negative dentries when casefolded
  2021-04-16 17:20 [PATCH] hfsplus: prevent negative dentries when casefolded Chung-Chiang Cheng
@ 2021-04-16 17:35 ` Al Viro
  0 siblings, 0 replies; 2+ messages in thread
From: Al Viro @ 2021-04-16 17:35 UTC (permalink / raw)
  To: Chung-Chiang Cheng
  Cc: christian.brauner, linux-fsdevel, linux-kernel, cccheng

On Sat, Apr 17, 2021 at 01:20:12AM +0800, Chung-Chiang Cheng wrote:
> 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.

Look into the way vfat et.al. are dealing with that (see their
->d_revalidate()).

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-16 17:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-16 17:20 [PATCH] hfsplus: prevent negative dentries when casefolded Chung-Chiang Cheng
2021-04-16 17:35 ` Al Viro

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).