It would cause serious problem that a user program try to write the large data to a file by a write system call.
#include "kernel/types.h"#include "kernel/stat.h"#include "user/user.h"#include "kernel/fs.h"#include "kernel/fcntl.h"void main(){ int fd = open("TEST2", O_CREATE | O_RDWR); char buf[((10-1-1-2) / 2) * BSIZE + 10] = {0}; for (int i = 0; i < ((10-1-1-2) / 2) * BSIZE + 9; i++) { buf[i] = 'x'; } printf("%s\n", buf); write(fd, buf, ((10-1-1-2) / 2) * BSIZE + 10); exit(0);}
It's fine if nothing happend.
If a crash happend after the first loop before the second.
The TEST2
file is existing and it's 3072 bytes.Despite the fact that xv6-book claims that each syscall promises their writes would be atomic, the implementation cannot guarantee that the write syscall is atomic.