Can two files in a directory be on different filesystems

filesystemsrename

I'm implementing atomic writes (FWIW in Python on Linux & FreeBSD), and I'm writing to a temporary file in the same directory with the file I'm planning to write to (in order to ensure that they are on the same filesystem, and thus rename(2) succeeds and writes can be atomic).

My question is that is there any condition where two files in the same directory be on different filesystems? (I am not following symlinks, so a file symlinked to another file on a different filesystem is not a problem for me).

Best Answer

Yes. It is not only possible to mount directories, but also files. This enables to mount files residing on different file systems into one mutual directory.

Renaming the file results in EBUSY, when mv is used, this usually prints the message “Device or resource busy”. The destination can be renamed without throwing an error. The changes are applied to the new name instead.

Related Question