OSDN Git Service

Update README
[linuxjm/LDP_man-pages.git] / release / man2 / splice.2
1 .\" This manpage is Copyright (C) 2006 Jens Axboe
2 .\" and Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\"*******************************************************************
27 .\"
28 .\" This file was generated with po4a. Translate the source file.
29 .\"
30 .\"*******************************************************************
31 .\"
32 .\" Japanese Version Copyright (c) 2007  Akihiro MOTOKI
33 .\"         all rights reserved.
34 .\" Translated 2007-02-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
35 .\" Updated 2008-11-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.13
36 .\"
37 .TH SPLICE 2 2014\-12\-31 Linux "Linux Programmer's Manual"
38 .SH 名前
39 splice \- パイプとの間でデータを継ぎ合わせる
40 .SH 書式
41 .nf
42 \fB#define _GNU_SOURCE\fP         /* feature_test_macros(7) 参照 */
43 \fB#include <fcntl.h>\fP
44
45 .\" Return type was long before glibc 2.7
46 \fBssize_t splice(int \fP\fIfd_in\fP\fB, loff_t *\fP\fIoff_in\fP\fB, int \fP\fIfd_out\fP\fB,\fP
47 \fB               loff_t *\fP\fIoff_out\fP\fB, size_t \fP\fIlen\fP\fB, unsigned int \fP\fIflags\fP\fB);\fP
48 .fi
49 .SH 説明
50 \fBsplice\fP()  は、カーネルアドレス空間とユーザーアドレス空間との間のコピーを伴わずに、 2
51 つのファイルディスクリプター間でデータの移動を行う。 ファイルディスクリプター \fIfd_in\fP からファイルディスクリプター \fIfd_out\fP
52 へ最大 \fIlen\fP バイトを転送する。 2 つのファイルディスクリプターのうち一つは パイプを参照していなければならない。
53
54 \fIfd_in\fP と \fIoff_in\fP には以下のルールが適用される。
55 .IP * 3
56 \fIfd_in\fP がパイプを参照している場合、 \fIoff_in\fP は NULL でなければならない。
57 .IP *
58 \fIfd_in\fP がパイプを参照しておらず、かつ \fIoff_in\fP が NULL の場合、 バイトは \fIfd_in\fP
59 の現在のファイルオフセットから読み出され、 現在のファイルオフセットは適切に調整される。
60 .IP *
61 \fIfd_in\fP がパイプを参照しておらず、 \fIoff_in\fP が NULL でない場合、 \fIoff_in\fP は \fIfd_in\fP
62 からのデータ読み出しを開始する先頭オフセットを格納したバッファー へのポインターでなければならない。この場合、 \fIfd_in\fP
63 の現在のファイルオフセットは変更されない。
64 .PP
65 \fIfd_out\fP と \fIoff_out\fP に関しても同様である。
66
67 \fIflags\fP 引き数には、以下の値の 0 個以上をビット毎の論理和の形で指定する。
68 .TP  1.9i
69 \fBSPLICE_F_MOVE\fP
70 ページのコピーでなく移動を試みる。 これはカーネルに対するヒントでしかない。 つまり、カーネルがパイプからページを移動できない場合や、
71 パイプバッファーがページ全部を参照していない場合は、 ページのコピーが行われることもある。 このフラグの最初の実装にはバグがあった。そのため、
72 Linux 2.6.21 以降ではこのフラグの操作はできないようになっている (ただし、 \fBsplice\fP()
73 コールでこのフラグを指定することは今も認められている)。 将来、正しい実装が行われることだろう。
74 .TP 
75 \fBSPLICE_F_NONBLOCK\fP
76 入出力時に停止 (block) しない。 このフラグを指定すると、 splice によるパイプ操作を非停止モード (nonblocking) で
77 行おうとするが、その場合でも \fBsplice\fP()  は停止することもある。なぜなら、データのやり取りを行う ファイルディスクリプターは
78 (\fBO_NONBLOCK\fP フラグをセットされていない場合) 停止する可能性があるからである。
79 .TP 
80 \fBSPLICE_F_MORE\fP
81 この後の splice でさらに転送されるデータがあることを示す。 このフラグは \fIfd_out\fP がソケットを参照している場合に有用なヒントとなる
82 (\fBsend\fP(2)  の \fBMSG_MORE\fP や \fBtcp\fP(7)  の \fBTCP_CORK\fP の説明も参照)。
83 .TP 
84 \fBSPLICE_F_GIFT\fP
85 \fBsplice\fP()  では使用しない。 \fBvmsplice\fP(2)  参照。
86 .SH 返り値
87 成功して完了すると、 \fBsplice\fP()  はパイプから出し入れしたバイト数を返す。 返り値 0 はデータの転送が行わなかったことを示す。
88 この場合、処理を停止 (block) しても無意味である。 なぜなら、 \fIfd_in\fP
89 が参照するパイプの書き込み側に接続されている者がいないからである。
90
91 エラーの場合、 \fBsplice\fP()  は \-1 を返し、 \fIerrno\fP にエラーを示す値を設定する。
92 .SH エラー
93 .TP 
94 \fBEAGAIN\fP
95 \fBSPLICE_F_NONBLOCK\fP が \fIflags\fP に指定されていて、かつ操作が停止するような状態であった。
96 .TP 
97 \fBEBADF\fP
98 ファイルディスクリプターの一方または両方が有効ではない、 もしくは適切な read\-write モードではない。
99 .TP 
100 \fBEINVAL\fP
101 .\" The append-mode error is given since 2.6.27; in earlier kernels,
102 .\" splice() in append mode was broken
103 対象のファイルシステムが splice に対応していない、 または対象のファイルが追記モードでオープンされている、
104 またはディスクリプターのどちらもパイプを参照していない、 または seek できないデバイスに対してオフセットが指定された。
105 .TP 
106 \fBENOMEM\fP
107 メモリー不足。
108 .TP 
109 \fBESPIPE\fP
110 \fIoff_in\fP か \fIoff_out\fP のいずれかが NULL ではないが、対応するファイルディスクリプターが パイプを参照している。
111 .SH バージョン
112 \fBsplice\fP() システムコールは Linux 2.6.17 で初めて登場した。
113 ライブラリによるサポートは glibc バージョン 2.5 で追加された。
114 .SH 準拠
115 このシステムコールは Linux 固有である。
116 .SH 注意
117 3 つのシステムコール (\fBsplice\fP(), \fBvmsplice\fP(2), \fBtee\fP(2))
118 を使うと、ユーザー空間プログラムは任意のカーネルバッファーに対する 完全な制御ができる。カーネルバッファーは、パイプに使用されているのと
119 同種のバッファーを使ってカーネル内に実装されている。 大まかにいうと、これらのシステムコールは以下の仕事を行う:
120 .TP  1.2i
121 \fBsplice\fP()
122 バッファーから任意のファイルディスクリプターや、その逆方向、 もしくはあるバッファーから別のバッファーへの、データ移動を行う。
123 .TP 
124 \fBtee\fP(2)
125 あるバッファーから別のバッファーへのデータ「コピー」を行う。
126 .TP 
127 \fBvmsplice\fP(2)
128 ユーザー空間からバッファーへのデータ「コピー」を行う。
129 .PP
130 .\"
131 .\" Linus: Now, imagine using the above in a media server, for example.
132 .\" Let's say that a year or two has passed, so that the video drivers
133 .\" have been updated to be able to do the splice thing, and what can
134 .\" you do? You can:
135 .\"
136 .\" - splice from the (mpeg or whatever - let's just assume that the video
137 .\"   input is either digital or does the encoding on its own - like they
138 .\"   pretty much all do) video input into a pipe (remember: no copies - the
139 .\"   video input will just DMA directly into memory, and splice will just
140 .\"   set up the pages in the pipe buffer)
141 .\" - tee that pipe to split it up
142 .\" - splice one end to a file (ie "save the compressed stream to disk")
143 .\" - splice the other end to a real-time video decoder window for your
144 .\"   real-time viewing pleasure.
145 .\"
146 .\" Linus: Now, the advantage of splice()/tee() is that you can
147 .\" do zero-copy movement of data, and unlike sendfile() you can
148 .\" do it on _arbitrary_ data (and, as shown by "tee()", it's more
149 .\" than just sending the data to somebody else: you can duplicate
150 .\" the data and choose to forward it to two or more different
151 .\" users - for things like logging etc.).
152 .\"
153 ここではコピーの話をしているが、実際のコピーは一般的に回避される。 カーネルは、パイプバッファーをカーネルメモリーのページへのポインター集合として
154 実装し、ページへの参照回数を管理することで、これを実現している。 カーネルは、対象となるページを参照する (出力バッファー用の) ポインターを
155 新規に作成することでバッファー内のページの「コピー」を作成し、 そのページの参照回数を増やす。つまり、ポインターだけがコピーされ、
156 バッファーのページはコピーされない。
157 .SH 例
158 \fBtee\fP(2)  参照。
159 .SH 関連項目
160 \fBsendfile\fP(2), \fBtee\fP(2), \fBvmsplice\fP(2)
161 .SH この文書について
162 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部
163 である。プロジェクトの説明とバグ報告に関する情報は
164 http://www.kernel.org/doc/man\-pages/ に書かれている。