#include #include #include #include #include int main(int ac, char **av) { struct stat sb; ssize_t bs; int fd; if (ac < 3) { fprintf(stderr, "usage: %s file-to-read block-size\n", av[0]); return (1); } if (stat(av[1], &sb) != 0) { perror("stat"); return (2); } bs = atol(av[2]); if (!(bs > 0)) bs = sb.st_blksize; printf("using i/o size %zd (optimal %d)\n", bs, sb.st_blksize); fd = open(av[1], O_RDONLY); if (fd == -1) { perror("open"); return (3); } char buf[bs]; for (int cnt = 0; ; cnt++) { ssize_t rb; rb = read(fd, buf, sizeof(buf)); if (rb == -1) { perror("read"); fprintf(stderr, "%d reads were successful\n", cnt); return (4); } else if (rb < sizeof(buf)) break; } return (0); }