2 * Punch out every other block in a file.
3 * Copyright (C) 2016 Oracle.
16 printf("Usage: %s [-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 with options.\n");
22 int main(int argc, char *argv[])
33 int size = 1; /* punch $SIZE blocks ... */
34 int interval = 2; /* every $INTERVAL blocks */
36 while ((c = getopt(argc, argv, "i:s:")) != EOF) {
39 interval = atoi(optarg);
50 printf("interval must be > 0\n");
55 printf("size must be > 0\n");
59 if (optind != argc - 1)
62 fd = open(argv[optind], O_WRONLY);
66 error = fstat(fd, &s);
70 error = fstatfs(fd, &sf);
77 mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
78 for (offset = 0; offset < sz; offset += blksz * interval) {
79 error = fallocate(fd, mode, offset, blksz * size);