[PATCH] bfs: update target dirent when overwriting rename

From: Yichong Chen

Date: Tue Aug 25 2026 - 22:37:09 EST


When bfs_rename() overwrites an existing target, it drops the link count of
the target inode but does not update the target directory entry to point to
the source inode.

The in-memory dentry state looks correct until the filesystem is remounted.
After remount, the target name still points to the old inode number, which
has already been dropped.

Update the existing target directory entry with the source inode number and
mark its metadata buffer dirty. Also update the target directory timestamp
when the rename crosses directories.

Signed-off-by: Yichong Chen <chenyichong@xxxxxxxxxxxxx>
---
fs/bfs/dir.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/fs/bfs/dir.c b/fs/bfs/dir.c
index 91a4871fa051..199564270e6c 100644
--- a/fs/bfs/dir.c
+++ b/fs/bfs/dir.c
@@ -238,6 +238,14 @@ static int bfs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
old_inode->i_ino);
if (error)
goto end_rename;
+ } else {
+ new_de->ino = cpu_to_le16((u16)old_inode->i_ino);
+ mmb_mark_buffer_dirty(new_bh, &BFS_I(new_dir)->i_metadata_bhs);
+ if (new_dir != old_dir) {
+ inode_set_mtime_to_ts(new_dir,
+ inode_set_ctime_current(new_dir));
+ mark_inode_dirty(new_dir);
+ }
}
old_de->ino = 0;
inode_set_mtime_to_ts(old_dir, inode_set_ctime_current(old_dir));
--
2.51.0