OSDN Git Service

9f6e3815c2af14b648679861355b6c11eff4b661
[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 2012\-05\-04 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 へ最大 \fIlen\fP バイトを転送する。 2
52 つのファイルディスクリプタのうち一つは パイプを参照していなければならない。
53
54 \fIfd_in\fP がパイプを参照している場合、 \fIoff_in\fP は NULL でなければならない。 \fIfd_in\fP がパイプを参照しておらず、
55 \fIoff_in\fP が NULL の場合、 \fIfd_in\fP の現在のファイルオフセットから始まるバイトを読み出す。
56 現在のファイルオフセットは適切に調整される。 \fIfd_in\fP がパイプを参照しておらず、 \fIoff_in\fP が NULL でない場合、
57 \fIoff_in\fP は \fIfd_in\fP からのデータ読み出しを開始する先頭オフセットを格納したバッファ へのポインタでなければならない。この場合、
58 \fIfd_in\fP の現在のファイルオフセットは変更されない。 \fIfd_out\fP と \fIoff_out\fP に関しても同様である。
59
60 \fIflags\fP 引き数には、以下の値の 0 個以上をビット毎の論理和の形で指定する。
61 .TP  1.9i
62 \fBSPLICE_F_MOVE\fP
63 ページのコピーでなく移動を試みる。 これはカーネルに対するヒントでしかない。 つまり、カーネルがパイプからページを移動できない場合や、
64 パイプバッファがページ全部を参照していない場合は、 ページのコピーが行われることもある。 このフラグの最初の実装にはバグがあった。そのため、 Linux
65 2.6.21 以降ではこのフラグの操作はできないようになっている (ただし、 \fBsplice\fP()
66 コールでこのフラグを指定することは今も認められている)。 将来、正しい実装が行われることだろう。
67 .TP 
68 \fBSPLICE_F_NONBLOCK\fP
69 入出力時に停止 (block) しない。 このフラグを指定すると、 splice によるパイプ操作を非停止モード (nonblocking) で
70 行おうとするが、その場合でも \fBsplice\fP()  は停止することもある。なぜなら、データのやり取りを行う ファイルディスクリプタは
71 (\fBO_NONBLOCK\fP フラグをセットされていない場合) 停止する可能性があるからである。
72 .TP 
73 \fBSPLICE_F_MORE\fP
74 この後の splice でさらに転送されるデータがあることを示す。 このフラグは \fIfd_out\fP がソケットを参照している場合に有用なヒントとなる
75 (\fBsend\fP(2)  の \fBMSG_MORE\fP や \fBtcp\fP(7)  の \fBTCP_CORK\fP の説明も参照)。
76 .TP 
77 \fBSPLICE_F_GIFT\fP
78 \fBsplice\fP()  では使用しない。 \fBvmsplice\fP(2)  参照。
79 .SH 返り値
80 成功して完了すると、 \fBsplice\fP()  はパイプから出し入れしたバイト数を返す。 返り値 0 はデータの転送が行わなかったことを示す。
81 この場合、処理を停止 (block) しても無意味である。 なぜなら、 \fIfd_in\fP
82 が参照するパイプの書き込み側に接続されている者がいないからである。
83
84 エラーの場合、 \fBsplice\fP()  は \-1 を返し、 \fIerrno\fP にエラーを示す値を設定する。
85 .SH エラー
86 .TP 
87 \fBEBADF\fP
88 ファイルディスクリプタの一方または両方が有効ではない、 もしくは適切な read\-write モードではない。
89 .TP 
90 \fBEINVAL\fP
91 .\" The append-mode error is given since 2.6.27; in earlier kernels,
92 .\" splice() in append mode was broken
93 Target filesystem doesn't support splicing; target file is opened in append
94 mode; neither of the descriptors refers to a pipe; or offset given for
95 nonseekable device.
96 .TP 
97 \fBENOMEM\fP
98 メモリ不足。
99 .TP 
100 \fBESPIPE\fP
101 \fIoff_in\fP か \fIoff_out\fP のいずれかが NULL ではないが、対応するファイルディスクリプタが パイプを参照している。
102 .SH バージョン
103 \fBsplice\fP() システムコールは Linux 2.6.17 で初めて登場した。
104 ライブラリによるサポートは glibc バージョン 2.5 で追加された。
105 .SH 準拠
106 このシステムコールは Linux 固有である。
107 .SH 注意
108 3 つのシステムコール (\fBsplice\fP(), \fBvmsplice\fP(2), \fBtee\fP(2))
109 を使うと、ユーザ空間プログラムは任意のカーネルバッファに対する 完全な制御ができる。カーネルバッファは、パイプに使用されているのと
110 同種のバッファを使ってカーネル内に実装されている。 大まかにいうと、これらのシステムコールは以下の仕事を行う:
111 .TP  1.2i
112 \fBsplice\fP()
113 バッファから任意のファイルディスクリプタや、その逆方向、 もしくはあるバッファから別のバッファへの、データ移動を行う。
114 .TP 
115 \fBtee\fP(2)
116 あるバッファから別のバッファへのデータ「コピー」を行う。
117 .TP 
118 \fBvmsplice\fP(2)
119 ユーザ空間からバッファへのデータ「コピー」を行う。
120 .PP
121 .\"
122 .\" Linus: Now, imagine using the above in a media server, for example.
123 .\" Let's say that a year or two has passed, so that the video drivers
124 .\" have been updated to be able to do the splice thing, and what can
125 .\" you do? You can:
126 .\"
127 .\" - splice from the (mpeg or whatever - let's just assume that the video
128 .\"   input is either digital or does the encoding on its own - like they
129 .\"   pretty much all do) video input into a pipe (remember: no copies - the
130 .\"   video input will just DMA directly into memory, and splice will just
131 .\"   set up the pages in the pipe buffer)
132 .\" - tee that pipe to split it up
133 .\" - splice one end to a file (ie "save the compressed stream to disk")
134 .\" - splice the other end to a real-time video decoder window for your
135 .\"   real-time viewing pleasure.
136 .\"
137 .\" Linus: Now, the advantage of splice()/tee() is that you can
138 .\" do zero-copy movement of data, and unlike sendfile() you can
139 .\" do it on _arbitrary_ data (and, as shown by "tee()", it's more
140 .\" than just sending the data to somebody else: you can duplicate
141 .\" the data and choose to forward it to two or more different
142 .\" users - for things like logging etc.).
143 .\"
144 ここではコピーの話をしているが、実際のコピーは一般的に回避される。 カーネルは、パイプ・バッファをカーネルメモリのページへのポインタ集合として
145 実装し、ページへの参照回数を管理することで、これを実現している。 カーネルは、対象となるページを参照する (出力バッファ用の) ポインタを
146 新規に作成することでバッファ内のページの「コピー」を作成し、 そのページの参照回数を増やす。つまり、ポインタだけがコピーされ、
147 バッファのページはコピーされない。
148 .SH 例
149 \fBtee\fP(2)  参照。
150 .SH 関連項目
151 \fBsendfile\fP(2), \fBtee\fP(2), \fBvmsplice\fP(2)
152 .SH この文書について
153 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.54 の一部
154 である。プロジェクトの説明とバグ報告に関する情報は
155 http://www.kernel.org/doc/man\-pages/ に書かれている。