Debian Codegraph @

upstream/debian-trixie/man2/FICLONE.2const

raw
1 .\" Copyright (c) 2016, Oracle. All rights reserved.
2 .\"
3 .\" SPDX-License-Identifier: GPL-2.0-or-later
4 .TH FICLONE 2const 2024-06-13 "Linux man-pages 6.9.1"
5 .SH NAME
6 FICLONE,
7 FICLONERANGE
8 \-
9 share some the data of one file with another file
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ", " \-lc )
13 .SH SYNOPSIS
14 .nf
15 .BR "#include <linux/fs.h>" " /* Definition of " FICLONE* " constants */"
16 .B #include <sys/ioctl.h>
17 .P
18 .BI "int ioctl(int " dest_fd ", FICLONERANGE, struct file_clone_range *" arg );
19 .BI "int ioctl(int " dest_fd ", FICLONE, int " src_fd );
20 .fi
21 .SH DESCRIPTION
22 If a filesystem supports files sharing physical storage between multiple
23 files ("reflink"), this
24 .BR ioctl (2)
25 operation can be used to make some of the data in the
26 .I src_fd
27 file appear in the
28 .I dest_fd
29 file by sharing the underlying storage, which is faster than making a separate
30 physical copy of the data.
31 Both files must reside within the same filesystem.
32 If a file write should occur to a shared region,
33 the filesystem must ensure that the changes remain private to the file being
34 written.
35 This behavior is commonly referred to as "copy on write".
36 .P
37 This ioctl reflinks up to
38 .I src_length
39 bytes from file descriptor
40 .I src_fd
41 at offset
42 .I src_offset
43 into the file
44 .I dest_fd
45 at offset
46 .IR dest_offset ,
47 provided that both are files.
48 If
49 .I src_length
50 is zero, the ioctl reflinks to the end of the source file.
51 This information is conveyed in a structure of
52 the following form:
53 .P
54 .in +4n
55 .EX
56 struct file_clone_range {
57 __s64 src_fd;
58 __u64 src_offset;
59 __u64 src_length;
60 __u64 dest_offset;
61 };
62 .EE
63 .in
64 .P
65 Clones are atomic with regards to concurrent writes, so no locks need to be
66 taken to obtain a consistent cloned copy.
67 .P
68 The
69 .B FICLONE
70 ioctl clones entire files.
71 .SH RETURN VALUE
72 On error, \-1 is returned, and
73 .I errno
74 is set to indicate the error.
75 .SH ERRORS
76 Error codes can be one of, but are not limited to, the following:
77 .TP
78 .B EBADF
79 .I src_fd
80 is not open for reading;
81 .I dest_fd
82 is not open for writing or is open for append-only writes;
83 or the filesystem which
84 .I src_fd
85 resides on does not support reflink.
86 .TP
87 .B EINVAL
88 The filesystem does not support reflinking the ranges of the given files.
89 This error can also appear if either file descriptor represents
90 a device, FIFO, or socket.
91 Disk filesystems generally require the offset and length arguments
92 to be aligned to the fundamental block size.
93 XFS and Btrfs do not support
94 overlapping reflink ranges in the same file.
95 .TP
96 .B EISDIR
97 One of the files is a directory and the filesystem does not support shared
98 regions in directories.
99 .TP
100 .B EOPNOTSUPP
101 This can appear if the filesystem does not support reflinking either file
102 descriptor, or if either file descriptor refers to special inodes.
103 .TP
104 .B EPERM
105 .I dest_fd
106 is immutable.
107 .TP
108 .B ETXTBSY
109 One of the files is a swap file.
110 Swap files cannot share storage.
111 .TP
112 .B EXDEV
113 .IR dest_fd " and " src_fd
114 are not on the same mounted filesystem.
115 .SH STANDARDS
116 Linux.
117 .SH HISTORY
118 Linux 4.5.
119 .P
120 They were previously known as
121 .B BTRFS_IOC_CLONE
122 and
123 .BR BTRFS_IOC_CLONE_RANGE ,
124 and were private to Btrfs.
125 .SH CAVEATS
126 Because a copy-on-write operation requires the allocation of new storage, the
127 .BR fallocate (2)
128 operation may unshare shared blocks to guarantee that subsequent writes will
129 not fail because of lack of disk space.
130 .SH SEE ALSO
131 .BR ioctl (2)