All posts

6 min readPost 13

macOS and Linux: no rename by handle

On Windows, Obituary verifies file identity and renames into the graveyard through the exact same handle. Neither macOS nor Linux exposes rename-by-fd, and POSIX immediately reuses inodes after deletion. Here is how we built non-overwriting move-verify-rollback, stopped inode reuse with file-handle generations and birth times, and shipped 1.1.0 across all three platforms.

On this page
  1. First stance: refuse rather than weaken the contract
  2. Two days later: move without overwrite, verify immediately, roll back on mismatch
  3. The second POSIX trap: instant inode reuse
  4. Running the full suite on Linux and macOS CI caught four real bugs

When Obituary buries an expired file on Windows, it leans on an ironclad primitive: open the target handle, verify its volume serial number and 128-bit NTFS file ID, and rename it into the graveyard through that exact same handle. Between verification and movement, no editor can sneak a brand-new file onto the path.

Porting that engine to macOS and Linux ran straight into a POSIX syscall gap:

Neither Linux nor macOS can rename by file descriptor. rename, Linux renameat2, and macOS renameatx_np all take a parent directory descriptor plus a filename string. In the microseconds between checking identity and invoking rename, a concurrent save can swap the path underneath.

First stance: refuse rather than weaken the contract ​

On 10 November we initially held the line: platforms unable to verify-and-move atomically on one handle returned "unsupported" for bury, resurrect, and recycle, leaving files untouched.

We considered a Linux workaround—hard-linking the verified inode into the graveyard via /proc/self/fd, then unlinking and verifying—which narrows the window for regular files yet fails completely on directories. So we dropped it.

The cost was stark: on macOS and Linux, users could register files and run hooks, while expiry burial and resurrection stayed completely disabled.

Two days later: move without overwrite, verify immediately, roll back on mismatch ​

Leaving core features broken for every Mac and Linux developer was untenable. On 12 November we adopted a five-step move-verify-rollback protocol for POSIX:

  1. Pin both source and destination parent directory descriptors and move strictly without overwrite: renameat2(RENAME_NOREPLACE) on Linux, renameatx_np(RENAME_EXCL) on macOS.
  2. Open the source object beforehand (O_PATH on Linux, O_EVTONLY on macOS) and keep that descriptor open throughout the move so the kernel cannot recycle the inode mid-flight.
  3. Immediately verify device, inode, file type, and link count inside the grave.
  4. On any mismatch, move the object straight back using the same non-overwriting rename and return a retryable error.
  5. If another file already claimed the original path and rollback cannot proceed, keep the object in the graveyard flagged as an identity mismatch—permanently excluded from automatic purge—and surface its exact location in obit graveyard and obit doctor.

We documented the honest gap against Windows: under a tight race with an editor save, the newer file could briefly bounce into the graveyard and back (or sit frozen for manual review), but it can never be overwritten or silently deleted.

Refusing filesystems without RENAME_NOREPLACE ​

Testing RENAME_NOREPLACE inside WSL Ubuntu exposed an immediate filesystem split:

  • On native ext4, renaming onto an empty slot succeeds and hitting an existing file returns EEXIST.
  • On /mnt/c (the Windows drive mounted via 9p), the kernel returns EINVAL even when the destination does not exist.

Whenever a filesystem lacks non-overwriting rename, Obituary refuses outright instead of falling back to plain rename.

Terminal output running renameat2 RENAME_NOREPLACE in WSL across ext4 and 9p: ext4 succeeds or returns EEXIST as expected, while 9p on /mnt/c returns EINVAL
Real renameat2(RENAME_NOREPLACE) test in WSL: supported on ext4, rejected with invalid argument on 9p (/mnt/c), where Obituary refuses to bury.

The second POSIX trap: instant inode reuse ​

That same evening exposed a second hazard Windows never hits:

Delete a file on Linux and immediately recreate one at the same path, and the new file frequently receives the exact same inode number. Identifying files solely by (device, inode) lets an older countdown bury a brand-new file.

We packed an 8-byte creation stamp into the high bits of our file ID:

  • Linux: hash of the exported kernel file handle (which carries the inode generation) combined with statx birth time.
  • macOS: filesystem birth time.
  • Filesystems unable to provide a persistent stamp (such as overlayfs without nfs_export) refuse scheduled lifespans; explicit immediate obit bury still works because it pins the source file descriptor live.
  • Legacy bare-inode entries stay untouched on expiry while list and doctor prompt re-marking.

Reproducing this on WSL native ext4: marking a.txt for 6 seconds, deleting it, and writing a new a.txt produced the exact same inode 703107 on both stat calls—yet expiry cleanup detected the identity change, kept the new contents intact, and left the graveyard empty.

Terminal run on Linux ext4: a.txt is marked for 6 seconds, deleted, and recreated with identical inode 703107; expiry cleanup retains the entry for retry, preserves new contents, and leaves the graveyard empty
Linux build running on WSL ext4: recreating a deleted file reuses inode 703107 verbatim, yet Obituary rejects the mismatch and preserves the new file.

Running the full suite on Linux and macOS CI caught four real bugs ​

By 20:58 that night, the full test suite and native safety mutations were green on both Linux (with -race) and macOS runners. Windows-only fixtures were cleanly abstracted or skipped with explicit reasons, while missing POSIX primitives asserted conservative refusals.

Running real POSIX tests immediately surfaced four bugs that cross-compilation alone had missed (without touching Windows behavior):

  • The delete guard misclassified every POSIX working directory as WSL interop, silently letting native Linux and macOS deletions pass.
  • Uninstall needed to route through obitd while skipping Windows Run keys, Explorer labels, and registry menus.
  • Registration checks needed to inspect tracked paths directly rather than failing over missing whole-volume inode search.
  • Filenames containing colons failed resurrection; initial macOS CI also caught case-insensitive APFS matching, ~/Library/Application Support paths, and /var symlink resolution.

At 12:17 on 13 November, Obituary 1.1.0 shipped across all three platforms, adding macOS launchd and Homebrew Cask support, Linux systemd user timers, SHA-256 verified install scripts, and full terminal delete guards.

All posts