1IOCTL-FICLONERANGE(2)      Linux Programmer's Manual     IOCTL-FICLONERANGE(2)
2
3
4

NAME

6       ioctl_ficlonerange,  ioctl_ficlone  -  share  some the data of one file
7       with another file
8

SYNOPSIS

10       #include <sys/ioctl.h>
11       #include <linux/fs.h>
12
13       int ioctl(int dest_fd, FICLONERANGE, struct file_clone_range *arg);
14       int ioctl(int dest_fd, FICLONE, int src_fd);
15

DESCRIPTION

17       If a filesystem supports files sharing physical storage between  multi‐
18       ple files ("reflink"), this ioctl(2) operation can be used to make some
19       of the data in the src_fd file appear in the dest_fd  file  by  sharing
20       the underlying storage, which is faster than making a separate physical
21       copy of the data.  Both files must reside within the  same  filesystem.
22       If  a  file  write should occur to a shared region, the filesystem must
23       ensure that the changes remain private to the file being written.  This
24       behavior is commonly referred to as "copy on write".
25
26       This  ioctl reflinks up to src_length bytes from file descriptor src_fd
27       at offset src_offset into the file dest_fd at offset dest_offset,  pro‐
28       vided  that  both are files.  If src_length is zero, the ioctl reflinks
29       to the end of the source file.   This  information  is  conveyed  in  a
30       structure of the following form:
31
32           struct file_clone_range {
33               __s64 src_fd;
34               __u64 src_offset;
35               __u64 src_length;
36               __u64 dest_offset;
37           };
38
39       Clones  are  atomic with regards to concurrent writes, so no locks need
40       to be taken to obtain a consistent cloned copy.
41
42       The FICLONE ioctl clones entire files.
43

RETURN VALUE

45       On error, -1 is returned, and errno is set to indicate the error.
46

ERRORS

48       Error codes can be one of, but are not limited to, the following:
49
50       EBADF  src_fd is not open for reading; dest_fd is not open for  writing
51              or  is  open  for  append-only  writes;  or the filesystem which
52              src_fd resides on does not support reflink.
53
54       EINVAL The filesystem does not support reflinking  the  ranges  of  the
55              given files.  This error can also appear if either file descrip‐
56              tor represents a device, FIFO, or socket.  Disk filesystems gen‐
57              erally  require the offset and length arguments to be aligned to
58              the fundamental block size.  XFS and Btrfs do not support  over‐
59              lapping reflink ranges in the same file.
60
61       EISDIR One of the files is a directory and the filesystem does not sup‐
62              port shared regions in directories.
63
64       EOPNOTSUPP
65              This can appear if the filesystem does  not  support  reflinking
66              either  file  descriptor, or if either file descriptor refers to
67              special inodes.
68
69       EPERM  dest_fd is immutable.
70
71       ETXTBSY
72              One of the files is a swap file.  Swap files cannot share  stor‐
73              age.
74
75       EXDEV  dest_fd and src_fd are not on the same mounted filesystem.
76

VERSIONS

78       These  ioctl  operations first appeared in Linux 4.5.  They were previ‐
79       ously known as BTRFS_IOC_CLONE and BTRFS_IOC_CLONE_RANGE, and were pri‐
80       vate to Btrfs.
81

CONFORMING TO

83       This API is Linux-specific.
84

NOTES

86       Because  a copy-on-write operation requires the allocation of new stor‐
87       age, the fallocate(2) operation may unshare shared blocks to  guarantee
88       that subsequent writes will not fail because of lack of disk space.
89

SEE ALSO

91       ioctl(2)
92

COLOPHON

94       This  page  is  part of release 4.15 of the Linux man-pages project.  A
95       description of the project, information about reporting bugs,  and  the
96       latest     version     of     this    page,    can    be    found    at
97       https://www.kernel.org/doc/man-pages/.
98
99
100
101Linux                             2017-09-15             IOCTL-FICLONERANGE(2)
Impressum