OSDN Git Service

9c9a9acf09fab5a5b0a13bc6c617b90793f360e2
[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 .\" 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
30 .\" 
31 .TH SPLICE 2 2009-09-15 "Linux" "Linux Programmer's Manual"
32 .\"O .SH NAME
33 .SH 名前
34 .\"O splice \- splice data to/from a pipe
35 splice \- パイプとの間でデータを継ぎ合わせる
36 .\"O .SH SYNOPSIS
37 .SH 書式
38 .nf
39 .\"O .BR "#define _GNU_SOURCE" "         /* See feature_test_macros(7) */"
40 .BR "#define _GNU_SOURCE" "         /* feature_test_macros(7) 参照 */"
41 .B #include <fcntl.h>
42
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 );
46 .fi
47 .\" Return type was long before glibc 2.7
48 .\"O .SH DESCRIPTION
49 .SH 説明
50 .\"O .BR splice ()
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
54 .\"O .I len
55 .\"O bytes of data from the file descriptor
56 .\"O .I fd_in
57 .\"O to the file descriptor
58 .\"O .IR fd_out ,
59 .\"O where one of the descriptors must refer to a pipe.
60 .BR splice ()
61 は、カーネルアドレス空間とユーザアドレス空間との間のコピーを伴わずに、
62 2 つのファイルディスクリプタ間でデータの移動を行う。
63 ファイルディスクリプタ
64 .I fd_in
65 からファイルディスクリプタ
66 .I fd_out
67 へ最大
68 .I len
69 バイトを転送する。
70 2 つのファイルディスクリプタのうち一つは
71 パイプを参照していなければならない。
72 .PP
73 .\"O If
74 .\"O .I fd_in
75 .\"O refers to a pipe, then
76 .\"O .I off_in
77 .\"O must be NULL.
78 .I fd_in
79 がパイプを参照している場合、
80 .I off_in
81 は NULL でなければならない。
82 .\"O If
83 .\"O .I fd_in
84 .\"O does not refer to a pipe and
85 .\"O .I off_in
86 .\"O is NULL, then bytes are read from
87 .\"O .I fd_in
88 .\"O starting from the current file offset,
89 .\"O and the current file offset is adjusted appropriately.
90 .I fd_in
91 がパイプを参照しておらず、
92 .I off_in
93 が NULL の場合、
94 .I fd_in
95 の現在のファイルオフセットから始まるバイトを読み出す。
96 現在のファイルオフセットは適切に調整される。
97 .\"O If
98 .\"O .I fd_in
99 .\"O does not refer to a pipe and
100 .\"O .I off_in
101 .\"O is not NULL, then
102 .\"O .I off_in
103 .\"O must point to a buffer which specifies the starting
104 .\"O offset from which bytes will be read from
105 .\"O .IR fd_in ;
106 .\"O in this case, the current file offset of
107 .\"O .I fd_in
108 .\"O is not changed.
109 .I fd_in
110 がパイプを参照しておらず、
111 .I off_in
112 が NULL でない場合、
113 .I off_in
114
115 .I fd_in
116 からのデータ読み出しを開始する先頭オフセットを格納したバッファ
117 へのポインタでなければならない。この場合、
118 .I fd_in
119 の現在のファイルオフセットは変更されない。
120 .\"O Analogous statements apply for
121 .\"O .I fd_out
122 .\"O and
123 .\"O .IR off_out .
124 .I fd_out
125
126 .I off_out
127 に関しても同様である。
128 .PP
129 .\"O The
130 .\"O .I flags
131 .\"O argument is a bit mask that is composed by ORing together
132 .\"O zero or more of the following values:
133 .I flags
134 引き数には、以下の値の 0 個以上のビット単位の論理和を
135 とったものを指定する:
136 .TP 1.9i
137 .B SPLICE_F_MOVE
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.
143 ページのコピーでなく移動を試みる。
144 これはカーネルに対するヒントでしかない。
145 つまり、カーネルがパイプからページを移動できない場合や、
146 パイプバッファがページ全部を参照していない場合は、
147 ページのコピーが行われることもある。
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
151 .\"O .BR splice ()
152 .\"O call);
153 .\"O in the future, a correct implementation may be restored.
154 このフラグの最初の実装にはバグがあった。そのため、
155 Linux 2.6.21 以降ではこのフラグの操作はできないようになっている
156 (ただし、
157 .BR splice ()
158 コールでこのフラグを指定することは今も認められている)。
159 将来、正しい実装が行われることだろう。
160 .TP
161 .B SPLICE_F_NONBLOCK
162 .\"O Do not block on I/O.
163 .\"O This makes the splice pipe operations nonblocking, but
164 .\"O .BR splice ()
165 .\"O may nevertheless block because the file descriptors that
166 .\"O are spliced to/from may block (unless they have the
167 .\"O .B O_NONBLOCK
168 .\"O flag set).
169 入出力時に停止 (block) しない。
170 このフラグを指定すると、
171 splice によるパイプ操作を非停止モード (nonblocking) で
172 行おうとするが、その場合でも
173 .BR splice ()
174 は停止することもある。なぜなら、データのやり取りを行う
175 ファイルディスクリプタは
176 .RB ( O_NONBLOCK
177 フラグをセットされていない場合) 停止する可能性があるからである。
178 .TP
179 .B SPLICE_F_MORE
180 .\"O More data will be coming in a subsequent splice.
181 .\"O This is a helpful hint when
182 .\"O the
183 .\"O .I fd_out
184 .\"O refers to a socket (see also the description of
185 .\"O .B MSG_MORE
186 .\"O in
187 .\"O .BR send (2),
188 .\"O and the description of
189 .\"O .B TCP_CORK
190 .\"O in
191 .\"O .BR tcp (7))
192 この後の splice でさらに転送されるデータがあることを示す。
193 このフラグは
194 .I fd_out
195 がソケットを参照している場合に有用なヒントとなる
196 .RB ( send (2)
197
198 .B MSG_MORE
199
200 .BR tcp (7)
201
202 .B TCP_CORK
203 の説明も参照)。
204 .TP
205 .B SPLICE_F_GIFT
206 .\"O Unused for
207 .\"O .BR splice ();
208 .\"O see
209 .\"O .BR vmsplice (2).
210 .BR splice ()
211 では使用しない。
212 .BR vmsplice (2)
213 参照。
214 .\"O .SH RETURN VALUE
215 .SH 返り値
216 .\"O Upon successful completion,
217 .\"O .BR splice ()
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
223 .\"O .IR fd_in .
224 成功して完了すると、
225 .BR splice ()
226 はパイプから出し入れしたバイト数を返す。
227 返り値 0 はデータの転送が行わなかったことを示す。
228 この場合、処理を停止 (block) しても無意味である。
229 なぜなら、
230 .I fd_in
231 が参照するパイプの書き込み側に接続されている者がいないからである。
232 .PP
233 .\"O On error,
234 .\"O .BR splice ()
235 .\"O returns \-1 and
236 .\"O .I errno
237 .\"O is set to indicate the error.
238 エラーの場合、
239 .BR splice ()
240 は \-1 を返し、
241 .I errno
242 にエラーを示す値を設定する。
243 .\"O .SH ERRORS
244 .SH エラー
245 .TP
246 .B EBADF
247 .\"O One or both file descriptors are not valid,
248 .\"O or do not have proper read-write mode.
249 ファイルディスクリプタの一方または両方が有効ではない、
250 もしくは適切な read-write モードではない。
251 .TP
252 .B EINVAL
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 できないデバイスに対してオフセットが指定された。
265 .TP
266 .B ENOMEM
267 .\"O Out of memory.
268 メモリ不足。
269 .TP
270 .B ESPIPE
271 .\"O Either
272 .\"O .I off_in
273 .\"O or
274 .\"O .I off_out
275 .\"O was not NULL, but the corresponding file descriptor refers to a pipe.
276 .I off_in
277
278 .I off_out
279 のいずれかが NULL ではないが、対応するファイルディスクリプタが
280 パイプを参照している。
281 .\"O .SH VERSIONS
282 .SH バージョン
283 .\"O The
284 .\"O .BR splice ()
285 .\"O system call first appeared in Linux 2.6.17.
286 .BR splice ()
287 システムコールは Linux 2.6.17 で初めて登場した。
288 .\"O .SH "CONFORMING TO"
289 .SH 準拠
290 .\"O This system call is Linux-specific.
291 このシステムコールは Linux 固有である。
292 .\"O .SH NOTES
293 .SH 注意
294 .\"O The three system calls
295 .\"O .BR splice (),
296 .\"O .BR vmsplice (2),
297 .\"O and
298 .\"O .BR tee (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.
302 3 つのシステムコール
303 .RB ( splice (),
304 .BR vmsplice (2),
305 .BR tee (2))
306 を使うと、ユーザ空間プログラムは任意のカーネルバッファに対する
307 完全な制御ができる。カーネルバッファは、パイプに使用されているのと
308 同種のバッファを使ってカーネル内に実装されている。
309 .\"O In overview, these system calls perform the following tasks:
310 大まかにいうと、これらのシステムコールは以下の仕事を行う:
311 .TP 1.2i
312 .BR splice ()
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 もしくはあるバッファから別のバッファへの、データ移動を行う。
317 .TP
318 .BR tee (2)
319 .\"O "copies" the data from one buffer to another.
320 あるバッファから別のバッファへのデータ「コピー」を行う。
321 .TP
322 .BR vmsplice (2)
323 .\"O "copies" data from user space into the buffer.
324 ユーザ空間からバッファへのデータ「コピー」を行う。
325 .PP
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 そのページの参照回数を増やす。つまり、ポインタだけがコピーされ、
339 バッファのページはコピーされない。
340 .\"
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
344 .\" you do? You can:
345 .\"
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.
355 .\"
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.).
362 .\"
363 .\"O .SH EXAMPLE
364 .SH 例
365 .\"O See
366 .\"O .BR tee (2).
367 .BR tee (2)
368 参照。
369 .\"O .SH SEE ALSO
370 .SH 関連項目
371 .BR sendfile (2),
372 .BR tee (2),
373 .BR vmsplice (2)