11 // not correctly in the headers yet!!
13 #define O_DIRECT 040000 /* direct disk access hint */
16 int main(int argc, char **argv)
25 printf("Usage: %s file nr_blocks\n", argv[0]);
29 blocks = strtoul(argv[2], 0, 0);
30 fd = open(argv[1], O_DIRECT | O_RDWR | O_CREAT, 0644);
32 printf("Cannot open %s: %s\n", argv[1], strerror(errno));
36 if (fstat(fd, &st) < 0) {
37 printf("Cannot stat %s: %s\n", argv[1], strerror(errno));
41 printf("directio on %s for %dx%lu blocks \n", argv[1], blocks,
44 buf = mmap(0, blocks * st.st_blksize, PROT_READ|PROT_WRITE,
45 MAP_PRIVATE|MAP_ANON, 0, 0);
47 printf("No memory %s\n", strerror(errno));
51 rc = write(fd, buf, blocks * st.st_blksize);
52 if (rc != blocks * st.st_blksize) {
53 printf("Write error %s (rc = %d)\n", strerror(errno), rc);
57 if (lseek(fd, 0, SEEK_SET) != 0) {
58 printf("Cannot seek %s\n", strerror(errno));
62 rc = read(fd, buf, blocks * st.st_blksize);
63 if (rc != blocks * st.st_blksize) {
64 printf("Read error: %s (rc = %d)\n", strerror(errno), rc);