1 /*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /*
21 * FILE : lftest.c
22 * DESCRIPTION : The purpose of this test is to verify the file size limitations of a filesystem.
23 * It writes one buffer at a time and lseeks from the beginning of the file to the
24 * end of the last write position. The intent is to test lseek64.
25 * HISTORY:
26 * 06/19/01 : Written by Jeff Martin(martinjn@us.ibm.com) to test large files on jfs.
27 * 07/12/01 : Added timing.
28 *
29 */
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <unistd.h>
36 #include <fcntl.h>
37 #include <time.h>
38
39 /* set write buffer size to whatever floats your boat. I usually use 1M */
40 #define BSIZE 1048576L
41 char buf[BSIZE];
42
main(int argc,char * argv[])43 int main(int argc, char *argv[])
44 {
45 off_t i;
46 long bufnum;
47 off_t fd;
48 time_t time1, time2;
49 int writecnt = 0, seekcnt = 0, diff;
50
51 time1 = time(NULL);
52
53 if (argc != 2 || atoi(argv[1]) < 1) {
54 printf("usage:<# of %ld buffers to write>\n", BSIZE);
55 exit(3);
56 }
57 bufnum = strtol(argv[1], NULL, 0);
58 printf("Started building a %lu megabyte file @ %s\n", bufnum,
59 asctime(localtime(&time1)));
60
61 buf[0] = 'A';
62 for (i = 1; i < BSIZE; i++)
63 buf[i] = '0';
64 buf[BSIZE - 1] = 'Z';
65
66 if ((fd = creat("large_file", 0755)) == -1)
67 perror("lftest: ");
68
69 for (i = 0; i < bufnum; i++) {
70 if (write(fd, buf, BSIZE) == -1)
71 return -1;
72 else {
73 printf(".");
74 writecnt++;
75 fflush(stdout);
76 }
77 fsync(fd);
78 if (lseek(fd, (i + 1) * BSIZE, 0) == -1)
79 return -1;
80 else
81 seekcnt++;
82 }
83 close(fd);
84 time2 = time(NULL);
85 printf("\nFinished building a %lu megabyte file @ %s\n", bufnum,
86 asctime(localtime(&time2)));
87 diff = time2 - time1;
88 printf("Number of Writes: %d\n"
89 "Number of Seeks: %d\n"
90 "Total time for test to run: %d minute(s) and %d seconds\n",
91 writecnt, seekcnt, diff / 60, diff % 60);
92
93 return 0;
94 }
95