#define _GNU_SOURCE #include #include #include #include #include #define FALLOC_FL_PUNCH_HOLE 0x02 #define FALLOC_FL_KEEP_SIZE 0X01 int main(int argc, char **argv) { int fd; int mode = 0; int ret = 0; if (argc < 2) { _exit(1); } mode = (mode | FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE); if ((fd = open(argv[1], O_RDWR)) < 0) { fprintf(stderr, "Cannot open file %s\n", argv[1]); _exit(1); } ret= fallocate(fd,mode,4096,4096); if( ret != 0) perror("Fallocate fail\n"); printf("ret = %d\n",ret); close(fd); return 0; }