1SPLICE(2)                  Linux Programmer's Manual                 SPLICE(2)
2
3
4

NAME

6       splice - splice data to/from a pipe
7

SYNOPSIS

9       #define _GNU_SOURCE         /* See feature_test_macros(7) */
10       #include <fcntl.h>
11
12       ssize_t splice(int fd_in, loff_t *off_in, int fd_out,
13                      loff_t *off_out, size_t len, unsigned int flags);
14

DESCRIPTION

16       splice()  moves  data  between  two  file  descriptors  without copying
17       between kernel address space and user address space.  It  transfers  up
18       to  len  bytes  of  data  from  the  file  descriptor fd_in to the file
19       descriptor fd_out, where one of the file descriptors must  refer  to  a
20       pipe.
21
22       The following semantics apply for fd_in and off_in:
23
24       *  If fd_in refers to a pipe, then off_in must be NULL.
25
26       *  If fd_in does not refer to a pipe and off_in is NULL, then bytes are
27          read from fd_in starting from the file offset, and the  file  offset
28          is adjusted appropriately.
29
30       *  If  fd_in  does  not  refer  to  a pipe and off_in is not NULL, then
31          off_in must point to a buffer which specifies  the  starting  offset
32          from  which  bytes  will  be read from fd_in; in this case, the file
33          offset of fd_in is not changed.
34
35       Analogous statements apply for fd_out and off_out.
36
37       The flags argument is a bit mask that is  composed  by  ORing  together
38       zero or more of the following values:
39
40       SPLICE_F_MOVE
41              Attempt  to  move pages instead of copying.  This is only a hint
42              to the kernel: pages may still be copied if  the  kernel  cannot
43              move the pages from the pipe, or if the pipe buffers don't refer
44              to full pages.  The initial  implementation  of  this  flag  was
45              buggy:  therefore starting in Linux 2.6.21 it is a no-op (but is
46              still permitted in a splice() call); in the  future,  a  correct
47              implementation may be restored.
48
49       SPLICE_F_NONBLOCK
50              Do not block on I/O.  This makes the splice pipe operations non‐
51              blocking, but splice() may nevertheless block because  the  file
52              descriptors that are spliced to/from may block (unless they have
53              the O_NONBLOCK flag set).
54
55       SPLICE_F_MORE
56              More data will be coming in a  subsequent  splice.   This  is  a
57              helpful  hint  when  the fd_out refers to a socket (see also the
58              description of MSG_MORE  in  send(2),  and  the  description  of
59              TCP_CORK in tcp(7)).
60
61       SPLICE_F_GIFT
62              Unused for splice(); see vmsplice(2).
63

RETURN VALUE

65       Upon  successful  completion,  splice()  returns  the  number  of bytes
66       spliced to or from the pipe.
67
68       A return value of 0 means end of input.  If fd_in  refers  to  a  pipe,
69       then  this  means  that there was no data to transfer, and it would not
70       make sense to block because there are no writers connected to the write
71       end of the pipe.
72
73       On error, splice() returns -1 and errno is set to indicate the error.
74

ERRORS

76       EAGAIN SPLICE_F_NONBLOCK  was  specified  in  flags,  and the operation
77              would block.
78
79       EBADF  One or both file descriptors are  not  valid,  or  do  not  have
80              proper read-write mode.
81
82       EINVAL The target filesystem doesn't support splicing.
83
84       EINVAL The target file is opened in append mode.
85
86       EINVAL Neither of the file descriptors refers to a pipe.
87
88       EINVAL An offset was given for nonseekable device (e.g., a pipe).
89
90       EINVAL fd_in and fd_out refer to the same pipe.
91
92       ENOMEM Out of memory.
93
94       ESPIPE Either  off_in  or  off_out  was not NULL, but the corresponding
95              file descriptor refers to a pipe.
96

VERSIONS

98       The splice() system call first appeared in Linux 2.6.17;  library  sup‐
99       port was added to glibc in version 2.5.
100

CONFORMING TO

102       This system call is Linux-specific.
103

NOTES

105       The three system calls splice(), vmsplice(2), and tee(2), provide user-
106       space programs with full  control  over  an  arbitrary  kernel  buffer,
107       implemented  within  the  kernel  using the same type of buffer that is
108       used for a pipe.  In overview, these system calls perform the following
109       tasks:
110
111       splice()    moves data from the buffer to an arbitrary file descriptor,
112                   or vice versa, or from one buffer to another.
113
114       tee(2)      "copies" the data from one buffer to another.
115
116       vmsplice(2) "copies" data from user space into the buffer.
117
118       Though we talk of copying, actual copies are  generally  avoided.   The
119       kernel  does  this by implementing a pipe buffer as a set of reference-
120       counted pointers  to  pages  of  kernel  memory.   The  kernel  creates
121       "copies"  of pages in a buffer by creating new pointers (for the output
122       buffer) referring to the pages, and increasing the reference counts for
123       the pages: only pointers are copied, not the pages of the buffer.
124
125       In  Linux  2.6.30  and  earlier,  exactly  one  of fd_in and fd_out was
126       required to be a pipe.  Since Linux 2.6.31, both arguments may refer to
127       pipes.
128

EXAMPLE

130       See tee(2).
131

SEE ALSO

133       copy_file_range(2), sendfile(2), tee(2), vmsplice(2), pipe(7)
134

COLOPHON

136       This  page  is  part of release 4.15 of the Linux man-pages project.  A
137       description of the project, information about reporting bugs,  and  the
138       latest     version     of     this    page,    can    be    found    at
139       https://www.kernel.org/doc/man-pages/.
140
141
142
143Linux                             2017-09-15                         SPLICE(2)
Impressum