1 .\" This manpage is Copyright (C) 2006 Jens Axboe
2 .\" and Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH splice 2 (date) "Linux man-pages (unreleased)"
8 splice \- splice data to/from a pipe
11 .RI ( libc ", " \-lc )
14 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
17 .BI "ssize_t splice(int " fd_in ", off64_t *_Nullable " off_in ,
18 .BI " int " fd_out ", off64_t *_Nullable " off_out ,
19 .BI " size_t " len ", unsigned int " flags );
20 .\" Return type was long before glibc 2.7
24 moves data between two file descriptors
25 without copying between kernel address space and user address space.
28 bytes of data from the file descriptor
30 to the file descriptor
32 where one of the file descriptors must refer to a pipe.
34 The following semantics apply for
41 refers to a pipe, then
47 does not refer to a pipe and
49 is NULL, then bytes are read from
51 starting from the file offset,
52 and the file offset is adjusted appropriately.
56 does not refer to a pipe and
60 must point to a buffer which specifies the starting
61 offset from which bytes will be read from
63 in this case, the file offset of
67 Analogous statements apply for
74 argument is a bit mask that is composed by ORing together
75 zero or more of the following values:
78 Attempt to move pages instead of copying.
79 This is only a hint to the kernel:
80 pages may still be copied if the kernel cannot move the
81 pages from the pipe, or if
82 the pipe buffers don't refer to full pages.
83 The initial implementation of this flag was buggy:
84 therefore starting in Linux 2.6.21 it is a no-op
85 (but is still permitted in a
88 in the future, a correct implementation may be restored.
92 This makes the splice pipe operations nonblocking, but
94 may nevertheless block because the file descriptors that
95 are spliced to/from may block (unless they have the
100 More data will be coming in a subsequent splice.
101 This is a helpful hint when
104 refers to a socket (see also the description of
108 and the description of
119 Upon successful completion,
121 returns the number of bytes
122 spliced to or from the pipe.
124 A return value of 0 means end of input.
127 refers to a pipe, then this means that there was no data to transfer,
128 and it would not make sense to block because there are no writers
129 connected to the write end of the pipe.
135 is set to indicate the error.
142 or one of the file descriptors had been marked as nonblocking
144 and the operation would block.
147 One or both file descriptors are not valid,
148 or do not have proper read-write mode.
151 The target filesystem doesn't support splicing.
154 The target file is opened in append mode.
155 .\" The append-mode error is given since Linux 2.6.27; in earlier kernels,
156 .\" splice() in append mode was broken
159 Neither of the file descriptors refers to a pipe.
162 An offset was given for nonseekable device (e.g., a pipe).
168 refer to the same pipe.
178 was not NULL, but the corresponding file descriptor refers to a pipe.
182 system call first appeared in Linux 2.6.17;
183 library support was added in glibc 2.5.
185 This system call is Linux-specific.
187 The three system calls
192 provide user-space programs with full control over an arbitrary
193 kernel buffer, implemented within the kernel using the same type
194 of buffer that is used for a pipe.
195 In overview, these system calls perform the following tasks:
198 moves data from the buffer to an arbitrary file descriptor, or vice versa,
199 or from one buffer to another.
202 "copies" the data from one buffer to another.
205 "copies" data from user space into the buffer.
207 Though we talk of copying, actual copies are generally avoided.
208 The kernel does this by implementing a pipe buffer as a set
209 of reference-counted pointers to pages of kernel memory.
210 The kernel creates "copies" of pages in a buffer by creating new
211 pointers (for the output buffer) referring to the pages,
212 and increasing the reference counts for the pages:
213 only pointers are copied, not the pages of the buffer.
215 .\" Linus: Now, imagine using the above in a media server, for example.
216 .\" Let's say that a year or two has passed, so that the video drivers
217 .\" have been updated to be able to do the splice thing, and what can
220 .\" - splice from the (mpeg or whatever - let's just assume that the video
221 .\" input is either digital or does the encoding on its own - like they
222 .\" pretty much all do) video input into a pipe (remember: no copies - the
223 .\" video input will just DMA directly into memory, and splice will just
224 .\" set up the pages in the pipe buffer)
225 .\" - tee that pipe to split it up
226 .\" - splice one end to a file (ie "save the compressed stream to disk")
227 .\" - splice the other end to a real-time video decoder window for your
228 .\" real-time viewing pleasure.
230 .\" Linus: Now, the advantage of splice()/tee() is that you can
231 .\" do zero-copy movement of data, and unlike sendfile() you can
232 .\" do it on _arbitrary_ data (and, as shown by "tee()", it's more
233 .\" than just sending the data to somebody else: you can duplicate
234 .\" the data and choose to forward it to two or more different
235 .\" users - for things like logging etc.).
238 In Linux 2.6.30 and earlier,
243 was required to be a pipe.
245 .\" commit 7c77f0b3f9208c339a4b40737bb2cb0f0319bb8d
246 both arguments may refer to pipes.
251 .BR copy_file_range (2),