Re: atomically swap two files

Pádraig Brady
2010-11-26T11:49:18Z

On 25/11/10 20:11, Frank A. Kingswood wrote:
> 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.