#include #include #include #include #include #include #include #include #include #define NR 256 #define SIZE 4096 int main(int argc, char **argv) { int fd, rc, n, iter = 0; const char *path; static unsigned char __attribute__ ((aligned (4096))) buf[NR][SIZE]; if (argc != 2) { fprintf(stderr, "usage: blktest2 [PATH]\n"); exit(1); } path = argv[1]; printf("opening %s for O_DIRECT access\n", path); fd = open(path, O_CREAT/*|O_DIRECT*/|O_RDWR, 0666); if (fd < 0) err(1,"unable to open file"); while(1) { if ((iter%10)==0) printf("iteration %d ...", iter); if (lseek(fd, (iter%NR)*SIZE, SEEK_SET) < 0) err(1, "seek for write %d %d\n", iter, n); memset(buf[iter%NR], 0xaa, SIZE); rc = write(fd, buf[iter%NR], SIZE); memset(buf[iter%NR], 0x55, SIZE); if (rc == -1) //warn("write failed"); err(1, "write failed"); else if (rc != SIZE) err(1, "only wrote %d/%d bytes\n", rc, SIZE); if ((iter%10)==0) printf("\n", iter); iter++; } }