copy_file_range(2) System Calls Manual copy_file_range(2) copy_file_range - (libc -lc) #define _GNU_SOURCE #define _FILE_OFFSET_BITS 64 #include ssize_t copy_file_range(int fd_in, off_t *_Nullable off_in, int fd_out, off_t *_Nullable off_out, size_t size, unsigned int flags); copy_file_range() . size fd_in fd_out . off_in off_out: o off_in (NULL) fd_in . o off_in (NULL) off_in fd_in. fd_in off_in . fd_in fd_out . . flags 0. copy_file_range() . . fd_in copy_file_range() . copy_file_range() -1 errno . EBADF . EBADF fd_in fd_out . EBADF O_APPEND ( open(2)) fd_out. EFBIG . EFBIG . . EFBIG . SIGXFSZ. EINVAL flags 0. EINVAL fd_in fd_out . EINVAL fd_in fd_out . EIO / . EISDIR fd_in fd_out . ENOMEM . ENOSPC . EOPNOTSUPP ( 5.19) . EOVERFLOW . EPERM fd_out . ETXTBSY fd_in fd_out . EXDEV ( 5.3) fd_in fd_out . EXDEV ( 5.19) fd_in fd_out . 5.3. . 5.19 . BUGS 5.19. 5.19 . . 4.5. glibc 2.30 glibc 2.27 glibc . glibc 2.30 ENOSYS .BR copy_file_range (). fd_in copy_file_range() . copy_file_range() lseek(2) SEEK_DATA SEEK_HOLE . copy_file_range() " " ( ) ( NFS). _FILE_OFFSET_BITS 64 off_in off_out copy_file_range x86 ARM 32 off_t 32 . 5.3 5.18 . . #define _GNU_SOURCE #define _FILE_OFFSET_BITS 64 #include #include #include #include #include #include int main(int argc, char *argv[]) { int fd_in, fd_out; off_t size, ret; struct stat stat; if (argc != 3) { fprintf(stderr, ": %s <> <>\n", argv[0]); exit(EXIT_FAILURE); } fd_in = open(argv[1], O_RDONLY); if (fd_in == -1) { perror("open (argv[1])"); exit(EXIT_FAILURE); } if (fstat(fd_in, &stat) == -1) { perror("fstat"); exit(EXIT_FAILURE); } size = stat.st_size; fd_out = open(argv[2], O_CREAT | O_WRONLY | O_TRUNC, 0644); if (fd_out == -1) { perror("open (argv[2])"); exit(EXIT_FAILURE); } do { ret = copy_file_range(fd_in, NULL, fd_out, NULL, size, 0); if (ret == -1) { perror("copy_file_range"); exit(EXIT_FAILURE); } size -= ret; } while (size > 0 && ret > 0); close(fd_in); close(fd_out); exit(EXIT_SUCCESS); } lseek(2), sendfile(2), splice(2) 3 . . : . 6.18 8 2026 copy_file_range(2)