Atomic rename
Atomic rename replaces an existing destination pathname without exposing an intermediate missing destination to concurrent lookups.
For Linux rename(), source and destination must be on the same mounted filesystem; even separate mount points of one filesystem produce EXDEV. Existing descriptors retain their original file references, and other hard links are unaffected. Both pathnames may temporarily refer to the source, so the guarantee is not a two-path snapshot. Success establishes visibility, not crash durability: the file-data and directory-persistence requirements must be handled separately. A lock held on the old file does not automatically coordinate writers opening its replacement; see the scoped lock-identity observation. [6]
With ordinary final-component symbolic links, Linux rename() moves or replaces the link itself rather than following it. Renaming a distinct file over such a destination leaves its referent unchanged. Intermediate symlink components can still be followed. If both operands already name the same file, rename() succeeds without changing the names. [1]
Relations
- related
- Mount point, Directory fsync, Open file description, Inode, Hard link, Unlink, Crash consistency, Advisory file lock, Open-file-description lock, Symbolic link, Path resolution, OverlayFS, SpanFS
Advantages
- Publishes a replacement without first removing the destination name.
Limitations
- Does not redirect already-open descriptors or update other hard links.
- Does not by itself make replacement data or directory entries crash-persistent.
- On NFS, a reported rename failure can follow successful server execution; NFSv4.1 replay guarantees depend on session and reply-cache recovery.