1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2004 Silicon Graphics, Inc.
8 * Write a bunch of holes to create a bunch of extents.
14 uint64_t num_holes = 1000;
21 unsigned int blocksize;
24 #define JUMP_SIZE (128 * 1024)
25 #define NUMHOLES_TO_SIZE(i) (i * JUMP_SIZE)
26 #define SIZE_TO_NUMHOLES(s) (s / JUMP_SIZE)
31 fprintf(stderr, "%s [-b blocksize] [-n num-holes] [-s status-num]"
32 " [-o start-offset] [-vwp] file\n", progname);
37 main(int argc, char *argv[])
45 unsigned char *buffer = NULL;
50 while ((c = getopt(argc, argv, "b:n:o:ps:vw")) != -1) {
53 blocksize = atoi(optarg);
56 num_holes = atoll(optarg);
68 status_num = atoi(optarg);
71 fileoffset = strtoull(optarg, NULL, 16);
78 filename = argv[optind];
82 buffer = malloc(blocksize);
84 fprintf(stderr, "%s: blocksize to big to allocate buffer\n", progname);
88 oflags = O_RDWR | O_CREAT;
89 oflags |= (preserve ? 0 : O_TRUNC) |
92 if ((fd = open(filename, oflags, 0666)) < 0) {
97 if (fstat(fd, &stat) < 0) {
102 curr_holes = SIZE_TO_NUMHOLES(stat.st_size);
103 if (num_holes < curr_holes) {
104 /* we need to truncate back */
105 if (ftruncate(fd, NUMHOLES_TO_SIZE(num_holes)) < 0) {
110 printf("truncating back to %llu\n",
112 NUMHOLES_TO_SIZE(num_holes));
120 if (curr_holes != 0 && verbose_opt) {
121 printf("creating %llu more holes\n",
122 (unsigned long long)num_holes - curr_holes);
125 /* create holes by seeking and writing */
126 for (i = curr_holes; i < num_holes; i++) {
128 offset = NUMHOLES_TO_SIZE(i) + fileoffset;
130 if (lseek64(fd, offset, SEEK_SET) < 0) {
135 if (write(fd, buffer, blocksize) < blocksize) {
140 if (verbose_opt && ((i+1) % status_num == 0)) {
141 printf("seeked and wrote %llu times\n",
142 (unsigned long long)i + 1);