]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/ioctl_ficlonerange.2
Various pages: Use .nf/.fi in SYNOPSIS
[thirdparty/man-pages.git] / man2 / ioctl_ficlonerange.2
1 .\" Copyright (c) 2016, Oracle. All rights reserved.
2 .\"
3 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
4 .\" This is free documentation; 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; either version 2 of
7 .\" the License, or (at your option) any later version.
8 .\"
9 .\" The GNU General Public License's references to "object code"
10 .\" and "executables" are to be interpreted as the output of any
11 .\" document formatting or typesetting system, including
12 .\" intermediate and printed output.
13 .\"
14 .\" This manual is distributed in the hope that it will be useful,
15 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 .\" GNU General Public License for more details.
18 .\"
19 .\" You should have received a copy of the GNU General Public
20 .\" License along with this manual; if not, see
21 .\" <http://www.gnu.org/licenses/>.
22 .\" %%%LICENSE_END
23 .TH IOCTL_FICLONERANGE 2 2017-09-15 "Linux" "Linux Programmer's Manual"
24 .SH NAME
25 ioctl_ficlonerange, ioctl_ficlone \- share some the data of one file with another file
26 .SH SYNOPSIS
27 .nf
28 .B #include <sys/ioctl.h>
29 .B #include <linux/fs.h>
30 .PP
31 .BI "int ioctl(int " dest_fd ", FICLONERANGE, struct file_clone_range *" arg );
32 .BI "int ioctl(int " dest_fd ", FICLONE, int " src_fd );
33 .fi
34 .SH DESCRIPTION
35 If a filesystem supports files sharing physical storage between multiple
36 files ("reflink"), this
37 .BR ioctl (2)
38 operation can be used to make some of the data in the
39 .I src_fd
40 file appear in the
41 .I dest_fd
42 file by sharing the underlying storage, which is faster than making a separate
43 physical copy of the data.
44 Both files must reside within the same filesystem.
45 If a file write should occur to a shared region,
46 the filesystem must ensure that the changes remain private to the file being
47 written.
48 This behavior is commonly referred to as "copy on write".
49 .PP
50 This ioctl reflinks up to
51 .IR src_length
52 bytes from file descriptor
53 .IR src_fd
54 at offset
55 .IR src_offset
56 into the file
57 .IR dest_fd
58 at offset
59 .IR dest_offset ,
60 provided that both are files.
61 If
62 .IR src_length
63 is zero, the ioctl reflinks to the end of the source file.
64 This information is conveyed in a structure of
65 the following form:
66 .PP
67 .in +4n
68 .EX
69 struct file_clone_range {
70 __s64 src_fd;
71 __u64 src_offset;
72 __u64 src_length;
73 __u64 dest_offset;
74 };
75 .EE
76 .in
77 .PP
78 Clones are atomic with regards to concurrent writes, so no locks need to be
79 taken to obtain a consistent cloned copy.
80 .PP
81 The
82 .B FICLONE
83 ioctl clones entire files.
84 .SH RETURN VALUE
85 On error, \-1 is returned, and
86 .I errno
87 is set to indicate the error.
88 .SH ERRORS
89 Error codes can be one of, but are not limited to, the following:
90 .TP
91 .B EBADF
92 .IR src_fd
93 is not open for reading;
94 .IR dest_fd
95 is not open for writing or is open for append-only writes;
96 or the filesystem which
97 .IR src_fd
98 resides on does not support reflink.
99 .TP
100 .B EINVAL
101 The filesystem does not support reflinking the ranges of the given files.
102 This error can also appear if either file descriptor represents
103 a device, FIFO, or socket.
104 Disk filesystems generally require the offset and length arguments
105 to be aligned to the fundamental block size.
106 XFS and Btrfs do not support
107 overlapping reflink ranges in the same file.
108 .TP
109 .B EISDIR
110 One of the files is a directory and the filesystem does not support shared
111 regions in directories.
112 .TP
113 .B EOPNOTSUPP
114 This can appear if the filesystem does not support reflinking either file
115 descriptor, or if either file descriptor refers to special inodes.
116 .TP
117 .B EPERM
118 .IR dest_fd
119 is immutable.
120 .TP
121 .B ETXTBSY
122 One of the files is a swap file.
123 Swap files cannot share storage.
124 .TP
125 .B EXDEV
126 .IR dest_fd " and " src_fd
127 are not on the same mounted filesystem.
128 .SH VERSIONS
129 These ioctl operations first appeared in Linux 4.5.
130 They were previously known as
131 .B BTRFS_IOC_CLONE
132 and
133 .BR BTRFS_IOC_CLONE_RANGE ,
134 and were private to Btrfs.
135 .SH CONFORMING TO
136 This API is Linux-specific.
137 .SH NOTES
138 Because a copy-on-write operation requires the allocation of new storage, the
139 .BR fallocate (2)
140 operation may unshare shared blocks to guarantee that subsequent writes will
141 not fail because of lack of disk space.
142 .SH SEE ALSO
143 .BR ioctl (2)