Skip to contentSkip to conversation

atomically swap two files

DISCUSSION Frank A. Kingswood 3 participants 3 messages Nov 25, 2010 – Nov 26, 2010

lore
Share & tools
lore
#0 lore raw

Hi!

Is it possible to swap two files in an atomic way, so that after the syscall either the two files have exchanged names or neither has been modified?

I suspect that btrfs could do it, but I'm wondering about ext3/4.

Frank

#1 lore raw
Quoted 7 lines · Frank A. Kingswood

Hi!

Is it possible to swap two files in an atomic way, so that after the syscall either the two files have exchanged names or neither has been modified?

I suspect that btrfs could do it, but I'm wondering about ext3/4.

I don't think there is anything equivalent to exchangedata() on Linux
http://developer.apple.com/library/mac/#DOCUMENTATION/Darwin/Reference/ManPages/man2/exchangedata.2.html

I've written some notes on atomically replacing
file contents with standard tools here:
http://www.pixelbeat.org/docs/unix_file_replacement.html

cheers,
Pádraig.

#2 lore raw
Quoted 11 lines · Pádraig Brady
Quoted 7 lines · Frank A. Kingswood

Hi!

Is it possible to swap two files in an atomic way, so that after the syscall either the two files have exchanged names or neither has been modified?

I suspect that btrfs could do it, but I'm wondering about ext3/4.

I don't think there is anything equivalent to exchangedata() on Linux
http://developer.apple.com/library/mac/#DOCUMENTATION/Darwin/Reference/ManPages/man2/exchangedata.2.html

XFS can do that, though the interface is an ioctl (XFS_IOC_SWAPEXT) whose parameters are closely tied to the functionality of the only
user: the online defragmenter (xfs_fsr). It would be pretty easy to wire it up to such a syscall if one existed, though....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]