Back Home

Table of Contents

Copy File Range

There are times that you may want to copy a file from one location to another. If you use the normal posix functions (open/read/write/close), you’ll have to copy data from the kernel to user space and then back to the kernel.

copy_file_range allows you to copy a section of one file to another without having to do the kernel to userspace dance:

ssize_t copy_file_range(int fd_in, off_t *_Nullable off_in,
                        int fd_out, off_t *_Nullable off_out,
                        size_t len, unsigned int flags);

(Kerrisk 2024) for more details.

References

Kerrisk, Michael. 2024. “Copy_file_range(2) Linux Manual Page.” 2024. https://man7.org/linux/man-pages/man2/copy_file_range.2.html.
View history for this file: on Github