Skip to contentSkip to conversation

exfat: fix parent link count when replacing a sibling directory

PATCH Applied Hungyu Lin 2 participants 2 messages Oct 28 – Oct 29

Subsystems (3)
lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH 1/1 exfat: fix parent link count when replacing a sibling directory

exfat_rename() adjusts parent link counts only when a directory moves between different parents. Replacing an existing empty directory in the same parent also removes one subdirectory, but leaves the parent's link count unchanged. For example, renaming one of two sibling directories over the other leaves the parent with four links instead of three.

Also adjust the parent count when a target inode exists in the directory rename case. Keep same-parent renames without replacement and the existing cross-parent accounting unchanged.

Fixes 5f2aa075070c ("exfat: add inode operations")
---
 fs/exfat/namei.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/exfat/namei.c +1 -1
index 68ddb9c5504f..24110e7fde47 100644
@@ -1309,7 +1309,7 @@ static int exfat_rename(const struct mnt_idmap *idmap,
 	else
 		mark_inode_dirty(old_inode);
 
-	if (S_ISDIR(old_inode->i_mode) && old_dir != new_dir) {
+	if (S_ISDIR(old_inode->i_mode) && (old_dir != new_dir || new_inode)) {
 		drop_nlink(old_dir);
 		if (!new_inode)
 			inc_nlink(new_dir);
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 8 lines · Hungyu Lin

exfat_rename() adjusts parent link counts only when a directory moves between different parents. Replacing an existing empty directory in the same parent also removes one subdirectory, but leaves the parent's link count unchanged. For example, renaming one of two sibling directories over the other leaves the parent with four links instead of three.

Quoted 7 lines

Also adjust the parent count when a target inode exists in the directory rename case. Keep same-parent renames without replacement and the existing cross-parent accounting unchanged.

Fixes 5f2aa075070c ("exfat: add inode operations")

Applied it to #dev.
Thanks!