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 .\"O .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
40 .BR "#define _GNU_SOURCE" " /* feature_test_macros(7) 参照 */"
43 .BI "ssize_t splice(int " fd_in ", loff_t *" off_in ", int " fd_out ,
44 .BI " loff_t *" off_out ", size_t " len \
45 ", unsigned int " flags );
47 .\" Return type was long before glibc 2.7
51 .\"O moves data between two file descriptors
52 .\"O without copying between kernel address space and user address space.
53 .\"O It transfers up to
55 .\"O bytes of data from the file descriptor
57 .\"O to the file descriptor
59 .\"O where one of the descriptors must refer to a pipe.
61 は、カーネルアドレス空間とユーザアドレス空間との間のコピーを伴わずに、
62 2 つのファイルディスクリプタ間でデータの移動を行う。
75 .\"O refers to a pipe, then
84 .\"O does not refer to a pipe and
86 .\"O is NULL, then bytes are read from
88 .\"O starting from the current file offset,
89 .\"O and the current file offset is adjusted appropriately.
95 の現在のファイルオフセットから始まるバイトを読み出す。
96 現在のファイルオフセットは適切に調整される。
99 .\"O does not refer to a pipe and
101 .\"O is not NULL, then
103 .\"O must point to a buffer which specifies the starting
104 .\"O offset from which bytes will be read from
106 .\"O in this case, the current file offset of
116 からのデータ読み出しを開始する先頭オフセットを格納したバッファ
117 へのポインタでなければならない。この場合、
119 の現在のファイルオフセットは変更されない。
120 .\"O Analogous statements apply for
131 .\"O argument is a bit mask that is composed by ORing together
132 .\"O zero or more of the following values:
134 引き数には、以下の値の 0 個以上のビット単位の論理和を
138 .\"O Attempt to move pages instead of copying.
139 .\"O This is only a hint to the kernel:
140 .\"O pages may still be copied if the kernel cannot move the
141 .\"O pages from the pipe, or if
142 .\"O the pipe buffers don't refer to full pages.
145 つまり、カーネルがパイプからページを移動できない場合や、
146 パイプバッファがページ全部を参照していない場合は、
148 .\"O The initial implementation of this flag was buggy:
149 .\"O therefore starting in Linux 2.6.21 it is a no-op
150 .\"O (but is still permitted in a
153 .\"O in the future, a correct implementation may be restored.
154 このフラグの最初の実装にはバグがあった。そのため、
155 Linux 2.6.21 以降ではこのフラグの操作はできないようになっている
158 コールでこのフラグを指定することは今も認められている)。
162 .\"O Do not block on I/O.
163 .\"O This makes the splice pipe operations nonblocking, but
165 .\"O may nevertheless block because the file descriptors that
166 .\"O are spliced to/from may block (unless they have the
171 splice によるパイプ操作を非停止モード (nonblocking) で
174 は停止することもある。なぜなら、データのやり取りを行う
177 フラグをセットされていない場合) 停止する可能性があるからである。
180 .\"O More data will be coming in a subsequent splice.
181 .\"O This is a helpful hint when
184 .\"O refers to a socket (see also the description of
188 .\"O and the description of
192 この後の splice でさらに転送されるデータがあることを示す。
195 がソケットを参照している場合に有用なヒントとなる
209 .\"O .BR vmsplice (2).
214 .\"O .SH RETURN VALUE
216 .\"O Upon successful completion,
218 .\"O returns the number of bytes
219 .\"O spliced to or from the pipe.
220 .\"O A return value of 0 means that there was no data to transfer,
221 .\"O and it would not make sense to block, because there are no
222 .\"O writers connected to the write end of the pipe referred to by
227 返り値 0 はデータの転送が行わなかったことを示す。
228 この場合、処理を停止 (block) しても無意味である。
231 が参照するパイプの書き込み側に接続されている者がいないからである。
237 .\"O is set to indicate the error.
247 .\"O One or both file descriptors are not valid,
248 .\"O or do not have proper read-write mode.
249 ファイルディスクリプタの一方または両方が有効ではない、
250 もしくは適切な read-write モードではない。
253 .\"O Target file system doesn't support splicing;
254 .\"O target file is opened in append mode;
255 .\"O .\" The append-mode error is given since 2.6.27; in earlier kernels,
256 .\"O .\" splice() in append mode was broken
257 .\"O neither of the descriptors refers to a pipe; or
258 .\"O offset given for nonseekable device.
259 対象のファイルシステムが splice に対応していない、
260 または対象のファイルが追記モードでオープンされている、
261 .\" 追記モードでのエラーは 2.6.27 以降で発生する。
262 .\" それより前のカーネルでは追記モードでの splice() は正しく動作しない。
263 またはディスクリプタのどちらもパイプを参照していない、
264 または seek できないデバイスに対してオフセットが指定された。
275 .\"O was not NULL, but the corresponding file descriptor refers to a pipe.
279 のいずれかが NULL ではないが、対応するファイルディスクリプタが
285 .\"O system call first appeared in Linux 2.6.17.
287 システムコールは Linux 2.6.17 で初めて登場した。
288 .\"O .SH "CONFORMING TO"
290 .\"O This system call is Linux-specific.
291 このシステムコールは Linux 固有である。
294 .\"O The three system calls
296 .\"O .BR vmsplice (2),
299 .\"O provide userspace programs with full control over an arbitrary
300 .\"O kernel buffer, implemented within the kernel using the same type
301 .\"O of buffer that is used for a pipe.
306 を使うと、ユーザ空間プログラムは任意のカーネルバッファに対する
307 完全な制御ができる。カーネルバッファは、パイプに使用されているのと
308 同種のバッファを使ってカーネル内に実装されている。
309 .\"O In overview, these system calls perform the following tasks:
310 大まかにいうと、これらのシステムコールは以下の仕事を行う:
313 .\"O moves data from the buffer to an arbitrary file descriptor, or vice versa,
314 .\"O or from one buffer to another.
315 バッファから任意のファイルディスクリプタや、その逆方向、
316 もしくはあるバッファから別のバッファへの、データ移動を行う。
319 .\"O "copies" the data from one buffer to another.
320 あるバッファから別のバッファへのデータ「コピー」を行う。
323 .\"O "copies" data from user space into the buffer.
324 ユーザ空間からバッファへのデータ「コピー」を行う。
326 .\"O Though we talk of copying, actual copies are generally avoided.
327 .\"O The kernel does this by implementing a pipe buffer as a set
328 .\"O of reference-counted pointers to pages of kernel memory.
329 .\"O The kernel creates "copies" of pages in a buffer by creating new
330 .\"O pointers (for the output buffer) referring to the pages,
331 .\"O and increasing the reference counts for the pages:
332 .\"O only pointers are copied, not the pages of the buffer.
333 ここではコピーの話をしているが、実際のコピーは一般的に回避される。
334 カーネルは、パイプ・バッファをカーネルメモリのページへのポインタ集合として
335 実装し、ページへの参照回数を管理することで、これを実現している。
336 カーネルは、対象となるページを参照する (出力バッファ用の) ポインタを
337 新規に作成することでバッファ内のページの「コピー」を作成し、
338 そのページの参照回数を増やす。つまり、ポインタだけがコピーされ、
341 .\" Linus: Now, imagine using the above in a media server, for example.
342 .\" Let's say that a year or two has passed, so that the video drivers
343 .\" have been updated to be able to do the splice thing, and what can
346 .\" - splice from the (mpeg or whatever - let's just assume that the video
347 .\" input is either digital or does the encoding on its own - like they
348 .\" pretty much all do) video input into a pipe (remember: no copies - the
349 .\" video input will just DMA directly into memory, and splice will just
350 .\" set up the pages in the pipe buffer)
351 .\" - tee that pipe to split it up
352 .\" - splice one end to a file (ie "save the compressed stream to disk")
353 .\" - splice the other end to a real-time video decoder window for your
354 .\" real-time viewing pleasure.
356 .\" Linus: Now, the advantage of splice()/tee() is that you can
357 .\" do zero-copy movement of data, and unlike sendfile() you can
358 .\" do it on _arbitrary_ data (and, as shown by "tee()", it's more
359 .\" than just sending the data to somebody else: you can duplicate
360 .\" the data and choose to forward it to two or more different
361 .\" users - for things like logging etc.).