2 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 void usage(char *progname);
28 void writeblk(int fd);
29 void truncfile(int fd);
34 fprintf(stderr, "usage: %s [-l filesize] [-b blocksize] [-c count] [-s seed] [-o fileoffset (hex)] [-v] filename\n",
40 main(int argc, char *argv[])
43 char *filename = NULL;
45 filesize = 256*1024*1024;
47 count = filesize/blocksize;
51 while ((ch = getopt(argc, argv, "b:l:s:c:o:v")) != EOF) {
53 case 'b': blocksize = atoi(optarg); break;
54 case 'l': filesize = atol(optarg); break;
55 case 's': seed = atoi(optarg); break;
56 case 'c': count = atoi(optarg); break;
57 case 'o': fileoffset = strtoll(optarg, NULL, 16); break;
58 case 'v': verbose++; break;
59 default: usage(argv[0]); break;
63 filename = argv[optind];
66 printf("Seed = %d (use \"-s %d\" to re-execute this test)\n", seed, seed);
70 * Open the file, write rand block in random places, truncate the file,
71 * repeat ad-nauseum, then close the file.
73 if ((fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) {
77 for (i = 0; i < count; i++) {
80 if (verbose && ((i % 100) == 0)) {
96 static char *buffer = NULL;
98 if ((buffer == NULL) && ((buffer = calloc(1, blocksize)) == NULL)) {
103 offset = random() % filesize;
104 if (lseek64(fd, (off64_t)(fileoffset + offset), SEEK_SET) < 0) {
108 *(long *)buffer = *(long *)(buffer+256) = (long)offset;
109 if (write(fd, buffer, blocksize) < blocksize) {
114 printf("writing data at offset=%llx\n",
115 (unsigned long long)(fileoffset + offset));
123 offset = random() % filesize;
124 if (ftruncate64(fd, (off64_t)(fileoffset + offset)) < 0) {
129 printf("truncated file to offset %llx\n",
130 (unsigned long long)(fileoffset + offset));