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 .\" Japanese Version Copyright (c) 2007 Akihiro MOTOKI
27 .\" all rights reserved.
28 .\" Translated 2007-02-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
29 .\" Updated 2008-11-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.13
31 .TH SPLICE 2 2009-09-15 "Linux" "Linux Programmer's Manual"
34 .\"O splice \- splice data to/from a pipe
35 splice \- ¥Ñ¥¤¥×¤È¤Î´Ö¤Ç¥Ç¡¼¥¿¤ò·Ñ¤®¹ç¤ï¤»¤ë
39 .B #define _GNU_SOURCE
42 .BI "ssize_t splice(int " fd_in ", loff_t *" off_in ", int " fd_out ,
43 .BI " loff_t *" off_out ", size_t " len \
44 ", unsigned int " flags );
46 .\" Return type was long before glibc 2.7
50 .\"O moves data between two file descriptors
51 .\"O without copying between kernel address space and user address space.
52 .\"O It transfers up to
54 .\"O bytes of data from the file descriptor
56 .\"O to the file descriptor
58 .\"O where one of the descriptors must refer to a pipe.
60 ¤Ï¡¢¥«¡¼¥Í¥ë¥¢¥É¥ì¥¹¶õ´Ö¤È¥æ¡¼¥¶¥¢¥É¥ì¥¹¶õ´Ö¤È¤Î´Ö¤Î¥³¥Ô¡¼¤òȼ¤ï¤º¤Ë¡¢
61 2 ¤Ä¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿´Ö¤Ç¥Ç¡¼¥¿¤Î°ÜÆ°¤ò¹Ô¤¦¡£
62 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
64 ¤«¤é¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿
69 2 ¤Ä¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¤¦¤Á°ì¤Ä¤Ï
70 ¥Ñ¥¤¥×¤ò»²¾È¤·¤Æ¤¤¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
74 .\"O refers to a pipe, then
78 ¤¬¥Ñ¥¤¥×¤ò»²¾È¤·¤Æ¤¤¤ë¾ì¹ç¡¢
80 ¤Ï NULL ¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
83 .\"O does not refer to a pipe and
85 .\"O is NULL, then bytes are read from
87 .\"O starting from the current file offset,
88 .\"O and the current file offset is adjusted appropriately.
90 ¤¬¥Ñ¥¤¥×¤ò»²¾È¤·¤Æ¤ª¤é¤º¡¢
94 ¤Î¸½ºß¤Î¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤«¤é»Ï¤Þ¤ë¥Ð¥¤¥È¤òÆɤ߽Ф¹¡£
95 ¸½ºß¤Î¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤ÏŬÀÚ¤ËÄ´À°¤µ¤ì¤ë¡£
98 .\"O does not refer to a pipe and
100 .\"O is not NULL, then
102 .\"O must point to a buffer which specifies the starting
103 .\"O offset from which bytes will be read from
105 .\"O in this case, the current file offset of
109 ¤¬¥Ñ¥¤¥×¤ò»²¾È¤·¤Æ¤ª¤é¤º¡¢
115 ¤«¤é¤Î¥Ç¡¼¥¿Æɤ߽Ф·¤ò³«»Ï¤¹¤ëÀèƬ¥ª¥Õ¥»¥Ã¥È¤ò³ÊǼ¤·¤¿¥Ð¥Ã¥Õ¥¡
116 ¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£¤³¤Î¾ì¹ç¡¢
118 ¤Î¸½ºß¤Î¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¡£
119 .\"O Analogous statements apply for
126 ¤Ë´Ø¤·¤Æ¤âƱÍͤǤ¢¤ë¡£
130 .\"O argument is a bit mask that is composed by ORing together
131 .\"O zero or more of the following values:
133 °ú¤¿ô¤Ë¤Ï¡¢°Ê²¼¤ÎÃͤΠ0 ¸Ä°Ê¾å¤Î¥Ó¥Ã¥Èñ°Ì¤ÎÏÀÍýϤò
134 ¤È¤Ã¤¿¤â¤Î¤ò»ØÄꤹ¤ë:
137 .\"O Attempt to move pages instead of copying.
138 .\"O This is only a hint to the kernel:
139 .\"O pages may still be copied if the kernel cannot move the
140 .\"O pages from the pipe, or if
141 .\"O the pipe buffers don't refer to full pages.
142 ¥Ú¡¼¥¸¤Î¥³¥Ô¡¼¤Ç¤Ê¤¯°ÜÆ°¤ò»î¤ß¤ë¡£
143 ¤³¤ì¤Ï¥«¡¼¥Í¥ë¤ËÂФ¹¤ë¥Ò¥ó¥È¤Ç¤·¤«¤Ê¤¤¡£
144 ¤Ä¤Þ¤ê¡¢¥«¡¼¥Í¥ë¤¬¥Ñ¥¤¥×¤«¤é¥Ú¡¼¥¸¤ò°ÜÆ°¤Ç¤¤Ê¤¤¾ì¹ç¤ä¡¢
145 ¥Ñ¥¤¥×¥Ð¥Ã¥Õ¥¡¤¬¥Ú¡¼¥¸Á´Éô¤ò»²¾È¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ï¡¢
146 ¥Ú¡¼¥¸¤Î¥³¥Ô¡¼¤¬¹Ô¤ï¤ì¤ë¤³¤È¤â¤¢¤ë¡£
147 .\"O The initial implementation of this flag was buggy:
148 .\"O therefore starting in Linux 2.6.21 it is a no-op
149 .\"O (but is still permitted in a
152 .\"O in the future, a correct implementation may be restored.
153 ¤³¤Î¥Õ¥é¥°¤ÎºÇ½é¤Î¼ÂÁõ¤Ë¤Ï¥Ð¥°¤¬¤¢¤Ã¤¿¡£¤½¤Î¤¿¤á¡¢
154 Linux 2.6.21 °Ê¹ß¤Ç¤Ï¤³¤Î¥Õ¥é¥°¤ÎÁàºî¤Ï¤Ç¤¤Ê¤¤¤è¤¦¤Ë¤Ê¤Ã¤Æ¤¤¤ë
157 ¥³¡¼¥ë¤Ç¤³¤Î¥Õ¥é¥°¤ò»ØÄꤹ¤ë¤³¤È¤Ïº£¤âǧ¤á¤é¤ì¤Æ¤¤¤ë)¡£
158 ¾Íè¡¢Àµ¤·¤¤¼ÂÁõ¤¬¹Ô¤ï¤ì¤ë¤³¤È¤À¤í¤¦¡£
161 .\"O Do not block on I/O.
162 .\"O This makes the splice pipe operations nonblocking, but
164 .\"O may nevertheless block because the file descriptors that
165 .\"O are spliced to/from may block (unless they have the
168 Æþ½ÐÎÏ»þ¤ËÄä»ß (block) ¤·¤Ê¤¤¡£
169 ¤³¤Î¥Õ¥é¥°¤ò»ØÄꤹ¤ë¤È¡¢
170 splice ¤Ë¤è¤ë¥Ñ¥¤¥×Áàºî¤òÈóÄä»ß¥â¡¼¥É (nonblocking) ¤Ç
171 ¹Ô¤ª¤¦¤È¤¹¤ë¤¬¡¢¤½¤Î¾ì¹ç¤Ç¤â
173 ¤ÏÄä»ß¤¹¤ë¤³¤È¤â¤¢¤ë¡£¤Ê¤¼¤Ê¤é¡¢¥Ç¡¼¥¿¤Î¤ä¤ê¼è¤ê¤ò¹Ô¤¦
174 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï
176 ¥Õ¥é¥°¤ò¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç) Ää»ß¤¹¤ë²ÄǽÀ¤¬¤¢¤ë¤«¤é¤Ç¤¢¤ë¡£
179 .\"O More data will be coming in a subsequent splice.
180 .\"O This is a helpful hint when
183 .\"O refers to a socket (see also the description of
187 .\"O and the description of
191 ¤³¤Î¸å¤Î splice ¤Ç¤µ¤é¤ËžÁ÷¤µ¤ì¤ë¥Ç¡¼¥¿¤¬¤¢¤ë¤³¤È¤ò¼¨¤¹¡£
194 ¤¬¥½¥±¥Ã¥È¤ò»²¾È¤·¤Æ¤¤¤ë¾ì¹ç¤ËÍÍѤʥҥó¥È¤È¤Ê¤ë
208 .\"O .BR vmsplice (2).
213 .\"O .SH RETURN VALUE
215 .\"O Upon successful completion,
217 .\"O returns the number of bytes
218 .\"O spliced to or from the pipe.
219 .\"O A return value of 0 means that there was no data to transfer,
220 .\"O and it would not make sense to block, because there are no
221 .\"O writers connected to the write end of the pipe referred to by
225 ¤Ï¥Ñ¥¤¥×¤«¤é½Ð¤·Æþ¤ì¤·¤¿¥Ð¥¤¥È¿ô¤òÊÖ¤¹¡£
226 ÊÖ¤êÃÍ 0 ¤Ï¥Ç¡¼¥¿¤ÎžÁ÷¤¬¹Ô¤ï¤Ê¤«¤Ã¤¿¤³¤È¤ò¼¨¤¹¡£
227 ¤³¤Î¾ì¹ç¡¢½èÍý¤òÄä»ß (block) ¤·¤Æ¤â̵°ÕÌ£¤Ç¤¢¤ë¡£
230 ¤¬»²¾È¤¹¤ë¥Ñ¥¤¥×¤Î½ñ¤¹þ¤ß¦¤ËÀܳ¤µ¤ì¤Æ¤¤¤ë¼Ô¤¬¤¤¤Ê¤¤¤«¤é¤Ç¤¢¤ë¡£
236 .\"O is set to indicate the error.
241 ¤Ë¥¨¥é¡¼¤ò¼¨¤¹ÃͤòÀßÄꤹ¤ë¡£
246 .\"O One or both file descriptors are not valid,
247 .\"O or do not have proper read-write mode.
248 ¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î°ìÊý¤Þ¤¿¤ÏξÊý¤¬Í¸ú¤Ç¤Ï¤Ê¤¤¡¢
249 ¤â¤·¤¯¤ÏŬÀÚ¤Ê read-write ¥â¡¼¥É¤Ç¤Ï¤Ê¤¤¡£
252 .\"O Target file system doesn't support splicing;
253 .\"O target file is opened in append mode;
254 .\"O .\" The append-mode error is given since 2.6.27; in earlier kernels,
255 .\"O .\" splice() in append mode was broken
256 .\"O neither of the descriptors refers to a pipe; or
257 .\"O offset given for nonseekable device.
258 ÂоݤΥե¡¥¤¥ë¥·¥¹¥Æ¥à¤¬ splice ¤ËÂбþ¤·¤Æ¤¤¤Ê¤¤¡¢
259 ¤Þ¤¿¤ÏÂоݤΥե¡¥¤¥ë¤¬Äɵ¥â¡¼¥É¤Ç¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¡¢
260 .\" Äɵ¥â¡¼¥É¤Ç¤Î¥¨¥é¡¼¤Ï 2.6.27 °Ê¹ß¤ÇȯÀ¸¤¹¤ë¡£
261 .\" ¤½¤ì¤è¤êÁ°¤Î¥«¡¼¥Í¥ë¤Ç¤ÏÄɵ¥â¡¼¥É¤Ç¤Î splice() ¤ÏÀµ¤·¤¯Æ°ºî¤·¤Ê¤¤¡£
262 ¤Þ¤¿¤Ï¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Î¤É¤Á¤é¤â¥Ñ¥¤¥×¤ò»²¾È¤·¤Æ¤¤¤Ê¤¤¡¢
263 ¤Þ¤¿¤Ï seek ¤Ç¤¤Ê¤¤¥Ç¥Ð¥¤¥¹¤ËÂФ·¤Æ¥ª¥Õ¥»¥Ã¥È¤¬»ØÄꤵ¤ì¤¿¡£
274 .\"O was not NULL, but the corresponding file descriptor refers to a pipe.
278 ¤Î¤¤¤º¤ì¤«¤¬ NULL ¤Ç¤Ï¤Ê¤¤¤¬¡¢Âбþ¤¹¤ë¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬
279 ¥Ñ¥¤¥×¤ò»²¾È¤·¤Æ¤¤¤ë¡£
284 .\"O system call first appeared in Linux 2.6.17.
286 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï Linux 2.6.17 ¤Ç½é¤á¤ÆÅо줷¤¿¡£
287 .\"O .SH "CONFORMING TO"
289 .\"O This system call is Linux-specific.
290 ¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï Linux ¸ÇͤǤ¢¤ë¡£
293 .\"O The three system calls
295 .\"O .BR vmsplice (2),
298 .\"O provide userspace programs with full control over an arbitrary
299 .\"O kernel buffer, implemented within the kernel using the same type
300 .\"O of buffer that is used for a pipe.
305 ¤ò»È¤¦¤È¡¢¥æ¡¼¥¶¶õ´Ö¥×¥í¥°¥é¥à¤ÏǤ°Õ¤Î¥«¡¼¥Í¥ë¥Ð¥Ã¥Õ¥¡¤ËÂФ¹¤ë
306 ´°Á´¤ÊÀ©¸æ¤¬¤Ç¤¤ë¡£¥«¡¼¥Í¥ë¥Ð¥Ã¥Õ¥¡¤Ï¡¢¥Ñ¥¤¥×¤Ë»ÈÍѤµ¤ì¤Æ¤¤¤ë¤Î¤È
307 Ʊ¼ï¤Î¥Ð¥Ã¥Õ¥¡¤ò»È¤Ã¤Æ¥«¡¼¥Í¥ëÆâ¤Ë¼ÂÁõ¤µ¤ì¤Æ¤¤¤ë¡£
308 .\"O In overview, these system calls perform the following tasks:
309 Âç¤Þ¤«¤Ë¤¤¤¦¤È¡¢¤³¤ì¤é¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï°Ê²¼¤Î»Å»ö¤ò¹Ô¤¦:
312 .\"O moves data from the buffer to an arbitrary file descriptor, or vice versa,
313 .\"O or from one buffer to another.
314 ¥Ð¥Ã¥Õ¥¡¤«¤éǤ°Õ¤Î¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤ä¡¢¤½¤ÎµÕÊý¸þ¡¢
315 ¤â¤·¤¯¤Ï¤¢¤ë¥Ð¥Ã¥Õ¥¡¤«¤éÊ̤ΥХåե¡¤Ø¤Î¡¢¥Ç¡¼¥¿°ÜÆ°¤ò¹Ô¤¦¡£
318 .\"O "copies" the data from one buffer to another.
319 ¤¢¤ë¥Ð¥Ã¥Õ¥¡¤«¤éÊ̤ΥХåե¡¤Ø¤Î¥Ç¡¼¥¿¡Ö¥³¥Ô¡¼¡×¤ò¹Ô¤¦¡£
322 .\"O "copies" data from user space into the buffer.
323 ¥æ¡¼¥¶¶õ´Ö¤«¤é¥Ð¥Ã¥Õ¥¡¤Ø¤Î¥Ç¡¼¥¿¡Ö¥³¥Ô¡¼¡×¤ò¹Ô¤¦¡£
325 .\"O Though we talk of copying, actual copies are generally avoided.
326 .\"O The kernel does this by implementing a pipe buffer as a set
327 .\"O of reference-counted pointers to pages of kernel memory.
328 .\"O The kernel creates "copies" of pages in a buffer by creating new
329 .\"O pointers (for the output buffer) referring to the pages,
330 .\"O and increasing the reference counts for the pages:
331 .\"O only pointers are copied, not the pages of the buffer.
332 ¤³¤³¤Ç¤Ï¥³¥Ô¡¼¤ÎÏäò¤·¤Æ¤¤¤ë¤¬¡¢¼ÂºÝ¤Î¥³¥Ô¡¼¤Ï°ìÈÌŪ¤Ë²óÈò¤µ¤ì¤ë¡£
333 ¥«¡¼¥Í¥ë¤Ï¡¢¥Ñ¥¤¥×¡¦¥Ð¥Ã¥Õ¥¡¤ò¥«¡¼¥Í¥ë¥á¥â¥ê¤Î¥Ú¡¼¥¸¤Ø¤Î¥Ý¥¤¥ó¥¿½¸¹ç¤È¤·¤Æ
334 ¼ÂÁõ¤·¡¢¥Ú¡¼¥¸¤Ø¤Î»²¾È²ó¿ô¤ò´ÉÍý¤¹¤ë¤³¤È¤Ç¡¢¤³¤ì¤ò¼Â¸½¤·¤Æ¤¤¤ë¡£
335 ¥«¡¼¥Í¥ë¤Ï¡¢ÂоݤȤʤë¥Ú¡¼¥¸¤ò»²¾È¤¹¤ë (½ÐÎϥХåե¡ÍѤÎ) ¥Ý¥¤¥ó¥¿¤ò
336 ¿·µ¬¤ËºîÀ®¤¹¤ë¤³¤È¤Ç¥Ð¥Ã¥Õ¥¡Æâ¤Î¥Ú¡¼¥¸¤Î¡Ö¥³¥Ô¡¼¡×¤òºîÀ®¤·¡¢
337 ¤½¤Î¥Ú¡¼¥¸¤Î»²¾È²ó¿ô¤òÁý¤ä¤¹¡£¤Ä¤Þ¤ê¡¢¥Ý¥¤¥ó¥¿¤À¤±¤¬¥³¥Ô¡¼¤µ¤ì¡¢
338 ¥Ð¥Ã¥Õ¥¡¤Î¥Ú¡¼¥¸¤Ï¥³¥Ô¡¼¤µ¤ì¤Ê¤¤¡£
340 .\" Linus: Now, imagine using the above in a media server, for example.
341 .\" Let's say that a year or two has passed, so that the video drivers
342 .\" have been updated to be able to do the splice thing, and what can
345 .\" - splice from the (mpeg or whatever - let's just assume that the video
346 .\" input is either digital or does the encoding on its own - like they
347 .\" pretty much all do) video input into a pipe (remember: no copies - the
348 .\" video input will just DMA directly into memory, and splice will just
349 .\" set up the pages in the pipe buffer)
350 .\" - tee that pipe to split it up
351 .\" - splice one end to a file (ie "save the compressed stream to disk")
352 .\" - splice the other end to a real-time video decoder window for your
353 .\" real-time viewing pleasure.
355 .\" Linus: Now, the advantage of splice()/tee() is that you can
356 .\" do zero-copy movement of data, and unlike sendfile() you can
357 .\" do it on _arbitrary_ data (and, as shown by "tee()", it's more
358 .\" than just sending the data to somebody else: you can duplicate
359 .\" the data and choose to forward it to two or more different
360 .\" users - for things like logging etc.).
373 .BR feature_test_macros (7)