.\" Updated 2013-05-06, Akihiro MOTOKI <amotoki@gmail.com>
.\" Updated 2013-08-16, Akihiro MOTOKI <amotoki@gmail.com>
.\"
-.TH OPEN 2 2013\-07\-21 Linux "Linux Programmer's Manual"
+.TH OPEN 2 2013\-08\-09 Linux "Linux Programmer's Manual"
.SH 名前
open, creat \- ファイルやデバイスのオープン、作成を行う
.SH 書式
.\" For more background, see
.\" http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=453946
.\" http://nfs.sourceforge.net/
-ファイルを追加 (append) モードでオープンする。 毎回の \fBwrite\fP(2) の前に \fBlseek\fP(2)
-を行ったかのように、ファイルポインタをファイルの最後に移動する。 NFS ファイルシステムで、 \fBO_APPEND\fP
-を使用すると、複数のプロセスがひとつのファイルに同時にデータを追加した場合、 ファイルが壊れてしまうことがある。 これは NFS
-が追加モードをサポートしていないため、 クライアントのカーネル (kernel) がそれをシミュレートしなければならないのだが、
-競合状態を避けることはできないからである。
+The file is opened in append mode. Before each \fBwrite\fP(2), the file offset
+is positioned at the end of the file, as if with \fBlseek\fP(2). \fBO_APPEND\fP
+may lead to corrupted files on NFS filesystems if more than one process
+appends data to a file at once. This is because NFS does not support
+appending to a file, so the client kernel has to simulate it, which can't be
+done without a race condition.
.TP
\fBO_ASYNC\fP
シグナル駆動 I/O (signal\-driven I/O) を有効にする: このファイルディスクリプタへの
\fBO_CREAT\fP
.\" As at 2.6.25, bsdgroups is supported by ext2, ext3, ext4, and
.\" XFS (since 2.6.14).
-ファイルが存在しなかった場合は作成 (create) する。 ファイルの所有者 (ユーザー ID) は、プロセスの実効ユーザー ID に設定される。
-グループ所有権 (グループ ID) は、プロセスの実効グループ ID または親ディレクトリのグループ ID に設定される
-(これは、ファイルシステムタイプ、マウントオプション、 親ディレクトリのモードに依存する。 \fBmount\fP(8) で説明されているマウントオプション
-\fIbsdgroups\fP と \fIsysvgroups\fP を参照)。
+If the file does not exist it will be created. The owner (user ID) of the
+file is set to the effective user ID of the process. The group ownership
+(group ID) is set either to the effective group ID of the process or to the
+group ID of the parent directory (depending on filesystem type and mount
+options, and the mode of the parent directory, see the mount options
+\fIbsdgroups\fP and \fIsysvgroups\fP described in \fBmount\fP(8)).
.RS
.PP
\fImode\fP は新しいファイルを作成する場合に使用するアクセス許可 (permission) を指定する。 \fIflags\fP に \fBO_CREAT\fP
システムがそのブロックデバイスを使用中の場合 (例えば、
マウントされているなど)、 \fBopen\fP() はエラー \fBEBUSY\fP で失敗する。
-NFS では、 \fBO_EXCL\fP は、Linux 2.6 以降で NFSv3 以降を使っている場合でのみサポートされる。 \fBO_EXCL\fP
-サポートが提供されていない NFS 環境では、このフラグに頼って ロック処理を実行するプログラムは競合状態 (race condition) に出会う
-可能性がある。 ロックファイルを使用して不可分 (atomic) なファイルロックを実現し、 NFS が \fBO_EXCL\fP
-をサポートしているかに依存しないようにしたい場合、 移植性のある方法は、同じファイルシステム上に他と名前の重ならない ファイル (例えばホスト名と
-PID を組み合わせた名前) を作成し、 \fBlink\fP(2) を使用してそのロックファイルへのリンクを作成することである。 \fBlink\fP(2)
-コールの返り値が 0 ならばロックに成功している。 あるいは、そのファイルに \fBstat\fP(2) を使用してリンク数 (link count) が
-2 になっているかをチェックする。 そうなっていれば、同じくロックに成功しているということである。
+On NFS, \fBO_EXCL\fP is supported only when using NFSv3 or later on kernel 2.6
+or later. In NFS environments where \fBO_EXCL\fP support is not provided,
+programs that rely on it for performing locking tasks will contain a race
+condition. Portable programs that want to perform atomic file locking using
+a lockfile, and need to avoid reliance on NFS support for \fBO_EXCL\fP, can
+create a unique file on the same filesystem (e.g., incorporating hostname
+and PID), and use \fBlink\fP(2) to make a link to the lockfile. If \fBlink\fP(2)
+returns 0, the lock is successful. Otherwise, use \fBstat\fP(2) on the unique
+file to check if its link count has increased to 2, in which case the lock
+is also successful.
.TP
\fBO_LARGEFILE\fP
(LFS) \fIoff_t\fP ではサイズを表せない (だだし \fIoff64_t\fP ではサイズを表せる)ファ
\fBO_NOATIME\fP (Linux 2.6.8 以降)
.\" The O_NOATIME flag also affects the treatment of st_atime
.\" by mmap() and readdir(2), MTK, Dec 04.
-ファイルに対して \fBread\fP(2) が実行されたときに、最終アクセス時刻 (inode の \fIst_atime\fP) を更新しない。
-このフラグはインデックス作成やバックアッププログラムで使うことを意図している。 これを使うとディスクに対する操作を大幅に減らすことができる。
-このフラグは全てのファイルシステムに対して有効であるわけではない。 その一例が NFS であり、サーバがアクセス時刻を管理している。
+Do not update the file last access time (\fIst_atime\fP in the inode) when the
+file is \fBread\fP(2). This flag is intended for use by indexing or backup
+programs, where its use can significantly reduce the amount of disk
+activity. This flag may not be effective on all filesystems. One example
+is NFS, where the server maintains the access time.
.TP
\fBO_NOCTTY\fP
\fIpathname\fP が端末 (terminal) デバイス \(em \fBtty\fP(4) 参照 \(em を指している
.\" Newsgroups: gmane.linux.man, gmane.linux.kernel
.\"
Obtain a file descriptor that can be used for two purposes: to indicate a
-location in the file\-system tree and to perform operations that act purely
-at the file descriptor level. The file itself is not opened, and other file
+location in the filesystem tree and to perform operations that act purely at
+the file descriptor level. The file itself is not opened, and other file
operations (e.g., \fBread\fP(2), \fBwrite\fP(2), \fBfchmod\fP(2), \fBfchown\fP(2),
-\fBfgetxattr\fP(2)) fail with the error \fBEBADF\fP.
+\fBfgetxattr\fP(2), \fBmmap\fP(2)) fail with the error \fBEBADF\fP.
The following operations \fIcan\fP be performed on the resulting file
descriptor:
またはファイルが存在せず、親ディレクトリへの書き込み許可がなかった。 (\fBpath_resolution\fP(7) も参照すること。)
.TP
\fBEDQUOT\fP
-\fBO_CREAT\fP が指定された場合で、そのファイルが存在せず、ディスクブロックか inode がそのファイルシステムのユーザクォータに達していた。
+Where \fBO_CREAT\fP is specified, the file does not exist, and the user's quota
+of disk blocks or inodes on the filesystem has been exhausted.
.TP
\fBEEXIST\fP
\fIpathname\fP は既に存在し、 \fBO_CREAT\fP と \fBO_EXCL\fP が使用された。
遅いデバイス (例えば FIFO、 \fBfifo\fP(7) 参照) のオープンが完了するのを待って停止している間に
システムコールがシグナルハンドラにより割り込まれた。 \fBsignal\fP(7) 参照。
.TP
+\fBEINVAL\fP
+The filesystem does not support the \fBO_DIRECT\fP flag. See \fBNOTES\fP for more
+information.
+.TP
\fBEISDIR\fP
\fIpathname\fP はディレクトリを参照しており、書き込み要求が含まれていた (つまり \fBO_WRONLY\fP または \fBO_RDWR\fP
が設定されている)。
を返していた。
.TP
\fBEPERM\fP
-.\" Strictly speaking, it's the file system UID... (MTK)
+.\" Strictly speaking, it's the filesystem UID... (MTK)
\fBO_NOATIME\fP フラグが指定されたが、呼び出し元の実効ユーザー ID が ファイルの所有者と一致せず、かつ呼び出し元に特権
(\fBCAP_FOWNER\fP) がない。
.TP
\fBEROFS\fP
-\fIpathname\fP が読み込み専用のファイルシステム上のファイルを参照しており、 書き込みアクセスが要求された。
+\fIpathname\fP refers to a file on a read\-only filesystem and write access was
+requested.
.TP
\fBETXTBSY\fP
\fIpathname\fP が現在実行中の実行イメージを参照しており、書き込みが要求された。
.PP
NFS を実現しているプロトコルには多くの不備があり、特に \fBO_SYNC\fP と \fBO_NDELAY\fP に影響する。
-POSIX では、3 種類の同期 I/O が提供されており、 \fBO_SYNC\fP, \fBO_DSYNC\fP, \fBO_RSYNC\fP
-フラグがこれに対応するものである。 今のところ (カーネル 2.6.31)、 Linux では \fBO_SYNC\fP だけが実装されているが、 glibc
-は \fBO_DSYNC\fP と \fBO_RSYNC\fP に \fBO_SYNC\fP と同じ数値を割り当てている。 ほとんどの Linux
-のファイルシステムは、実際には POSIX の \fBO_SYNC\fP の動作ではなく \fBO_DSYNC\fP の動作だけを実装している。 POSIX の
-\fBO_SYNC\fP では、 \fBopen\fP() がユーザ空間に返る際に、書き込みに関する全てのメタデータの
-更新がディスクに書き込まれている必要がある。 一方、 \fBO_DSYNC\fP では、 \fBopen\fP()
-が返るまでに、実際のファイルのデータとそのデータを取得するために 必要なメタデータだけがディスクに書き込まれていればよい。
+POSIX provides for three different variants of synchronized I/O,
+corresponding to the flags \fBO_SYNC\fP, \fBO_DSYNC\fP, and \fBO_RSYNC\fP. Currently
+(2.6.31), Linux implements only \fBO_SYNC\fP, but glibc maps \fBO_DSYNC\fP and
+\fBO_RSYNC\fP to the same numerical value as \fBO_SYNC\fP. Most Linux filesystems
+don't actually implement the POSIX \fBO_SYNC\fP semantics, which require all
+metadata updates of a write to be on disk on returning to user space, but
+only the \fBO_DSYNC\fP semantics, which require only actual file data and
+metadata necessary to retrieve it to be on disk by the time the system call
+returns.
\fBopen\fP() はスペシャルファイルをオープンすることができるが、 \fBcreat\fP() でスペシャルファイルを作成できない点に注意すること。
代わりに \fBmknod\fP(2) を使用する。
.LP
-UID マッピングを使用している NFS ファイルシステムでは、 \fBopen\fP() がファイルディスクリプタを返した場合でも \fBread\fP(2)
-が \fBEACCES\fP で拒否される場合がある。 これはクライアントがアクセス許可のチェックを行って \fBopen\fP()
-を実行するが、読み込みや書き込みの際には サーバーで UID マッピングが行われるためである。
+On NFS filesystems with UID mapping enabled, \fBopen\fP() may return a file
+descriptor but, for example, \fBread\fP(2) requests are denied with
+\fBEACCES\fP. This is because the client performs \fBopen\fP() by checking the
+permissions, but UID mapping is performed by the server upon read and write
+requests.
ファイルが新しく作成されると、 ファイルの \fIst_atime\fP, \fIst_ctime\fP, \fIst_mtime\fP フィールド
(それぞれ最終アクセス時刻、最終状態変更時刻、最終修正時刻である。 \fBstat\fP(2) 参照) が現在時刻に設定される。 さらに親ディレクトリの
ファイルの \fIst_ctime\fP と \fIst_mtime\fP フィールドが現在時刻に設定される。
.SS O_DIRECT
.LP
-\fBO_DIRECT\fP フラグを使用する場合、ユーザ空間バッファの長さやアドレス、 I/O
-のファイルオフセットに関してアラインメントの制限が課されることがある。 Linux では、アラインメントの制限はファイルシステムやカーネルのバージョンに
-よって異なり、全く制限が存在しない場合もある。 しかしながら、現在のところ、指定されたファイルやファイルシステムに対して
-こうした制限があるかを見つけるための、アプリケーション向けのインタフェースで ファイルシステム非依存のものは存在しない。
-いくつかのファイルシステムでは、制限を確認するための独自のインタフェースが 提供されている。例えば、 \fBxfsctl\fP(3) の
-\fBXFS_IOC_DIOINFO\fP 命令である。
+The \fBO_DIRECT\fP flag may impose alignment restrictions on the length and
+address of user\-space buffers and the file offset of I/Os. In Linux
+alignment restrictions vary by filesystem and kernel version and might be
+absent entirely. However there is currently no filesystem\-independent
+interface for an application to discover these restrictions for a given file
+or filesystem. Some filesystems provide their own interfaces for doing so,
+for example the \fBXFS_IOC_DIOINFO\fP operation in \fBxfsctl\fP(3).
.LP
-Linux 2.4 では、転送サイズ、 ユーザーバッファのアラインメント、ファイルオフセットは、
-ファイルシステムの論理ブロックサイズの倍数でなければならない。 Linux 2.6 では、512 バイトごとの境界に配置されていれば充分である。
+Under Linux 2.4, transfer sizes, and the alignment of the user buffer and
+the file offset must all be multiples of the logical block size of the
+filesystem. Under Linux 2.6, alignment to 512\-byte boundaries suffices.
.LP
メモリバッファがプライベートマッピング (\fBmmap\fP(2) の \fBMAP_PRIVATE\fP
フラグで作成されたマッピング) の場合には、\fBO_DIRECT\fP I/O は
アラインメントの制限がある。 また、IRIX には適切な配置とサイズを取得するための \fBfcntl\fP(2) コールがある。 FreeBSD 4.x
も同じ名前のフラグを導入したが、アラインメントの制限はない。
.LP
-\fBO_DIRECT\fP が Linux でサポートされたのは、カーネルバージョン 2.4.10 である。 古い Linux
-カーネルは、このフラグを単に無視する。 \fBO_DIRECT\fP フラグをサポートしていないファイルシステムもあり、その場合は、 \fBO_DIRECT\fP
-を使用すると \fBopen\fP() は \fBEINVAL\fP で失敗する。
+\fBO_DIRECT\fP support was added under Linux in kernel version 2.4.10. Older
+Linux kernels simply ignore this flag. Some filesystems may not implement
+the flag and \fBopen\fP() will fail with \fBEINVAL\fP if it is used.
.LP
-アプリケーションは、同じファイル、 特に同じファイルの重複するバイト領域に対して、 \fBO_DIRECT\fP と通常の I/O
-を混ぜて使うのは避けるべきである。 ファイルシステムがこのような状況において一貫性の問題を正しく 扱うことができる場合であっても、全体の I/O
-スループットは どちらか一方を使用するときと比べて低速になるであろう。 同様に、アプリケーションは、同じファイルに対して \fBmmap\fP(2) と直接
-I/O (\fBO_DIRECT\fP) を混ぜて使うのも避けるべきである。
+Applications should avoid mixing \fBO_DIRECT\fP and normal I/O to the same
+file, and especially to overlapping byte regions in the same file. Even
+when the filesystem correctly handles the coherency issues in this
+situation, overall I/O throughput is likely to be slower than using either
+mode alone. Likewise, applications should avoid mixing \fBmmap\fP(2) of files
+with direct I/O to the same files.
.LP
-NFS で \fBO_DIRECT\fP を使った場合の動作はローカルのファイルシステムの場合と違う。
-古いカーネルや、ある種の設定でコンパイルされたカーネルは、 \fBO_DIRECT\fP と NFS の組み合わせをサポートしていないかもしれない。 NFS
-プロトコル自体はサーバにフラグを渡す機能は持っていないので、 \fBO_DIRECT\fP I/O
-はクライアント上のページキャッシュをバイパスするだけになり、 サーバは I/O をキャッシュしているかもしれない。 クライアントは、
-\fBO_DIRECT\fP の同期機構を保持するため、サーバに対して I/O を同期して行うように依頼する。 サーバによっては、こうした状況下、特に I/O
-サイズが小さい場合に 性能が大きく劣化する。 また、サーバによっては、I/O が安定したストレージにまで行われたと、
-クライアントに対して嘘をつくものもある。 これは、サーバの電源故障が起こった際にデータの完全性が保たれない
-危険は少しあるが、性能面での不利な条件を回避するために行われている。 Linux の NFS クライアントでは \fBO_DIRECT\fP I/O
-でのアラインメントの制限はない。
+The behaviour of \fBO_DIRECT\fP with NFS will differ from local filesystems.
+Older kernels, or kernels configured in certain ways, may not support this
+combination. The NFS protocol does not support passing the flag to the
+server, so \fBO_DIRECT\fP I/O will bypass the page cache only on the client;
+the server may still cache the I/O. The client asks the server to make the
+I/O synchronous to preserve the synchronous semantics of \fBO_DIRECT\fP. Some
+servers will perform poorly under these circumstances, especially if the I/O
+size is small. Some servers may also be configured to lie to clients about
+the I/O having reached stable storage; this will avoid the performance
+penalty at some risk to data integrity in the event of server power
+failure. The Linux NFS client places no alignment restrictions on
+\fBO_DIRECT\fP I/O.
.PP
まとめると、 \fBO_DIRECT\fP は、注意して使うべきであるが、強力なツールとなる可能性を持っている。 アプリケーションは \fBO_DIRECT\fP
をデフォルトでは無効になっている性能向上のためのオプションと 考えておくのがよいであろう。
\fBsocket\fP(2), \fBstat\fP(2), \fBumask\fP(2), \fBunlink\fP(2), \fBwrite\fP(2),
\fBfopen\fP(3), \fBfifo\fP(7), \fBpath_resolution\fP(7), \fBsymlink\fP(7)
.SH この文書について
-この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.54 の一部
である。プロジェクトの説明とバグ報告に関する情報は
http://www.kernel.org/doc/man\-pages/ に書かれている。