Search code examples
filesystemsntfsfile-lockingfat32

Windows File/Directory Lock


Say, I am copying or creating a file foo.txt in a path a/b/c. While it is getting copied, is it possible to rename any part of the path. I tried changing c (immediate parent), but it end ups into Access denied, while renaming b worked. Why so? And, let's say if I'm copying 2 files foo1 and foo2 to the same directory on the Windows filesystem simultaneously; would it affect the performance of any? Alternatively, will any of the copying process will take a lock the folder? If yes, till what level?


Solution

  • There's nothing in the file system itself that precludes you from renaming a, b, or c while writing to foo.txt. I suspect the utility you're using has opened the folder with access that denies other processes write or delete access to the folder itself (which has nothing to do with the files therein).

    In NTFS, renaming a folder (or even moving it somewhere on the same volume) doesn't cause the identity of the folder to change. I imagine the utility opens the (leafiest) folder in order to prevent it from being deleted out from under it. Reasonable, defensive behavior.

    Moving a folder (within the same volume) also has no impact on where the writes to it's contained files occur. They're allocated on demand out of available sectors, and where those sectors are is not related to the conceptual location afforded by the file hierarchy. So, I can't see where a mid-copy rename would have any impact on performance - over the (negligible) price of the rename itself