OSDN Git Service

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