Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6333

Can Xv6 guarantee the write syscall is atomic?

$
0
0

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.

image

image

If a crash happend after the first loop before the second.

image

image

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.

image


Viewing all articles
Browse latest Browse all 6333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>