NTFS Error on rename operation with replace if its hardlink is opened

Hello Guys,

I’ve read “A file cannot be renamed if a file with the same name exists and has open handles”, from “FILE_RENAME_INFORMATION structure” documentation, in “Special rules for renaming open files” section.

So I have tried to create one hardlink on the file “with the same name” before the rename, and surprise, if the hardlink is opened, the rename operation fail.

May someone explain me why ?

Not sure I understand the question.

You should think of rename as “Create hard link to new location, remove hardlink from old location”. So if there is a restriction on the new name for rename it is likely to hold for creating a hard link.

In general in Win32 you cannot delete a directory entry which is open. I would suspect that this extends to deleting files as well their DIRENTs (but I have never done the nature study).

The WSL has introduced all sorts of funk “Posix” ways of deleting dir entries but let’s not go there - mostly they don’t matter unless you are implementing a real file system.

Thank you @rod_widdowson for this precision.

I think I understand rename better.