11 // not correctly in the headers yet!!
13 #define O_DIRECT 040000 /* direct disk access hint */
16 int main(int argc, char **argv)
20 int blocks, seek_blocks;
27 printf("Usage: %s file seek nr_blocks\n", argv[0]);
31 seek_blocks = strtoul(argv[2], 0, 0);
32 blocks = strtoul(argv[3], 0, 0);
33 fd = open(argv[1], O_LARGEFILE | O_DIRECT | O_RDWR | O_CREAT, 0644);
35 printf("Cannot open %s: %s\n", argv[1], strerror(errno));
39 if (fstat64(fd, &st) < 0) {
40 printf("Cannot stat %s: %s\n", argv[1], strerror(errno));
44 printf("directio on %s for %dx%lu bytes \n", argv[1], blocks,
47 seek = (off64_t)seek_blocks * (off64_t)st.st_blksize;
48 if (lseek64(fd, seek, SEEK_SET) < 0) {
49 printf("lseek64 failed: %s\n", strerror(errno));
53 len = blocks * st.st_blksize;
54 buf = mmap(0, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, 0, 0);
56 printf("No memory %s\n", strerror(errno));
60 memset(buf, 0xba, len);
61 rc = write(fd, buf, len);
63 printf("Write error %s (rc = %d)\n", strerror(errno), rc);
67 if (lseek64(fd, seek, SEEK_SET) < 0) {
68 printf("Cannot seek %s\n", strerror(errno));
72 rc = read(fd, buf, len);
74 printf("Read error: %s (rc = %d)\n", strerror(errno), rc);