What are posix/linux/filesystem durability guarantees for ordered file writes?

181 Views Asked by At

Suppose I have a (single-threaded) program that (exclusively) opens a large file and does two non-overlapping writes:

int fd = open(path, O_RDWR);
pwrite(fd, data1, size1, offset1);
pwrite(fd, data2, size2, offset2);
close(fd);

Are there any guarantees (by posix, linux or common filesystems like ext4) that, in case of power failure, no part of data2 will end up in permanent storage unless all of data1 also ends up in permanent storage?

Or, to put it another way, that the file (in permanent storage) won't end up in a state where the second write started while the first hadn't completed?

Or do I have to fsync(fd)/fdatasync(fd) between the writes to achieve this?

0

There are 0 best solutions below