1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" This manpage is Copyright (C) 2006 Jens Axboe
4 .\" and Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH SPLICE 2 2009-09-15 "Linux" "Linux Programmer's Manual"
28 splice \- splice data to/from a pipe
31 .B #define _GNU_SOURCE
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 descriptors must refer to a pipe.
53 refers to a pipe, then
58 does not refer to a pipe and
60 is NULL, then bytes are read from
62 starting from the current file offset,
63 and the current file offset is adjusted appropriately.
66 does not refer to a pipe and
70 must point to a buffer which specifies the starting
71 offset from which bytes will be read from
73 in this case, the current file offset of
76 Analogous statements apply for
83 argument is a bit mask that is composed by ORing together
84 zero or more of the following values:
87 Attempt to move pages instead of copying.
88 This is only a hint to the kernel:
89 pages may still be copied if the kernel cannot move the
90 pages from the pipe, or if
91 the pipe buffers don't refer to full pages.
92 The initial implementation of this flag was buggy:
93 therefore starting in Linux 2.6.21 it is a no-op
94 (but is still permitted in a
97 in the future, a correct implementation may be restored.
101 This makes the splice pipe operations nonblocking, but
103 may nevertheless block because the file descriptors that
104 are spliced to/from may block (unless they have the
109 More data will be coming in a subsequent splice.
110 This is a helpful hint when
113 refers to a socket (see also the description of
117 and the description of
128 Upon successful completion,
130 returns the number of bytes
131 spliced to or from the pipe.
132 A return value of 0 means that there was no data to transfer,
133 and it would not make sense to block, because there are no
134 writers connected to the write end of the pipe referred to by
141 is set to indicate the error.
145 One or both file descriptors are not valid,
146 or do not have proper read-write mode.
149 Target file system doesn't support splicing;
150 target file is opened in append mode;
151 .\" The append-mode error is given since 2.6.27; in earlier kernels,
152 .\" splice() in append mode was broken
153 neither of the descriptors refers to a pipe; or
154 offset given for non-seekable device.
164 was not NULL, but the corresponding file descriptor refers to a pipe.
168 system call first appeared in Linux 2.6.17.
170 This system call is Linux-specific.
172 The three system calls
177 provide userspace programs with full control over an arbitrary
178 kernel buffer, implemented within the kernel using the same type
179 of buffer that is used for a pipe.
180 In overview, these system calls perform the following tasks:
183 moves data from the buffer to an arbitrary file descriptor, or vice versa,
184 or from one buffer to another.
187 "copies" the data from one buffer to another.
190 "copies" data from user space into the buffer.
192 Though we talk of copying, actual copies are generally avoided.
193 The kernel does this by implementing a pipe buffer as a set
194 of reference-counted pointers to pages of kernel memory.
195 The kernel creates "copies" of pages in a buffer by creating new
196 pointers (for the output buffer) referring to the pages,
197 and increasing the reference counts for the pages:
198 only pointers are copied, not the pages of the buffer.
200 .\" Linus: Now, imagine using the above in a media server, for example.
201 .\" Let's say that a year or two has passed, so that the video drivers
202 .\" have been updated to be able to do the splice thing, and what can
205 .\" - splice from the (mpeg or whatever - let's just assume that the video
206 .\" input is either digital or does the encoding on its own - like they
207 .\" pretty much all do) video input into a pipe (remember: no copies - the
208 .\" video input will just DMA directly into memory, and splice will just
209 .\" set up the pages in the pipe buffer)
210 .\" - tee that pipe to split it up
211 .\" - splice one end to a file (ie "save the compressed stream to disk")
212 .\" - splice the other end to a real-time video decoder window for your
213 .\" real-time viewing pleasure.
215 .\" Linus: Now, the advantage of splice()/tee() is that you can
216 .\" do zero-copy movement of data, and unlike sendfile() you can
217 .\" do it on _arbitrary_ data (and, as shown by "tee()", it's more
218 .\" than just sending the data to somebody else: you can duplicate
219 .\" the data and choose to forward it to two or more different
220 .\" users - for things like logging etc.).
229 .BR feature_test_macros (7)