1 .\" This manpage is Copyright (C) 2006 Jens Axboe
2 .\" and Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH SPLICE 2 2017-09-15 "Linux" "Linux Programmer's Manual"
28 splice \- splice data to/from a pipe
31 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
34 .BI "ssize_t splice(int " fd_in ", loff_t *" off_in ", int " fd_out ,
35 .BI " loff_t *" off_out ", size_t " len \
36 ", unsigned int " flags );
37 .\" Return type was long before glibc 2.7
41 moves data between two file descriptors
42 without copying between kernel address space and user address space.
45 bytes of data from the file descriptor
47 to the file descriptor
49 where one of the file descriptors must refer to a pipe.
51 The following semantics apply for
58 refers to a pipe, then
64 does not refer to a pipe and
66 is NULL, then bytes are read from
68 starting from the file offset,
69 and the file offset is adjusted appropriately.
73 does not refer to a pipe and
77 must point to a buffer which specifies the starting
78 offset from which bytes will be read from
80 in this case, the file offset of
84 Analogous statements apply for
91 argument is a bit mask that is composed by ORing together
92 zero or more of the following values:
95 Attempt to move pages instead of copying.
96 This is only a hint to the kernel:
97 pages may still be copied if the kernel cannot move the
98 pages from the pipe, or if
99 the pipe buffers don't refer to full pages.
100 The initial implementation of this flag was buggy:
101 therefore starting in Linux 2.6.21 it is a no-op
102 (but is still permitted in a
105 in the future, a correct implementation may be restored.
109 This makes the splice pipe operations nonblocking, but
111 may nevertheless block because the file descriptors that
112 are spliced to/from may block (unless they have the
117 More data will be coming in a subsequent splice.
118 This is a helpful hint when
121 refers to a socket (see also the description of
125 and the description of
136 Upon successful completion,
138 returns the number of bytes
139 spliced to or from the pipe.
141 A return value of 0 means end of input.
144 refers to a pipe, then this means that there was no data to transfer,
145 and it would not make sense to block because there are no writers
146 connected to the write end of the pipe.
152 is set to indicate the error.
159 and the operation would block.
162 One or both file descriptors are not valid,
163 or do not have proper read-write mode.
166 The target filesystem doesn't support splicing.
169 The target file is opened in append mode.
170 .\" The append-mode error is given since 2.6.27; in earlier kernels,
171 .\" splice() in append mode was broken
174 Neither of the file descriptors refers to a pipe.
177 An offset was given for nonseekable device (e.g., a pipe).
183 refer to the same pipe.
193 was not NULL, but the corresponding file descriptor refers to a pipe.
197 system call first appeared in Linux 2.6.17;
198 library support was added to glibc in version 2.5.
200 This system call is Linux-specific.
202 The three system calls
207 provide user-space programs with full control over an arbitrary
208 kernel buffer, implemented within the kernel using the same type
209 of buffer that is used for a pipe.
210 In overview, these system calls perform the following tasks:
213 moves data from the buffer to an arbitrary file descriptor, or vice versa,
214 or from one buffer to another.
217 "copies" the data from one buffer to another.
220 "copies" data from user space into the buffer.
222 Though we talk of copying, actual copies are generally avoided.
223 The kernel does this by implementing a pipe buffer as a set
224 of reference-counted pointers to pages of kernel memory.
225 The kernel creates "copies" of pages in a buffer by creating new
226 pointers (for the output buffer) referring to the pages,
227 and increasing the reference counts for the pages:
228 only pointers are copied, not the pages of the buffer.
230 .\" Linus: Now, imagine using the above in a media server, for example.
231 .\" Let's say that a year or two has passed, so that the video drivers
232 .\" have been updated to be able to do the splice thing, and what can
235 .\" - splice from the (mpeg or whatever - let's just assume that the video
236 .\" input is either digital or does the encoding on its own - like they
237 .\" pretty much all do) video input into a pipe (remember: no copies - the
238 .\" video input will just DMA directly into memory, and splice will just
239 .\" set up the pages in the pipe buffer)
240 .\" - tee that pipe to split it up
241 .\" - splice one end to a file (ie "save the compressed stream to disk")
242 .\" - splice the other end to a real-time video decoder window for your
243 .\" real-time viewing pleasure.
245 .\" Linus: Now, the advantage of splice()/tee() is that you can
246 .\" do zero-copy movement of data, and unlike sendfile() you can
247 .\" do it on _arbitrary_ data (and, as shown by "tee()", it's more
248 .\" than just sending the data to somebody else: you can duplicate
249 .\" the data and choose to forward it to two or more different
250 .\" users - for things like logging etc.).
253 In Linux 2.6.30 and earlier,
258 was required to be a pipe.
260 .\" commit 7c77f0b3f9208c339a4b40737bb2cb0f0319bb8d
261 both arguments may refer to pipes.
266 .BR copy_file_range (2),