IOCTL-FICLONERANGE(2) | Linux Programmer's Manual | IOCTL-FICLONERANGE(2) |
ioctl_ficlonerange, ioctl_ficlone - share some the data of one file with another file
#include <sys/ioctl.h>
#include <linux/fs.h>
int ioctl(int dest_fd, FICLONERANGE, struct
file_clone_range *arg);
int ioctl(int dest_fd, FICLONE, int
src_fd);
If a filesystem supports files sharing physical storage between multiple files ("reflink"), this ioctl(2) operation can be used to make some of the data in the src_fd file appear in the dest_fd file by sharing the underlying storage, which is faster than making a separate physical copy of the data. Both files must reside within the same filesystem. If a file write should occur to a shared region, the filesystem must ensure that the changes remain private to the file being written. This behavior is commonly referred to as "copy on write".
This ioctl reflinks up to src_length bytes from file descriptor src_fd at offset src_offset into the file dest_fd at offset dest_offset, provided that both are files. If src_length is zero, the ioctl reflinks to the end of the source file. This information is conveyed in a structure of the following form:
struct file_clone_range {
__s64 src_fd;
__u64 src_offset;
__u64 src_length;
__u64 dest_offset; };
Clones are atomic with regards to concurrent writes, so no locks need to be taken to obtain a consistent cloned copy.
The FICLONE ioctl clones entire files.
On error, -1 is returned, and errno is set to indicate the error.
Error codes can be one of, but are not limited to, the following:
These ioctl operations first appeared in Linux 4.5. They were previously known as BTRFS_IOC_CLONE and BTRFS_IOC_CLONE_RANGE, and were private to Btrfs.
This API is Linux-specific.
Because a copy-on-write operation requires the allocation of new storage, the fallocate(2) operation may unshare shared blocks to guarantee that subsequent writes will not fail because of lack of disk space.
This page is part of release 4.16 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.
2017-09-15 | Linux |