.\" This man page is Copyright (C) 1998 Pawel Krawczyk. .\" .\" %%%LICENSE_START(VERBATIM_ONE_PARA) .\" Permission is granted to distribute possibly modified copies .\" of this page provided the header is included verbatim, .\" and in case of nontrivial modification author and date .\" of the modification is added to the header. .\" %%%LICENSE_END .\" .\" $Id: sendfile.2,v 1.5 1999/05/18 11:54:11 freitag Exp $ .\" 2000-11-19 bert hubert : in_fd cannot be socket .\" .\" 2004-12-17, mtk .\" updated description of in_fd and out_fd for 2.6 .\" Various wording and formatting changes .\" .\" 2005-03-31 Martin Pool mmap() improvements .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1999 HANATAKA Shinya .\" all rights reserved. .\" Translated 1999-06-26, HANATAKA Shinya .\" Updated 2001-02-16, Kentaro Shirakata .\" Updated 2003-09-08, Kentaro Shirakata .\" Updated 2005-03-14, Akihiro MOTOKI .\" Updated 2005-04-17, Akihiro MOTOKI .\" Updated 2010-04-18, Akihiro MOTOKI , LDP v3.24 .\" Updated 2012-04-30, Akihiro MOTOKI .\" .TH SENDFILE 2 2017\-09\-15 Linux "Linux Programmer's Manual" .SH 名前 sendfile \- ファイルディスクリプター間でデータを転送する .SH 書式 \fB#include \fP .PP .\" The below is too ugly. Comments about glibc versions belong .\" in the notes, not in the header. .\" .\" .B #include .\" .br .\" .B #if (__GLIBC__==2 && __GLIBC_MINOR__>=1) || __GLIBC__>2 .\" .br .\" .B #include .\" .br .\" #else .\" .br .\" .B #include .\" .br .\" .B /* No system prototype before glibc 2.1. */ .\" .br .\" .BI "ssize_t sendfile(int" " out_fd" ", int" " in_fd" ", off_t *" \ .\" offset ", size_t" " count" ) .\" .br .\" .B #endif .\" \fBssize_t sendfile(int\fP\fI out_fd\fP\fB, int\fP\fI in_fd\fP\fB, off_t *\fP\fIoffset\fP\fB, size_t\fP\fI count\fP\fB);\fP .SH 説明 \fBsendfile\fP() は、あるファイルディスクリプターから別の ファイルディスクリプターへのデータのコピーを行う。 このコピーはカーネル内で行われるので、 \fBsendfile\fP() は、 \fBread\fP(2) と \fBwrite\fP(2) を組み合わせるよりも効率がよい。 \fBread\fP(2) や \fBwrite\fP(2) ではユーザー空間との間でデータの転送が必要となるからである。 .PP \fIin_fd\fP は読み込みのためにオープンされたファイルディスクリプター、 \fIout_fd\fP は書き込みのためにオープンされたディスクリプターでなければならない。 .PP \fIoffset\fP が NULL でない場合、 \fIoffset\fP は \fBsendfile\fP() が \fIin_fd\fP のどこからデータを読み始めるかを示すファイルオフセットを保持する変数への ポインターである。 \fBsendfile\fP() は復帰する時、この変数に最後に読み込んだバイトの 次のバイトのオフセットを書き込む。 \fIoffset\fP が NULL でない場合、 \fBsendfile\fP() は \fIin_fd\fP のファイルオフセットを変更しない。 NULL の場合は、ファイルオフセットを \fIin_fd\fP から読み込んだバイト数を反映した位置に調整する。 .PP \fIoffset\fP が NULL の場合、データは \fIin_fd\fP のファイルオフセットから読み出され、 ファイルオフセットはこの呼び出しで更新される。 .PP \fIcount\fP は、ファイルディスクリプター間でコピーするバイト数である。 .PP \fIin_fd\fP 引数は \fBmmap\fP(2) 風の操作ができるファイルを指していなければならな い (ソケットを指定することはできない)。 .PP 2.6.33 より前の Linux カーネルでは \fIout_fd\fP はソケットを参照していなければな らない。Linux 2.6.33 以降では、任意のファイルを参照することができる。 通常のファイルの場合には \fBsendfile\fP() はファイルオフセットを適切に変更する。 .SH 返り値 If the transfer was successful, the number of bytes written to \fIout_fd\fP is returned. Note that a successful call to \fBsendfile\fP() may write fewer bytes than requested; the caller should be prepared to retry the call if there were unsent bytes. See also NOTES. .PP エラーの場合は \-1 が返され、 \fIerrno\fP が適切に設定される。 .SH エラー .TP \fBEAGAIN\fP \fBO_NONBLOCK\fP を用いて非ブロック I/O が選択されたが、書き込みがブロックされた。 .TP \fBEBADF\fP 入力ファイルが読み込みのためにオープンされていないか、 出力ファイルが書き込みのためにオープンされていない。 .TP \fBEFAULT\fP アドレスがおかしい。 .TP \fBEINVAL\fP ディスクリプターが有効でないか、ロックされている。もしくは \fBmmap\fP(2) 風の操作が \fIin_fd\fP では利用できない。もしくは \fIcount\fP が負である。 .TP \fBEINVAL\fP \fIout_fd\fP has the \fBO_APPEND\fP flag set. This is not currently supported by \fBsendfile\fP(). .TP \fBEIO\fP \fIin_fd\fP から読み込んでいるうちに予期しないエラーが起こった。 .TP \fBENOMEM\fP \fIin_fd\fP から読み込むための十分なメモリーがない。 .TP \fBEOVERFLOW\fP \fIcount\fP is too large, the operation would result in exceeding the maximum size of either the input file or the output file. .TP \fBESPIPE\fP \fIoffset\fP is not NULL but the input file is not seekable. .SH バージョン \fBsendfile\fP は Linux 2.2 で初めて登場した。 インクルードファイル \fI\fP は glibc 2.1 から存在している。 .SH 準拠 POSIX.1\-2001 や他の標準では規定されていない。 .PP 他の UNIX システムでは、異なった方式やプロトタイプで \fBsendfile\fP() を実装している。移植性を考慮したプログラムでは使用すべきではない。 .SH 注意 .\" commit e28cc71572da38a5a12c1cfe4d7032017adccf69 \fBsendfile\fP() will transfer at most 0x7ffff000 (2,147,479,552) bytes, returning the number of bytes actually transferred. (This is true on both 32\-bit and 64\-bit systems.) .PP \fBsendfile\fP() を使って TCP ソケットにファイルを送ろうとしていて、 ファイルの内容の前にヘッダーデータを付け加える必要がある場合は、 パケット数を最小にして性能を上げるために \fBtcp\fP(7) に記述されている \fBTCP_CORK\fP オプションを使うといいだろう。 .PP In Linux 2.4 and earlier, \fIout_fd\fP could also refer to a regular file; this possibility went away in the Linux 2.6.x kernel series, but was restored in Linux 2.6.33. .PP 元々の Linux \fBsendfile\fP() システムコールは大きなファイルオフセットを 扱えるように設計されていなかった。その結果、Linux 2.4 で、 ビット幅の大きな \fIoffset\fP 引数を持った \fBsendfile64\fP() が追加された。 glibc の \fBsendfile\fP() のラッパー関数はカーネルによるこの違いを吸収している。 .PP \fBsendfile\fP() が \fBEINVAL\fP や \fBENOSYS\fP で失敗するような場合は、 アプリケーションは \fBread\fP(2)/\fBwrite\fP(2) に戻すことを考えてもよいかもしれない。 .PP If \fIout_fd\fP refers to a socket or pipe with zero\-copy support, callers must ensure the transferred portions of the file referred to by \fIin_fd\fP remain unmodified until the reader on the other end of \fIout_fd\fP has consumed the transferred data. .PP The Linux\-specific \fBsplice\fP(2) call supports transferring data between arbitrary file descriptors provided one (or both) of them is a pipe. .SH 関連項目 \fBcopy_file_range\fP(2), \fBmmap\fP(2), \fBopen\fP(2), \fBsocket\fP(2), \fBsplice\fP(2) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。