11 // not correctly in the headers yet!!
13 #define O_DIRECT 040000 /* direct disk access hint */
16 int main(int argc, char **argv)
26 printf("Usage: %s file nr_blocks\n", argv[0]);
30 blocks = strtoul(argv[2], 0, 0);
31 fd = open(argv[1], O_DIRECT | O_RDWR | O_CREAT, 0644);
33 printf("Cannot open %s: %s\n", argv[1], strerror(errno));
37 if (fstat(fd, &st) < 0) {
38 printf("Cannot stat %s: %s\n", argv[1], strerror(errno));
42 printf("directio on %s for %dx%lu blocks \n", argv[1], blocks,
45 len = blocks * st.st_blksize;
46 buf = mmap(0, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0);
48 printf("No memory %s\n", strerror(errno));
52 memset(buf, 0xba, len);
53 rc = write(fd, buf, len);
55 printf("Write error %s (rc = %d)\n", strerror(errno), rc);
59 if (lseek(fd, 0, SEEK_SET) != 0) {
60 printf("Cannot seek %s\n", strerror(errno));
64 rc = read(fd, buf, len);
66 printf("Read error: %s (rc = %d)\n", strerror(errno), rc);