-.\" Hey Emacs! This file is -*- nroff -*- source.
-.\"
.\" This manpage is Copyright (C) 1992 Drew Eckhardt;
-.\" 1993 Michael Haardt, Ian Jackson.
+.\" and Copyright (C) 1993 Michael Haardt, Ian Jackson.
.\"
+.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
.\"
.\" Modified Sat Jul 24 00:06:00 1993 by Rik Faith <faith@cs.unc.edu>
.\" Modified Wed Jan 17 16:02:32 1996 by Michael Haardt
.\" Modified Sat Jul 12 20:45:39 1997 by Michael Haardt
.\" <michael@cantor.informatik.rwth-aachen.de>
.\"
+.\"*******************************************************************
+.\"
+.\" This file was generated with po4a. Translate the source file.
+.\"
+.\"*******************************************************************
+.\"
.\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
.\" all rights reserved.
.\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
.\" Updated 2005-10-14, Akihiro MOTOKI
.\" Updated 2008-02-10, Akihiro MOTOKI, LDP v2.77
.\" Updated 2009-04-13, Akihiro MOTOKI, LDP v3.20
+.\" Updated 2012-04-30, Akihiro MOTOKI <amotoki@gmail.com>
+.\" Updated 2013-05-06, Akihiro MOTOKI <amotoki@gmail.com>
.\"
-.\"WORD: descriptor ディスクリプター
-.\"WORD: buffer バッファー
-.\"WORD: signal シグナル
-.\"WORD: process group プロセス・グループ
-.\"WORD: backgraound バックグランド
-.\"WORD: orphan 孤立
-.\"WORD: open オープン
-.\"WORD: directory ディレクトリ
-.\"WORD: object オブジェクト
-.\"
-.TH READ 2 2009-02-23 "Linux" "Linux Programmer's Manual"
-.\"O .SH NAME
+.TH READ 2 2014\-05\-04 Linux "Linux Programmer's Manual"
.SH 名前
-.\"O read \- read from a file descriptor
-read \- ファイル・ディスクリプターから読み込む
-.\"O .SH SYNOPSIS
+read \- ファイルディスクリプタから読み込む
.SH 書式
.nf
-.B #include <unistd.h>
+\fB#include <unistd.h>\fP
.sp
-.BI "ssize_t read(int " fd ", void *" buf ", size_t " count );
+\fBssize_t read(int \fP\fIfd\fP\fB, void *\fP\fIbuf\fP\fB, size_t \fP\fIcount\fP\fB);\fP
.fi
-.\"O .SH DESCRIPTION
.SH 説明
-.\"O .BR read ()
-.\"O attempts to read up to
-.\"O .I count
-.\"O bytes from file descriptor
-.\"O .I fd
-.\"O into the buffer starting at
-.\"O .IR buf .
-.BR read ()
-はファイル・ディスクリプター (file descriptor)
-.I fd
-から最大
-.I count
-バイトを
-.I buf
+\fBread\fP() はファイルディスクリプタ (file descriptor) \fIfd\fP から最大 \fIcount\fP バイトを \fIbuf\fP
で始まるバッファーへ読み込もうとする。
-.PP
-.\"O If
-.\"O .I count
-.\"O is zero,
-.\"O .BR read ()
-.\"O returns zero and has no other results.
-.\"O If
-.\"O .I count
-.\"O is greater than
-.\"O .BR SSIZE_MAX ,
-.\"O the result is unspecified.
-.I count
-が 0 ならば、
-.BR read ()
-は 0 を返し、他に何も起きない。
-.I count
-が
-.B SSIZE_MAX
-より大きければ、結果は特定できない。
-.\"O .SH "RETURN VALUE"
+
+seek に対応しているファイルでは、read
+は現在のファイルオフセットから行われ、ファイルオフセットは読み込んだバイト数分だけ進められる。現在のファイルオフセットがファイル末尾かそれより先の場合は、読み出しは行われず、
+\fBread\fP() は 0 を返す。
+
+\fIcount\fP が 0 の場合、 \fBread\fP() は以下で説明するエラーを検出する\fI場合がある\fP。 どのエラーもなかった場合、もしくは
+\fBread\fP() がエラーのチェックを行わない場合、 \fIcount\fP が 0 で呼び出された \fBread\fP() は 0 を返し、何も行わない。
+
+\fIcount\fP が \fBSSIZE_MAX\fP より大きければ、結果は規定できない。
.SH 返り値
-.\"O On success, the number of bytes read is returned (zero indicates end of
-.\"O file), and the file position is advanced by this number.
-.\"O It is not an error if this number is smaller than the number of bytes
-.\"O requested; this may happen for example because fewer bytes are actually
-.\"O available right now (maybe because we were close to end-of-file, or
-.\"O because we are reading from a pipe, or from a terminal), or because
-.\"O .BR read ()
-.\"O was interrupted by a signal.
-成功した場合、読み込んだバイト数を返す (0 はファイルの終りを意味する)。
-ファイル位置はこの数だけ進められる。
-この数が要求した数より小さかったとしてもエラーではない;
-例えば今すぐには実際にそれだけの数しかない場合 (ファイルの最後に近いのかも
-しれないし、パイプ (pipe) や端末 (terminal) から読み込んでいるかもしれない) や
-.BR read ()
-がシグナル (signal) によって割り込まれた場合にこれは起こりえる。
-.\"O On error, \-1 is returned, and
-.\"O .I errno
-.\"O is set appropriately.
-.\"O In this case it is left unspecified whether
-.\"O the file position (if any) changes.
-エラーの場合は、\-1 が返され、
-.I errno
-が適切に設定される。この場合はファイル位置が変更されるかどうかは
-不定である。
+成功した場合、読み込んだバイト数を返す (0 はファイルの終りを意味する)。 ファイル位置はこの数だけ進められる。
+この数が要求した数より小さかったとしてもエラーではない; 例えば今すぐには実際にそれだけの数しかない場合 (ファイルの最後に近いのかも
+しれないし、パイプ (pipe) や端末 (terminal) から読み込んでいるかもしれない) や \fBread\fP() がシグナル (signal)
+によって割り込まれた場合にこれは起こりえる。 エラーの場合は、\-1 が返され、 \fIerrno\fP
+が適切に設定される。この場合はファイル位置が変更されるかどうかは 不定である。
.SH エラー
-.TP
-.B EAGAIN
-.\"O The file descriptor
-.\"O .I fd
-.\"O refers to a file other than a socket and has been marked nonblocking
-.\"O .RB ( O_NONBLOCK ),
-.\"O and the read would block.
-ファイル・ディスクリプター
-.I fd
-がソケット以外のファイルを参照していて、
-非停止 (nonblocking) モード
-.RB ( O_NONBLOCK )
+.TP
+\fBEAGAIN\fP
+ファイルディスクリプタ \fIfd\fP がソケット以外のファイルを参照していて、 非停止 (nonblocking) モード (\fBO_NONBLOCK\fP)
に設定されており、読み込みを行うと停止する状況にある。
-.TP
-.\"O .BR EAGAIN " or " EWOULDBLOCK
-.BR EAGAIN " または " EWOULDBLOCK
+.TP
+\fBEAGAIN\fP または \fBEWOULDBLOCK\fP
.\" Actually EAGAIN on Linux
-.\"O The file descriptor
-.\"O .I fd
-.\"O refers to a socket and has been marked nonblocking
-.\"O .RB ( O_NONBLOCK ),
-.\"O and the read would block.
-.\"O POSIX.1-2001 allows either error to be returned for this case,
-.\"O and does not require these constants to have the same value,
-.\"O so a portable application should check for both possibilities.
-ファイル・ディスクリプター
-.I fd
-がソケットを参照していて、非停止 (nonblocking) モード
-.RB ( O_NONBLOCK )
-に設定されており、読み込みを行うと停止する状況にある。
-POSIX.1-2001 は、この場合にどちらのエラーを返すことも認めており、
-これら 2 つの定数が同じ値を持つことも求めていない。
-したがって、移植性が必要なアプリケーションでは、両方の可能性を
-確認すべきである。
-.TP
-.B EBADF
-.\"O .I fd
-.\"O is not a valid file descriptor or is not open for reading.
-.I fd
-が有効なファイル・ディスクリプターでないか、読み込みのために
-オープン (open) されていない。
-.TP
-.B EFAULT
-.\"O .I buf
-.\"O is outside your accessible address space.
-.I buf
-がアクセス可能なアドレス空間の外にある。
-.TP
-.B EINTR
-.\"O The call was interrupted by a signal before any data was read; see
-.\"O .BR signal (7).
-何のデータも読み込まないうちにシグナルに割り込まれた。
-.BR signal (7)
-参照。
-.TP
-.B EINVAL
-.\"O .I fd
-.\"O is attached to an object which is unsuitable for reading;
-.\"O or the file was opened with the
-.\"O .B O_DIRECT
-.\"O flag, and either the address specified in
-.\"O .IR buf ,
-.\"O the value specified in
-.\"O .IR count ,
-.\"O or the current file offset is not suitably aligned.
-.I fd
-は読み込みに適していないオブジェクトを参照している。
-もしくは、ファイルが
-.B O_DIRECT
-フラグを指定してオープンされているが、
-.I buf
-に指定されたアドレス、
-.I count
-に指定された値、
-現在のファイルオフセットのいずれかの
-アラインメントが不適切である。
-.TP
-.B EINVAL
-.\"O .I fd
-.\"O was created via a call to
-.\"O .BR timerfd_create (2)
-.\"O and the wrong size buffer was given to
-.\"O .BR read ();
-.\"O see
-.\"O .BR timerfd_create (2)
-.\"O for further information.
-.I fd
-が
-.BR timerfd_create (2)
-の呼び出しで作成されたが、
-.BR read ()
-に間違ったサイズのバッファが渡された。
-さらなる情報は
-.BR timerfd_create (2)
-を参照のこと。
-.TP
-.B EIO
-.\"O I/O error.
-.\"O This will happen for example when the process is in a
-.\"O background process group, tries to read from its controlling tty,
-.\"O and either it is ignoring or blocking
-.\"O .B SIGTTIN
-.\"O or its process group
-.\"O is orphaned.
-.\"O It may also occur when there is a low-level I/O error
-.\"O while reading from a disk or tape.
-I/O エラー。これは例えばプロセスがバックグランド・プロセス・グループで、
-それを制御している tty から読み込もうとし、
-.B SIGTTIN
-が無視 (ignore) または禁止 (blocking) されている場合や、
-そのプロセス・グループが孤立 (orphan) している場合に起こる。
-またディスクやテープを読んでいる時に低レベル I/O エラー
-が発生した場合にも起こる。
-.TP
-.B EISDIR
-.\"O .I fd
-.\"O refers to a directory.
-.I fd
-がディレクトリを参照している。
+ファイルディスクリプタ \fIfd\fP がソケットを参照していて、非停止 (nonblocking) モード (\fBO_NONBLOCK\fP)
+に設定されており、読み込みを行うと停止する状況にある。 POSIX.1\-2001 は、この場合にどちらのエラーを返すことも認めており、 これら 2
+つの定数が同じ値を持つことも求めていない。 したがって、移植性が必要なアプリケーションでは、両方の可能性を 確認すべきである。
+.TP
+\fBEBADF\fP
+\fIfd\fP が有効なファイルディスクリプタでないか、読み込みのために オープン (open) されていない。
+.TP
+\fBEFAULT\fP
+\fIbuf\fP がアクセス可能なアドレス空間の外にある。
+.TP
+\fBEINTR\fP
+何のデータも読み込まないうちにシグナルに割り込まれた。 \fBsignal\fP(7) 参照。
+.TP
+\fBEINVAL\fP
+\fIfd\fP は読み込みに適していないオブジェクトを参照している。 もしくは、ファイルが \fBO_DIRECT\fP フラグを指定してオープンされているが、
+\fIbuf\fP に指定されたアドレス、 \fIcount\fP に指定された値、 現在のファイルオフセットのいずれかの アラインメントが不適切である。
+.TP
+\fBEINVAL\fP
+\fIfd\fP が \fBtimerfd_create\fP(2) の呼び出しで作成されたが、 \fBread\fP() に間違ったサイズのバッファが渡された。
+さらなる情報は \fBtimerfd_create\fP(2) を参照のこと。
+.TP
+\fBEIO\fP
+I/O エラー。これは例えばプロセスがバックグランド・プロセスグループで、それを制御している端末から読み込もうとし、 \fBSIGTTIN\fP が無視
+(ignore) または禁止 (blocking) されている場合や、 そのプロセスグループが孤立 (orphan) している場合に起こる。
+またディスクやテープを読んでいる時に低レベル I/O エラー が発生した場合にも起こる。
+.TP
+\fBEISDIR\fP
+\fIfd\fP がディレクトリを参照している。
.PP
-.\"O Other errors may occur, depending on the object connected to
-.\"O .IR fd .
-.I fd
-が接続しているオブジェクトによっては他のエラーも起こりえる。
-.\"O POSIX allows a
-.\"O .BR read ()
-.\"O that is interrupted after reading some data
-.\"O to return \-1 (with
-.\"O .I errno
-.\"O set to
-.\"O .BR EINTR )
-.\"O or to return the number of bytes already read.
-POSIX では、
-いくらかのデータを読んだ後に割り込みが起こった場合、
-.BR read ()
-は
-.RI ( errno
-に
-.B EINTR
-を設定して) \-1 を返してもよいし、
-既に読み込んだバイト数を返してもよい。
-.\"O .SH "CONFORMING TO"
+\fIfd\fP が接続しているオブジェクトによっては他のエラーも起こりえる。 POSIX では、 いくらかのデータを読んだ後に割り込みが起こった場合、
+\fBread\fP() は (\fIerrno\fP に \fBEINTR\fP を設定して) \-1 を返してもよいし、 既に読み込んだバイト数を返してもよい。
.SH 準拠
-SVr4, 4.3BSD, POSIX.1-2001.
-.\"O .SH NOTES
+SVr4, 4.3BSD, POSIX.1\-2001.
.SH 注意
-.\"O On NFS file systems, reading small amounts of data will only update the
-.\"O timestamp the first time, subsequent calls may not do so.
-.\"O This is caused
-.\"O by client side attribute caching, because most if not all NFS clients
-.\"O leave st_atime (last file access time)
-.\"O updates to the server and client side reads satisfied from the
-.\"O client's cache will not cause st_atime updates on the server as there are no
-.\"O server side reads.
-.\"O UNIX semantics can be obtained by disabling client
-.\"O side attribute caching, but in most situations this will substantially
-.\"O increase server load and decrease performance.
-NFS において。少量のデータを読み込む場合、最初の時のみにタイム
-スタンプが更新され、続くコールでは更新されないだろう。
-これはクライアント側で属性のキャッシングを行なうためである。
-なぜならば、もし全ての NFS クライアントが st_atime (最終ファイルアクセス時刻)
-の更新をサーバーに送らず、クライアント側でキャッシュを読むことに満足して
-いれば、サーバー側での read は発生しないので st_atime の更新は行なわれからだ。
-UNIX の方式では、クライアント側の属性のキャッシングを無効にすることで、
-これを得ることができる。しかしほとんどの状況ではこれは続くサーバーの
-負荷を増加させ、パフォーマンスの低下をもたらす。
-.PP
-.\"O Many file systems and disks were considered to be fast enough that the
-.\"O implementation of
-.\"O .B O_NONBLOCK
-.\"O was deemed unnecessary.
-.\"O So,
-.\"O .B O_NONBLOCK
-.\"O may not be available on files
-.\"O and/or disks.
-多くのファイルシステムやディスクは
-.B O_NONBLOCK
-の実装はしなくても済むくらいに十分に高速であると考えられている。
-それでそのようなファイルやディスクには
-.B O_NONBLOCK
-は利用できないかもしれない。
-.\"O .SH "SEE ALSO"
+NFS において。少量のデータを読み込む場合、最初の時のみにタイム スタンプが更新され、続くコールでは更新されないだろう。
+これはクライアント側で属性のキャッシングを行なうためである。 なぜならば、もし全ての NFS クライアントが st_atime
+(最終ファイルアクセス時刻) の更新をサーバーに送らず、クライアント側でキャッシュを読むことに満足して いれば、サーバー側での read
+は発生しないので st_atime の更新は行なわれからだ。 UNIX の方式では、クライアント側の属性のキャッシングを無効にすることで、
+これを得ることができる。しかしほとんどの状況ではこれは続くサーバーの 負荷を増加させ、パフォーマンスの低下をもたらす。
+.SH バグ
+According to POSIX.1\-2008/SUSv4 Section XSI 2.9.7 ("Thread Interactions with
+Regular File Operations"):
+
+.RS 4
+All of the following functions shall be atomic with respect to each other in
+the effects specified in POSIX.1\-2008 when they operate on regular files or
+symbolic links: ...
+.RE
+
+.\" http://thread.gmane.org/gmane.linux.kernel/1649458
+.\" From: Michael Kerrisk (man-pages <mtk.manpages <at> gmail.com>
+.\" Subject: Update of file offset on write() etc. is non-atomic with I/O
+.\" Date: 2014-02-17 15:41:37 GMT
+.\" Newsgroups: gmane.linux.kernel, gmane.linux.file-systems
+.\" commit 9c225f2655e36a470c4f58dbbc99244c5fc7f2d4
+.\" Author: Linus Torvalds <torvalds@linux-foundation.org>
+.\" Date: Mon Mar 3 09:36:58 2014 -0800
+.\"
+.\" vfs: atomic f_pos accesses as per POSIX
+Among the APIs subsequently listed are \fBread\fP() and \fBreadv\fP(2). And
+among the effects that should be atomic across threads (and processes) are
+updates of the file offset. However, on Linux before version 3.14, this was
+not the case: if two processes that share an open file description (see
+\fBopen\fP(2)) perform a \fBread\fP() (or \fBreadv\fP(2)) at the same time, then
+the I/O operations were not atomic with respect updating the file offset,
+with the result that the reads in the two processes might (incorrectly)
+overlap in the blocks of data that they obtained. This problem was fixed in
+Linux 3.14.
.SH 関連項目
-.BR close (2),
-.BR fcntl (2),
-.BR ioctl (2),
-.BR lseek (2),
-.BR open (2),
-.BR pread (2),
-.BR readdir (2),
-.BR readlink (2),
-.BR readv (2),
-.BR select (2),
-.BR write (2),
-.BR fread (3)
+\fBclose\fP(2), \fBfcntl\fP(2), \fBioctl\fP(2), \fBlseek\fP(2), \fBopen\fP(2), \fBpread\fP(2),
+\fBreaddir\fP(2), \fBreadlink\fP(2), \fBreadv\fP(2), \fBselect\fP(2), \fBwrite\fP(2),
+\fBfread\fP(3)
+.SH この文書について
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.67 の一部
+である。プロジェクトの説明とバグ報告に関する情報は
+http://www.kernel.org/doc/man\-pages/ に書かれている。