2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
41 void usage(char *progname);
42 void writeblk(int fd);
43 void truncfile(int fd);
48 fprintf(stderr, "usage: %s [-l filesize] [-b blocksize] [-c count] [-s seed] [-o fileoffset (hex)] [-v] filename\n",
54 main(int argc, char *argv[])
59 filesize = 256*1024*1024;
61 count = filesize/blocksize;
65 while ((ch = getopt(argc, argv, "b:l:s:c:o:v")) != EOF) {
67 case 'b': blocksize = atoi(optarg); break;
68 case 'l': filesize = atol(optarg); break;
69 case 's': seed = atoi(optarg); break;
70 case 'c': count = atoi(optarg); break;
71 case 'o': fileoffset = strtoll(optarg, NULL, 16); break;
72 case 'v': verbose++; break;
73 default: usage(argv[0]); break;
77 filename = argv[optind];
80 printf("Seed = %d (use \"-s %d\" to re-execute this test)\n", seed, seed);
84 * Open the file, write rand block in random places, truncate the file,
85 * repeat ad-nauseum, then close the file.
87 if ((fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) {
91 for (i = 0; i < count; i++) {
94 if (verbose && ((i % 100) == 0)) {
110 static char *buffer = NULL;
112 if ((buffer == NULL) && ((buffer = calloc(1, blocksize)) == NULL)) {
117 offset = random() % filesize;
118 if (lseek64(fd, (off64_t)(fileoffset + offset), SEEK_SET) < 0) {
122 *(long *)buffer = *(long *)(buffer+256) = (long)offset;
123 if (write(fd, buffer, blocksize) < blocksize) {
128 printf("writing data at offset=%llx\n",
129 (fileoffset + offset));
137 offset = random() % filesize;
138 if (ftruncate64(fd, (off64_t)(fileoffset + offset)) < 0) {
143 printf("truncated file to offset %llx\n",
144 (fileoffset + offset));