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"
33 splice \- パイプとの間でデータを継ぎ合わせる
36 .BR "#define _GNU_SOURCE" " /* feature_test_macros(7) 参照 */"
39 .BI "ssize_t splice(int " fd_in ", loff_t *" off_in ", int " fd_out ,
40 .BI " loff_t *" off_out ", size_t " len \
41 ", unsigned int " flags );
43 .\" Return type was long before glibc 2.7
46 は、カーネルアドレス空間とユーザアドレス空間との間のコピーを伴わずに、
47 2 つのファイルディスクリプタ間でデータの移動を行う。
67 の現在のファイルオフセットから始まるバイトを読み出す。
68 現在のファイルオフセットは適切に調整される。
76 からのデータ読み出しを開始する先頭オフセットを格納したバッファ
86 引き数には、以下の値の 0 個以上のビット単位の論理和を
92 つまり、カーネルがパイプからページを移動できない場合や、
93 パイプバッファがページ全部を参照していない場合は、
95 このフラグの最初の実装にはバグがあった。そのため、
96 Linux 2.6.21 以降ではこのフラグの操作はできないようになっている
99 コールでこのフラグを指定することは今も認められている)。
105 splice によるパイプ操作を非停止モード (nonblocking) で
108 は停止することもある。なぜなら、データのやり取りを行う
111 フラグをセットされていない場合) 停止する可能性があるからである。
114 この後の splice でさらに転送されるデータがあることを示す。
117 がソケットを参照している場合に有用なヒントとなる
136 返り値 0 はデータの転送が行わなかったことを示す。
137 この場合、処理を停止 (block) しても無意味である。
140 が参照するパイプの書き込み側に接続されている者がいないからである。
150 ファイルディスクリプタの一方または両方が有効ではない、
151 もしくは適切な read-write モードではない。
154 対象のファイルシステムが splice に対応していない、
155 または対象のファイルが追記モードでオープンされている、
156 .\" 追記モードでのエラーは 2.6.27 以降で発生する。
157 .\" それより前のカーネルでは追記モードでの splice() は正しく動作しない。
158 またはディスクリプタのどちらもパイプを参照していない、
159 または seek できないデバイスに対してオフセットが指定された。
168 のいずれかが NULL ではないが、対応するファイルディスクリプタが
172 システムコールは Linux 2.6.17 で初めて登場した。
174 このシステムコールは Linux 固有である。
180 を使うと、ユーザ空間プログラムは任意のカーネルバッファに対する
181 完全な制御ができる。カーネルバッファは、パイプに使用されているのと
182 同種のバッファを使ってカーネル内に実装されている。
183 大まかにいうと、これらのシステムコールは以下の仕事を行う:
186 バッファから任意のファイルディスクリプタや、その逆方向、
187 もしくはあるバッファから別のバッファへの、データ移動を行う。
190 あるバッファから別のバッファへのデータ「コピー」を行う。
193 ユーザ空間からバッファへのデータ「コピー」を行う。
195 ここではコピーの話をしているが、実際のコピーは一般的に回避される。
196 カーネルは、パイプ・バッファをカーネルメモリのページへのポインタ集合として
197 実装し、ページへの参照回数を管理することで、これを実現している。
198 カーネルは、対象となるページを参照する (出力バッファ用の) ポインタを
199 新規に作成することでバッファ内のページの「コピー」を作成し、
200 そのページの参照回数を増やす。つまり、ポインタだけがコピーされ、
203 .\" Linus: Now, imagine using the above in a media server, for example.
204 .\" Let's say that a year or two has passed, so that the video drivers
205 .\" have been updated to be able to do the splice thing, and what can
208 .\" - splice from the (mpeg or whatever - let's just assume that the video
209 .\" input is either digital or does the encoding on its own - like they
210 .\" pretty much all do) video input into a pipe (remember: no copies - the
211 .\" video input will just DMA directly into memory, and splice will just
212 .\" set up the pages in the pipe buffer)
213 .\" - tee that pipe to split it up
214 .\" - splice one end to a file (ie "save the compressed stream to disk")
215 .\" - splice the other end to a real-time video decoder window for your
216 .\" real-time viewing pleasure.
218 .\" Linus: Now, the advantage of splice()/tee() is that you can
219 .\" do zero-copy movement of data, and unlike sendfile() you can
220 .\" do it on _arbitrary_ data (and, as shown by "tee()", it's more
221 .\" than just sending the data to somebody else: you can duplicate
222 .\" the data and choose to forward it to two or more different
223 .\" users - for things like logging etc.).