exfat: fix parent link count when replacing a sibling directory
Subsystems (3)
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.
--- fs/exfat/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/exfat/namei.c +1 -1
@@ -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
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")Signed-off-by Hungyu Lin <[email protected]>
Applied it to #dev.
Thanks!