#include #include #include #include #include #include #include int main(int argc, char **argv) { if (argc != 6) { fputs("Error: usage: wrong number of arguments\n", stderr); return -1; } char *src_name = argv[1]; char *dest_name = argv[2]; u_int64_t src_offset = atoll(argv[3]); u_int64_t src_length = atoll(argv[4]); u_int64_t dest_offset = atoll(argv[5]); int src, dest; if ((src = open(src_name, O_RDONLY)) < 0) { perror("Error opening input file"); return 1; } if ((dest = open(dest_name, O_RDWR | O_CREAT)) < 0) { perror("Error opening output file"); return 2; } if (dest_offset == 0) { struct stat buf; stat(dest_name, &buf); dest_offset = buf.st_size; } struct file_clone_range s = {src, src_offset, src_length, dest_offset}; if (ioctl(dest, FICLONERANGE, &s)) { perror("ioctl FICLONERANGE failed"); return 3; } else { return 0; } }