Easy
Power loss after write() returns but before fsync()
write() returns 13 (success) as shown. The machine loses power at the point marked in the comment, after write() returns but before fsync() or close() runs. Is "critical data" guaranteed to be recoverable from output.dat after reboot?
main.cpp
#include <fcntl.h>
#include <unistd.h>
#include <cstdio>
int main() {
int fd = open("output.dat", O_WRONLY | O_CREAT | O_TRUNC, 0644);
ssize_t n = write(fd, "critical data", 13);
printf("write returned %zd\n", n); // prints 13
// power loss happens here, before fsync() or close()
close(fd);
return 0;
}30 of 53 in Operating Systems