]>
Commit | Line | Data |
---|---|---|
9eb18e17 DW |
1 | .\" Copyright (C) 2016 Oracle. All rights reserved. |
2 | .\" | |
3 | .\" %%%LICENSE_START(VERBATIM) | |
4 | .\" This program is free software; you can redistribute it and/or | |
5 | .\" modify it under the terms of the GNU General Public License as | |
6 | .\" published by the Free Software Foundation. | |
7 | .\" | |
8 | .\" This program is distributed in the hope that it would be useful, | |
9 | .\" but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | .\" GNU General Public License for more details. | |
12 | .\" | |
13 | .\" You should have received a copy of the GNU General Public License | |
14 | .\" along with this program; if not, write the Free Software Foundation, | |
15 | .\" Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
16 | .\" %%%LICENSE_END | |
17 | .TH IOCTL-FICLONERANGE 2 2016-02-10 "Linux" "Linux Programmer's Manual" | |
18 | .SH NAME | |
19 | ioctl_ficlonerange, ioctl_ficlone \- share some the data of one file with another file | |
20 | .SH SYNOPSIS | |
21 | .br | |
22 | .B #include <sys/ioctl.h> | |
23 | .br | |
24 | .B #include <linux/fs.h> | |
25 | .sp | |
26 | .BI "int ioctl(int " dest_fd ", FICLONERANGE, struct file_clone_range * " arg ); | |
27 | .br | |
28 | .BI "int ioctl(int " dest_fd ", FICLONE, int " src_fd ); | |
29 | .SH DESCRIPTION | |
30 | If a filesystem supports files sharing physical storage between multiple | |
31 | files ("reflink"), this | |
32 | .BR ioctl (2) | |
33 | system call can be used to make some of the data in the | |
34 | .B src_fd | |
35 | file appear in the | |
36 | .B dest_fd | |
37 | file by sharing the underlying storage, which is faster than making a separate | |
1d691add MK |
38 | physical copy of the data. |
39 | If a file write should occur to a shared region, | |
9eb18e17 | 40 | the filesystem must ensure that the changes remain private to the file being |
1d691add MK |
41 | written. |
42 | This behavior is commonly referred to as "copy on write". | |
9eb18e17 DW |
43 | |
44 | This ioctl reflinks up to | |
45 | .IR src_length | |
46 | bytes from file descriptor | |
47 | .IR src_fd | |
48 | at offset | |
49 | .IR src_offset | |
50 | into the file | |
51 | .IR dest_fd | |
52 | at offset | |
53 | .IR dest_offset ", | |
1d691add MK |
54 | provided that both are files. |
55 | This information is conveyed in a structure of | |
9eb18e17 DW |
56 | the following form: |
57 | .in +4n | |
58 | .nf | |
59 | ||
60 | struct file_clone_range { | |
61 | __s64 src_fd; | |
62 | __u64 src_offset; | |
63 | __u64 src_length; | |
64 | __u64 dest_offset; | |
65 | }; | |
66 | ||
67 | .fi | |
68 | .in | |
69 | Clones are atomic with regards to concurrent writes, so no locks need to be | |
70 | taken to obtain a consistent cloned copy. | |
71 | ||
72 | The FICLONE ioctl clones entire files. | |
73 | .SH RETURN VALUE | |
74 | On error, \-1 is returned, and | |
75 | .I errno | |
76 | is set to indicate the error. | |
77 | .PP | |
78 | .SH ERRORS | |
79 | Error codes can be one of, but are not limited to, the following: | |
80 | .TP | |
81 | .B EXDEV | |
82 | .IR dest_fd " and " src_fd | |
83 | are not on the same mounted filesystem. | |
84 | .TP | |
85 | .B EISDIR | |
86 | One of the files is a directory and the filesystem does not support shared | |
87 | regions in directories. | |
88 | .TP | |
89 | .B EINVAL | |
1d691add MK |
90 | The filesystem does not support reflinking the ranges of the given files. |
91 | This error can also appear if either file descriptor represents | |
92 | a device, fifo, or socket. | |
93 | Disk filesystems generally require the offset and length arguments | |
94 | to be aligned to the fundamental block size. | |
95 | XFS and btrfs do not support | |
9eb18e17 DW |
96 | overlapping reflink ranges in the same file. |
97 | .TP | |
98 | .B EBADF | |
99 | .IR src_fd | |
100 | is not open for reading; | |
101 | .IR dest_fd | |
102 | is not open for writing or is open for append-only writes; or the filesystem | |
103 | which | |
104 | .IR src_fd | |
105 | resides on does not support reflink. | |
106 | .TP | |
107 | .B EPERM | |
108 | .IR dest_fd | |
109 | is immutable. | |
110 | .TP | |
111 | .B ETXTBSY | |
1d691add MK |
112 | One of the files is a swap file. |
113 | Swap files cannot share storage. | |
9eb18e17 DW |
114 | .TP |
115 | .B EOPNOTSUPP | |
116 | This can appear if the filesystem does not support reflinking either file | |
117 | descriptor. | |
118 | .SH NOTES | |
119 | Because a copy on write operation requires the allocation of new storage, the | |
120 | .B fallocate (2) | |
121 | operation may un-share shared blocks to guarantee that subsequent writes will | |
122 | not fail because of lack of disk space. | |
123 | .SH CONFORMING TO | |
1d691add MK |
124 | This API is Linux-specific. |
125 | This ioctl was previously known as | |
9eb18e17 DW |
126 | .B BTRFS_IOC_CLONE_RANGE |
127 | and was private to btrfs. | |
128 | .fi | |
129 | .in | |
130 | .SH SEE ALSO | |
131 | .BR ioctl (2) |