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) */"
15 .B #define _FILE_OFFSET_BITS 64
18 .BI "ssize_t splice(int " fd_in ", off_t *_Nullable " off_in ,
19 .BI " int " fd_out ", off_t *_Nullable " off_out ,
20 .BI " size_t " len ", unsigned int " flags );
21 .\" Return type was long before glibc 2.7
25 moves data between two file descriptors
26 without copying between kernel address space and user address space.
29 bytes of data from the file descriptor
31 to the file descriptor
33 where one of the file descriptors must refer to a pipe.
35 The following semantics apply for
42 refers to a pipe, then
48 does not refer to a pipe and
50 is NULL, then bytes are read from
52 starting from the file offset,
53 and the file offset is adjusted appropriately.
57 does not refer to a pipe and
61 must point to a buffer which specifies the starting
62 offset from which bytes will be read from
64 in this case, the file offset of
68 Analogous statements apply for
75 argument is a bit mask that is composed by ORing together
76 zero or more of the following values:
79 Attempt to move pages instead of copying.
80 This is only a hint to the kernel:
81 pages may still be copied if the kernel cannot move the
82 pages from the pipe, or if
83 the pipe buffers don't refer to full pages.
84 The initial implementation of this flag was buggy:
85 therefore starting in Linux 2.6.21 it is a no-op
86 (but is still permitted in a
89 in the future, a correct implementation may be restored.
93 This makes the splice pipe operations nonblocking, but
95 may nevertheless block because the file descriptors that
96 are spliced to/from may block (unless they have the
101 More data will be coming in a subsequent splice.
102 This is a helpful hint when
105 refers to a socket (see also the description of
109 and the description of
120 Upon successful completion,
122 returns the number of bytes
123 spliced to or from the pipe.
125 A return value of 0 means end of input.
128 refers to a pipe, then this means that there was no data to transfer,
129 and it would not make sense to block because there are no writers
130 connected to the write end of the pipe.
136 is set to indicate the error.
143 or one of the file descriptors had been marked as nonblocking
145 and the operation would block.
148 One or both file descriptors are not valid,
149 or do not have proper read-write mode.
152 The target filesystem doesn't support splicing.
155 The target file is opened in append mode.
156 .\" The append-mode error is given since Linux 2.6.27; in earlier kernels,
157 .\" splice() in append mode was broken
160 Neither of the file descriptors refers to a pipe.
163 An offset was given for nonseekable device (e.g., a pipe).
169 refer to the same pipe.
179 was not NULL, but the corresponding file descriptor refers to a pipe.
186 In Linux 2.6.30 and earlier,
191 was required to be a pipe.
193 .\" commit 7c77f0b3f9208c339a4b40737bb2cb0f0319bb8d
194 both arguments may refer to pipes.
196 The three system calls
201 provide user-space programs with full control over an arbitrary
202 kernel buffer, implemented within the kernel using the same type
203 of buffer that is used for a pipe.
204 In overview, these system calls perform the following tasks:
207 moves data from the buffer to an arbitrary file descriptor, or vice versa,
208 or from one buffer to another.
211 "copies" the data from one buffer to another.
214 "copies" data from user space into the buffer.
216 Though we talk of copying, actual copies are generally avoided.
217 The kernel does this by implementing a pipe buffer as a set
218 of reference-counted pointers to pages of kernel memory.
219 The kernel creates "copies" of pages in a buffer by creating new
220 pointers (for the output buffer) referring to the pages,
221 and increasing the reference counts for the pages:
222 only pointers are copied, not the pages of the buffer.
224 .\" Linus: Now, imagine using the above in a media server, for example.
225 .\" Let's say that a year or two has passed, so that the video drivers
226 .\" have been updated to be able to do the splice thing, and what can
229 .\" - splice from the (mpeg or whatever - let's just assume that the video
230 .\" input is either digital or does the encoding on its own - like they
231 .\" pretty much all do) video input into a pipe (remember: no copies - the
232 .\" video input will just DMA directly into memory, and splice will just
233 .\" set up the pages in the pipe buffer)
234 .\" - tee that pipe to split it up
235 .\" - splice one end to a file (ie "save the compressed stream to disk")
236 .\" - splice the other end to a real-time video decoder window for your
237 .\" real-time viewing pleasure.
239 .\" Linus: Now, the advantage of splice()/tee() is that you can
240 .\" do zero-copy movement of data, and unlike sendfile() you can
241 .\" do it on _arbitrary_ data (and, as shown by "tee()", it's more
242 .\" than just sending the data to somebody else: you can duplicate
243 .\" the data and choose to forward it to two or more different
244 .\" users - for things like logging etc.).
248 should be defined to be 64 in code that uses non-null
252 or that takes the address of
254 if the code is intended to be portable
255 to traditional 32-bit x86 and ARM platforms where
257 width defaults to 32 bits.
262 .BR copy_file_range (2),