fd1=open(dirname(file))
fd2=openat(fd1, NULL, O_CREAT) // Creates an unlinked file
write(fd2)
flinkat(fd1, fd2, basename(file)) // Should guarantee fd2 is written to disk before linking.
close(fd2)
close(fd1)
This seems race free:
doesn't break if the directory is moved during write
doesn't let other apps see or modify the temp file while writing
doesn't leave a broken tempfile around on app crash
doesn't end up with an empty file on system crash
Ts'o: Delayed allocation and the zero-length file problem
Posted Mar 14, 2009 1:41 UTC (Sat) by dcoutts (guest, #5387) [Link]
Ts'o: Delayed allocation and the zero-length file problem
Posted Mar 15, 2009 23:25 UTC (Sun) by halfline (subscriber, #31920) [Link]
Ts'o: Delayed allocation and the zero-length file problem
Posted Mar 21, 2009 0:34 UTC (Sat) by spitzak (guest, #4593) [Link]
Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds