9 // not correctly in the headers yet!!
11 #define O_DIRECT 040000 /* direct disk access hint */
14 #define BLOCKSIZE 4096
16 int main(int argc, char **argv)
24 printf("Usage: %s file nr_pages\n", argv[0]);
28 pages = strtoul(argv[2], 0, 0);
29 printf("directio on %s for %d pages \n", argv[1], pages);
31 buf = mmap(0, pages * BLOCKSIZE, PROT_READ|PROT_WRITE,
32 MAP_PRIVATE|MAP_ANON, 0, 0);
34 printf("No memory %s\n", strerror(errno));
38 fd = open(argv[1], O_DIRECT | O_RDWR | O_CREAT);
40 printf("Cannot open %s: %s\n", argv[1], strerror(errno));
44 rc = read(fd, buf, pages * BLOCKSIZE);
45 if (rc != pages * BLOCKSIZE) {
46 printf("Read error: %s, rc %d\n", strerror(errno), rc);
50 if ( lseek(fd, 0, SEEK_SET) != 0 ) {
51 printf("Cannot seek %s\n", strerror(errno));
55 rc = write(fd, buf, pages * BLOCKSIZE);
56 if (rc != pages * BLOCKSIZE) {
57 printf("Write error %s\n", strerror(errno));