2 * Copyright (c) 2000-2004 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
20 * Write a bunch of holes to create a bunch of extents.
26 uint64_t num_holes = 1000;
33 unsigned int blocksize;
36 #define JUMP_SIZE (128 * 1024)
37 #define NUMHOLES_TO_SIZE(i) (i * JUMP_SIZE)
38 #define SIZE_TO_NUMHOLES(s) (s / JUMP_SIZE)
43 fprintf(stderr, "%s [-b blocksize] [-n num-holes] [-s status-num]"
44 " [-o start-offset] [-vwp] file\n", progname);
49 main(int argc, char *argv[])
57 unsigned char *buffer = NULL;
62 while ((c = getopt(argc, argv, "b:n:o:ps:vw")) != -1) {
65 blocksize = atoi(optarg);
68 num_holes = atoll(optarg);
80 status_num = atoi(optarg);
83 fileoffset = strtoull(optarg, NULL, 16);
90 filename = argv[optind];
94 buffer = malloc(blocksize);
96 fprintf(stderr, "%s: blocksize to big to allocate buffer\n", progname);
100 oflags = O_RDWR | O_CREAT;
101 oflags |= (preserve ? 0 : O_TRUNC) |
102 (wsync ? O_SYNC : 0);
104 if ((fd = open(filename, oflags, 0666)) < 0) {
109 if (fstat(fd, &stat) < 0) {
114 curr_holes = SIZE_TO_NUMHOLES(stat.st_size);
115 if (num_holes < curr_holes) {
116 /* we need to truncate back */
117 if (ftruncate(fd, NUMHOLES_TO_SIZE(num_holes)) < 0) {
122 printf("truncating back to %llu\n",
124 NUMHOLES_TO_SIZE(num_holes));
132 if (curr_holes != 0 && verbose_opt) {
133 printf("creating %llu more holes\n",
134 (unsigned long long)num_holes - curr_holes);
137 /* create holes by seeking and writing */
138 for (i = curr_holes; i < num_holes; i++) {
140 offset = NUMHOLES_TO_SIZE(i) + fileoffset;
142 if (lseek64(fd, offset, SEEK_SET) < 0) {
147 if (write(fd, buffer, blocksize) < blocksize) {
152 if (verbose_opt && ((i+1) % status_num == 0)) {
153 printf("seeked and wrote %llu times\n",
154 (unsigned long long)i + 1);