#define _GNU_SOURCE #define _FILE_OFFSET_BITS 64 #include #include #include #include #include #include #include static void usage(int argc, char **argv) { (void)argc; printf("Usage: %s \n", argv[0]); exit(EXIT_FAILURE); } int main(int argc, char **argv) { int fd, ret; off_t i, blk; const int blk_size = 4096; struct stat file_stat; if (argc != 2) usage(argc, argv); fd = open(argv[1], O_RDWR); if (fd < 0) { perror("open"); return EXIT_FAILURE; } ret = fstat(fd, &file_stat); if (ret < 0) { perror("stat"); close(fd); return EXIT_FAILURE; } blk = (file_stat.st_size + blk_size - 1) / blk_size; for (i = 0; i < blk; i += 10) { printf("i: %llu\n", i); ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, i * blk_size, blk_size * 6); if (ret < 0) { perror("fallcate"); close(fd); return EXIT_FAILURE; } } fsync(fd); close(fd); return EXIT_SUCCESS; }