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