9 // not correctly in the headers yet!!
10 #define O_DIRECT 040000 /* direct disk access hint */
12 int main(int argc, char **argv)
20 printf("Usage: %s file nr_pages\n", argv[0]);
24 pages = strtoul(argv[2], 0, 0);
25 printf("directio on %s for %d pages \n", argv[1], pages);
27 buf = mmap(0, pages * 4096, PROT_READ|PROT_WRITE,
28 MAP_PRIVATE|MAP_ANON, 0, 0);
30 printf("No memory %s\n", strerror(errno));
34 fd = open(argv[1], O_DIRECT | O_RDWR | O_CREAT);
36 printf("Cannot open %s: %s\n", argv[1], strerror(errno));
40 rc = read(fd, buf, pages * 4096);
41 if (rc != pages * 4096) {
42 printf("Read error: %s, rc %d\n", strerror(errno), rc);
46 if ( lseek(fd, 0, SEEK_SET) != 0 ) {
47 printf("Cannot seek %s\n", strerror(errno));
51 rc = write(fd, buf, pages * 4096);
52 if (rc != pages * 4096) {
53 printf("Write error %s\n", strerror(errno));