2 * Punch out every other block in a file.
3 * Copyright (C) 2016 Oracle.
16 printf("Usage: %s [-o offset] [-i interval] [-s size] file\n", cmd);
17 printf("Punches every other block in the file by default,\n");
18 printf("or 'size' blocks every 'interval' blocks starting at\n");
19 printf("'offset'. Units are in fstatfs blocks.\n");
23 int main(int argc, char *argv[])
28 off_t start_offset = 0;
35 int size = 1; /* punch $SIZE blocks ... */
36 int interval = 2; /* every $INTERVAL blocks */
38 while ((c = getopt(argc, argv, "i:o:s:")) != EOF) {
41 interval = atoi(optarg);
45 start_offset = strtoull(optarg, NULL, 0);
47 fprintf(stderr, "invalid offset '%s'\n", optarg);
60 printf("interval must be > 0\n");
65 printf("size must be > 0\n");
69 if (optind != argc - 1)
72 fd = open(argv[optind], O_WRONLY);
76 error = fstat(fd, &s);
80 error = fstatfs(fd, &sf);
87 mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
88 for (offset = start_offset * blksz;
90 offset += blksz * interval) {
91 error = fallocate(fd, mode, offset, blksz * size);
105 perror(argv[optind]);