1 /* 2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README 3 */ 4 5 /* 6 * MONGO READ - simple possible program to read a number of given files 7 * suitable for benchmarking FS read performance 8 */ 9 10 #include <stdio.h> 11 #include <errno.h> 12 #include <sys/types.h> 13 #include <sys/stat.h> 14 #include <fcntl.h> 15 #include <stdlib.h> 16 #include <unistd.h> 17 18 int main(int argc, char **argv) 19 { 20 int fd, rd, i; 21 char *buf; 22 int bufsize = 4096; 23 24 if (argc < 2) { 25 printf("\nUsage: %s filename [,filename2 [,...] ] ]\n\n", 26 argv[0]); 27 return 0; 28 } 29 30 buf = malloc(bufsize); 31 if (buf == 0) { 32 printf("Malloc failed on %d\n", bufsize); 33 return 0; 34 } 35 36 /* Read all given files */ 37 for (i = 1; i < argc; i++) { 38 39 /* open the file */ 40 fd = open(argv[i], O_RDONLY); 41 if (fd == -1) { 42 printf("Open failed (%s)\n", strerror(errno)); 43 return 0; 44 } 45 46 /* read the file */ 47 while ((rd = read(fd, buf, bufsize)) == bufsize) ; 48 if (rd == -1) { 49 printf("Read failed (%s)\n", strerror(errno)); 50 return 0; 51 } 52 close(fd); 53 } 54 55 free(buf); 56 return 0; 57 } 58