8 int main(int argc, char **argv)
15 fprintf(stderr, "Usage: %s <file> <size-in-KB>\n",
20 fsize = strtol(argv[2], NULL, 10);
22 fprintf(stderr, "Invalid file size: %s\n", argv[2]);
27 fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0644);
29 perror("Cannot open file");
33 buf = mmap(NULL, fsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
34 if (buf == MAP_FAILED) {
35 perror("Cannot memory map");
40 * We extend the file byte-by-byte through fallocate(2) and write data
41 * to each byte through the mmap. Then we verify whether the data is
42 * really there to see whether the zeroing of last file page during
43 * writeback didn't corrupt the data.
45 for (i = 0; i < fsize; i++) {
46 if (posix_fallocate(fd, i, 1) != 0) {
47 perror("Cannot fallocate");
54 "Value not written correctly (off=%lu)\n",
60 for (i = 0; i < fsize; i++) {
62 fprintf(stderr, "Value has been modified (off=%lu)\n",