CS FundamentalsVery hardGATE CS

Which of these is the correct reason that the Unix `rename(old, new)` within one file system is widely used to update a file safely (write a temp file, then rename over the original)?

  1. A. rename copies the data and verifies a checksum
  2. B. rename locks the file against all readers forever
  3. C. rename within a file system is atomic: observers see either the old file or the new one, never a half-written file
  4. D. rename works across file systems by moving blocks

Correct answer: C. rename within a file system is atomic: observers see either the old file or the new one, never a half-written file

POSIX requires rename to replace the target atomically. Combined with fsync of the temp file (and the directory), it gives crash-safe updates. Across file systems rename fails with EXDEV.

More Operating Systems questions

Exams that ask this topic