#include #include #define __USE_GNU #include #include #include #define ALIGN(buf) (char *) (((unsigned long) (buf) + 4095) & ~(4095)) int main(int argc, char *argv[]) { char *p; int fd, i; int BS, BLOCKS; if (argc < 4) { printf("%s: bs cnt\n", argv[0]); return 1; } BS = atoi(argv[2]); BLOCKS = atoi(argv[3]); fd = open(argv[1], O_RDONLY | O_DIRECT); if (fd == -1) { perror("open"); return 1; } p = ALIGN(malloc(BS + 4095)); for (i = 0; i < BLOCKS; i++) { int r = read(fd, p, BS); if (r == BS) continue; else { if (r == -1) perror("read"); break; } } return 0; }