OSDN Git Service

282f577f320c2f081d9e436504da1087c67631e4
[linuxjm/LDP_man-pages.git] / draft / man2 / open.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\"                               1993 Michael Haardt, Ian Jackson.
5 .\"                               2008 Greg Banks
6 .\"
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
10 .\"
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
15 .\"
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein.  The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
22 .\" professionally.
23 .\"
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
26 .\"
27 .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1994-08-21 by Michael Haardt
29 .\" Modified 1996-04-13 by Andries Brouwer <aeb@cwi.nl>
30 .\" Modified 1996-05-13 by Thomas Koenig
31 .\" Modified 1996-12-20 by Michael Haardt
32 .\" Modified 1999-02-19 by Andries Brouwer <aeb@cwi.nl>
33 .\" Modified 1998-11-28 by Joseph S. Myers <jsm28@hermes.cam.ac.uk>
34 .\" Modified 1999-06-03 by Michael Haardt
35 .\" Modified 2002-05-07 by Michael Kerrisk <mtk.manpages@gmail.com>
36 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
37 .\" 2004-12-08, mtk, reordered flags list alphabetically
38 .\" 2004-12-08, Martin Pool <mbp@sourcefrog.net> (& mtk), added O_NOATIME
39 .\" 2007-09-18, mtk, Added description of O_CLOEXEC + other minor edits
40 .\" 2008-01-03, mtk, with input from Trond Myklebust
41 .\"     <trond.myklebust@fys.uio.no> and Timo Sirainen <tss@iki.fi>
42 .\"     Rewrite description of O_EXCL.
43 .\" 2008-01-11, Greg Banks <gnb@melbourne.sgi.com>: add more detail
44 .\"     on O_DIRECT.
45 .\" 2008-02-26, Michael Haardt: Reorganized text for O_CREAT and mode
46 .\"
47 .\" FIXME . Apr 08: The next POSIX revision has O_EXEC, O_SEARCH, and
48 .\" O_TTYINIT.  Eventually these may need to be documented.  --mtk
49 .\" FIXME Linux 2.6.33 has O_DSYNC, and a hidden __O_SYNC.
50 .\"
51 .\" Japanese Version Copyright (c) 1997-1999 HANATAKA Shinya
52 .\"         all rights reserved.
53 .\" Translated 1999-08-14, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
54 .\" Updated 2001-05-25, Yuichi SATO <ysato444@yahoo.co.jp>
55 .\" Updated & Modified 2002-01-02, Yuichi SATO
56 .\" Updated & Modified 2002-07-07, Yuichi SATO
57 .\" Updated & Modified 2002-09-19, Yuichi SATO
58 .\" Updated & Modified 2003-07-30, Yuichi SATO
59 .\" Updated & Modified 2003-11-27, Yuichi SATO
60 .\" Updated & Modified 2005-01-01, Yuichi SATO
61 .\" Updated & Modified 2005-09-14, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
62 .\" Updated & Modified 2005-10-14, Akihiro MOTOKI
63 .\" Updated & Modified 2006-01-18, Akihiro MOTOKI
64 .\" Updated & Modified 2006-04-15, Akihiro MOTOKI, LDP v2.29
65 .\" Updated 2007-01-07, Akihiro MOTOKI, LDP v2.43
66 .\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46
67 .\" Updated 2007-10-12, Akihiro MOTOKI, LDP v2.66
68 .\" Updated 2008-02-12, Akihiro MOTOKI, LDP v2.77
69 .\" Updated 2008-04-04, Akihiro MOTOKI, LDP v2.79
70 .\" Updated 2008-08-08, Akihiro MOTOKI, LDP v3.05
71 .\" Updated 2010-04-23, Akihiro MOTOKI, LDP v3.24
72 .\"
73 .\"WORD:        descriptor              ディスクリプタ
74 .\"WORD:        file description        ファイル記述
75 .\"WORD:        open                    オープン
76 .\"WORD:        create                  作成
77 .\"WORD:        file offset             ファイル・オフセット
78 .\"WORD:        controling terminal     制御端末
79 .\"WORD:        non-blocking I/O        非停止 I/O
80 .\"WORD:        synchronous I/O         同期 I/O
81 .\"WORD:        permission              許可
82 .\"WORD:        user                    ユーザー
83 .\"WORD:        owner                   所有者
84 .\"WORD:        group                   グループ
85 .\"WORD:        other                   他人
86 .\"WORD:        kernel                  カーネル
87 .\"WORD:        symbolic link           シンボリック・リンク
88 .\"WORD:        dangling symbolic link  壊れたシンボリック・リンク
89 .\"WORD:        file creation flag      ファイル作成フラグ
90 .\"WORD:        file status flag        ファイル状態フラグ
91 .\"
92 .TH OPEN 2 2010-09-10 "Linux" "Linux Programmer's Manual"
93 .\"O .SH NAME
94 .SH 名前
95 .\"O open, creat \- open and possibly create a file or device
96 open, creat \- ファイルやデバイスのオープン、作成を行う
97 .\"O .SH SYNOPSIS
98 .SH 書式
99 .nf
100 .B #include <sys/types.h>
101 .B #include <sys/stat.h>
102 .B #include <fcntl.h>
103 .sp
104 .BI "int open(const char *" pathname ", int " flags );
105 .BI "int open(const char *" pathname ", int " flags ", mode_t " mode );
106
107 .BI "int creat(const char *" pathname ", mode_t " mode );
108 .fi
109 .\"O .SH DESCRIPTION
110 .SH 説明
111 .\"O Given a
112 .\"O .I pathname
113 .\"O for a file,
114 .\"O .BR open ()
115 .\"O returns a file descriptor, a small, nonnegative integer
116 .\"O for use in subsequent system calls
117 .\"O .RB ( read "(2), " write "(2), " lseek "(2), " fcntl "(2), etc.)."
118 .\"O The file descriptor returned by a successful call will be
119 .\"O the lowest-numbered file descriptor not currently open for the process.
120 ファイルの
121 .I pathname
122 を与えると、
123 .BR open ()
124 はファイル・ディスクリプタを返す。
125 ファイル・ディスクリプタは、この後に続くシステムコール
126 .RB ( read "(2), " write "(2), " lseek "(2), " fcntl "(2) など)"
127 で使用される小さな非負の整数である。
128 このシステムコールが成功した場合に返されるファイル・ディスクリプタは
129 そのプロセスがその時点でオープンしていないファイル・ディスクリプタの
130 うち最小の数字のものとなる。
131 .PP
132 .\"O By default, the new file descriptor is set to remain open across an
133 .\"O .BR execve (2)
134 .\"O (i.e., the
135 .\"O .B FD_CLOEXEC
136 .\"O file descriptor flag described in
137 .\"O .BR fcntl (2)
138 .\"O is initially disabled; the Linux-specific
139 .\"O .B O_CLOEXEC
140 .\"O flag, described below, can be used to change this default).
141 .\"O The file offset is set to the beginning of the file (see
142 .\"O .BR lseek (2)).
143 デフォルトでは、新しいファイル・ディスクリプタは
144 .BR execve (2)
145 を実行した後もオープンされたままとなる (つまり、
146 .BR fcntl (2)
147 に説明がある
148 .B FD_CLOEXEC
149 ファイル・ディスクリプタ・フラグは最初は無効である;
150 後述の Linux 固有のフラグ
151 .B O_CLOEXEC
152 を使うとこのデフォルトを変更することができる)。
153 ファイル・オフセット (file offset) はファイルの先頭に設定される
154 .RB ( lseek (2)
155 参照)。
156 .PP
157 .\"O A call to
158 .\"O .BR open ()
159 .\"O creates a new
160 .\"O .IR "open file description" ,
161 .\"O an entry in the system-wide table of open files.
162 .BR open ()
163 を呼び出すと、「オープンファイル記述」
164 .I "(open file description)"
165 が作成される。ファイル記述とは、システム全体の
166 オープン中のファイルのテーブルのエントリである。
167 .\"O This entry records the file offset and the file status flags
168 .\"O (modifiable via the
169 .\"O .BR fcntl (2)
170 .\"O .B F_SETFL
171 .\"O operation).
172 .\"O A file descriptor is a reference to one of these entries;
173 .\"O this reference is unaffected if
174 .\"O .I pathname
175 .\"O is subsequently removed or modified to refer to a different file.
176 このエントリは、ファイル・オフセットとファイル状態フラグ
177 .RB ( fcntl (2)
178 .B F_SETFL
179 操作により変更可能) が保持する。
180 ファイル・ディスクリプタはこれらのエントリの一つへの参照である。
181 この後で
182 .I pathname
183 が削除されたり、他のファイルを参照するように変更されたりしても、
184 この参照は影響を受けない。
185 .\"O The new open file description is initially not shared
186 .\"O with any other process,
187 .\"O but sharing may arise via
188 .\"O .BR fork (2).
189 新しいオープンファイル記述は最初は他のどのプロセスとも
190 共有されていないが、
191 .BR fork (2)
192 で共有が起こる場合がある。
193 .PP
194 .\"O The argument
195 .\"O .I flags
196 .\"O must include one of the following
197 .\"O .IR "access modes" :
198 .\"O .BR O_RDONLY ", " O_WRONLY ", or " O_RDWR .
199 .\"O These request opening the file read-only, write-only, or read/write,
200 .\"O respectively.
201 引き数
202 .I flags
203 には、アクセスモード
204 .BR O_RDONLY ", " O_WRONLY ", " O_RDWR
205 のどれかひとつが入っていなければならない。
206 これらはそれぞれ読み込み専用、書き込み専用、読み書き用に
207 ファイルをオープンすることを要求するものである。
208
209 .\"O In addition, zero or more file creation flags and file status flags
210 .\"O can be
211 .\"O .RI bitwise- or 'd
212 .\"O in
213 .\"O .IR flags .
214 さらに、
215 .I flags
216 には、ファイル作成フラグ (file creation flag) とファイル状態フラグ
217 (file status flag) を 0 個以上「ビット単位の OR (bitwise-or)」で
218 指定することができる。
219 .\"O The
220 .\"O .I file creation flags
221 .\"O are
222 .\"O .BR O_CREAT ", " O_EXCL ", " O_NOCTTY ", and " O_TRUNC .
223 .\"O The
224 .\"O .I file status flags
225 .\"O are all of the remaining flags listed below.
226 .I ファイル作成フラグ
227
228 .BR O_CREAT ", " O_EXCL ", " O_NOCTTY ", " O_TRUNC
229 である。
230 .I ファイル状態フラグ
231 は以下のリストのうち上記以外の残りのものである。
232 .\" FIXME . Actually is it true that the "file status flags" are all of the
233 .\" remaining flags listed below?  SUSv4 divides the flags into:
234 .\" * Access mode
235 .\" * File creation
236 .\" * File status
237 .\" * Other (O_CLOEXEC, O_DIRECTORY, O_NOFOLLOW)
238 .\" though it's not clear what the difference between "other" and
239 .\" "File creation" flags is.  (I've raised an Aardvark to see if this
240 .\" can be clarified in SUSv4; 10 Oct 2008.)
241 .\"O The distinction between these two groups of flags is that
242 .\"O the file status flags can be retrieved and (in some cases)
243 .\"O modified using
244 .\"O .BR fcntl (2).
245 .\"O The full list of file creation flags and file status flags is as follows:
246 二種類のフラグの違いは、ファイル状態フラグの方は
247 .BR fcntl (2)
248 を使ってその内容を取得したり (場合によっては) 変更したりできる点にある。
249 ファイル作成フラグとファイル状態フラグの全リストを以下に示す:
250 .TP
251 .B O_APPEND
252 .\"O The file is opened in append mode.
253 .\"O Before each
254 .\"O .BR write (2),
255 .\"O the file offset is positioned at the end of the file,
256 .\"O as if with
257 .\"O .BR lseek (2).
258 ファイルを追加 (append) モードでオープンする。
259 毎回の
260 .BR write (2)
261 の前に
262 .BR lseek (2)
263 を行ったかのように、ファイル・ポインターをファイルの最後に移動する。
264 .\"O .B O_APPEND
265 .\"O may lead to corrupted files on NFS file systems if more than one process
266 .\"O appends data to a file at once.
267 .\" For more background, see
268 .\" http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=453946
269 .\" http://nfs.sourceforge.net/
270 .\"O This is because NFS does not support
271 .\"O appending to a file, so the client kernel has to simulate it, which
272 .\"O can't be done without a race condition.
273 NFS ファイル・システムで、
274 .B O_APPEND
275 を使用すると、複数のプロセスがひとつのファイルに同時にデータを追加した場合、
276 ファイルが壊れてしまうことがある。
277 これは NFS が追加モードをサポートしていないため、
278 クライアントのカーネル (kernel) がそれをシミュレートしなければならないのだが、
279 競合状態を避けることはできないからである。
280 .TP
281 .B O_ASYNC
282 .\"O Enable signal-driven I/O:
283 .\"O generate a signal
284 .\"O .RB ( SIGIO
285 .\"O by default, but this can be changed via
286 .\"O .BR fcntl (2))
287 .\"O when input or output becomes possible on this file descriptor.
288 シグナル駆動 I/O (signal-driven I/O) を有効にする:
289 このファイル・ディスクリプタへの
290 入力または出力が可能になった場合に、シグナルを生成する
291 (デフォルトは
292 .B SIGIO
293 であるが、
294 .BR fcntl (2)
295 によって変更可能である)。
296 .\"O This feature is only available for terminals, pseudoterminals,
297 .\"O sockets, and (since Linux 2.6) pipes and FIFOs.
298 .\"O See
299 .\"O .BR fcntl (2)
300 .\"O for further details.
301 この機能が使用可能なのは端末、疑似端末、ソケットのみであり、
302 (Linux 2.6 以降では) パイプと FIFO に対しても使用できる。
303 さらに詳しい説明は
304 .BR fcntl (2)
305 を参照すること。
306 .TP
307 .\"O .BR O_CLOEXEC " (Since Linux 2.6.23)"
308 .BR O_CLOEXEC " (Linux 2.6.23 以降)"
309 .\"O Enable the close-on-exec flag for the new file descriptor.
310 新しいファイル・ディスクリプタに対して close-on-exec フラグを有効にする。
311 .\"O Specifying this flag permits a program to avoid additional
312 .\"O .BR fcntl (2)
313 .\"O .B F_SETFD
314 .\"O operations to set the
315 .\"O .B FD_CLOEXEC
316 .\"O flag.
317 このフラグを指定することで、プログラムは
318 .B FD_CLOEXEC
319 フラグをセットするための
320 .BR fcntl (2)
321 .B F_SETFD
322 操作を別途呼び出す必要がなくなる。
323 .\"O Additionally,
324 .\"O use of this flag is essential in some multithreaded programs
325 .\"O since using a separate
326 .\"O .BR fcntl (2)
327 .\"O .B F_SETFD
328 .\"O operation to set the
329 .\"O .B FD_CLOEXEC
330 .\"O flag does not suffice to avoid race conditions
331 .\"O where one thread opens a file descriptor at the same
332 .\"O time as another thread does a
333 .\"O .BR fork (2)
334 .\"O plus
335 .\"O .BR execve (2).
336 また、ある種のマルチスレッドのプログラムはこのフラグの使用は
337 不可欠である。なぜなら、個別に
338 .B FD_CLOEXEC
339 フラグを設定する
340 .BR fcntl (2)
341 .B F_SETFD
342 操作を呼び出したとしても、あるスレッドがファイルディスクリプタを
343 オープンするのと同時に別のスレッドが
344 .BR fork (2)
345
346 .BR execve (2)
347 を実行するという競合条件を避けるのには十分ではないからである。
348 .\" This flag fixes only one form of the race condition;
349 .\" The race can also occur with, for example, descriptors
350 .\" returned by accept(), pipe(), etc.
351 .TP
352 .B O_CREAT
353 .\"O If the file does not exist it will be created.
354 ファイルが存在しなかった場合は作成 (create) する。
355 .\"O The owner (user ID) of the file is set to the effective user ID
356 .\"O of the process.
357 .\"O The group ownership (group ID) is set either to
358 .\"O the effective group ID of the process or to the group ID of the
359 .\"O parent directory (depending on file system type and mount options,
360 .\"O and the mode of the parent directory, see the mount options
361 .\"O .I bsdgroups
362 .\"O and
363 .\"O .I sysvgroups
364 .\"O described in
365 .\"O .BR mount (8)).
366 .\"O .\" As at 2.6.25, bsdgroups is supported by ext2, ext3, ext4, and
367 .\"O .\" XFS (since 2.6.14).
368 ファイルの所有者 (ユーザー ID) は、プロセスの実効ユーザー ID に設定される。
369 グループ所有権 (グループ ID) は、プロセスの実効グループ ID
370 または親ディレクトリのグループ ID に設定される
371 (これは、ファイルシステムタイプ、マウントオプション、
372 親ディレクトリのモードに依存する。
373 .BR mount (8)
374 で説明されているマウントオプション
375 .I bsdgroups
376
377 .I sysvgroups
378 を参照)。
379 .\" 2.6.25 時点では、bsdgroups は ext2, ext3, ext4, XFS でサポート
380 .\" されている (2.6.14 以降)。
381 .RS
382 .PP
383 .\"O .I mode
384 .\"O specifies the permissions to use in case a new file is created.
385 .\"O This argument must be supplied when
386 .\"O .B O_CREAT
387 .\"O is specified in
388 .\"O .IR flags ;
389 .\"O if
390 .\"O .B O_CREAT
391 .\"O is not specified, then
392 .\"O .I mode
393 .\"O is ignored.
394 .\"O The effective permissions are modified by
395 .\"O the process's
396 .\"O .I umask
397 .\"O in the usual way: The permissions of the created file are
398 .\"O .IR "(mode\ &\ ~umask)" .
399 .I mode
400 は新しいファイルを作成する場合に使用するアクセス許可 (permission) を指定する。
401 .I flags
402
403 .B O_CREAT
404 が指定されている場合、
405 .I mode
406 を指定しなければならない。
407 .B O_CREAT
408 が指定されていない場合、
409 .I mode
410 は無視される。
411 有効なアクセス許可は、普段と同じようにプロセスの
412 .I umask
413 によって修正され、作成されたファイルの許可は
414 .I "(mode\ &\ ~umask)"
415 となる。
416 .\"O Note that this mode only applies to future accesses of the
417 .\"O newly created file; the
418 .\"O .BR open ()
419 .\"O call that creates a read-only file may well return a read/write
420 .\"O file descriptor.
421 このモードは、新しく作成されたファイルに対するそれ以降のアクセス
422 にのみ適用される点に注意すること。
423 読み取り専用のファイルを作成する
424 .BR open ()
425 コールであっても、
426 読み書き可能なファイル・ディスクリプタを返すことがありうる。
427 .PP
428 .\"O The following symbolic constants are provided for
429 .\"O .IR mode :
430 .I mode
431 のために以下のシンボル定数が提供されている :
432 .TP 9
433 .B S_IRWXU
434 .\"O 00700 user (file owner) has read, write and execute permission
435 00700 ユーザー (ファイルの所有者) に読み込み、書き込み、
436 実行の許可がある。
437 .TP
438 .B S_IRUSR
439 .\"O 00400 user has read permission
440 00400 ユーザーに読み込みの許可がある。
441 .TP
442 .B S_IWUSR
443 .\"O 00200 user has write permission
444 00200 ユーザーに書き込みの許可がある。
445 .TP
446 .B S_IXUSR
447 .\"O 00100 user has execute permission
448 00100 ユーザーに実行の許可がある。
449 .TP
450 .B S_IRWXG
451 .\"O 00070 group has read, write and execute permission
452 00070 グループに読み込み、書き込み、実行の許可がある。
453 .TP
454 .B S_IRGRP
455 .\"O 00040 group has read permission
456 00040 グループに読み込みの許可がある。
457 .TP
458 .B S_IWGRP
459 .\"O 00020 group has write permission
460 00020 グループに書き込みの許可がある。
461 .TP
462 .B S_IXGRP
463 .\"O 00010 group has execute permission
464 00010 グループに実行の許可がある。
465 .TP
466 .B S_IRWXO
467 .\"O 00007 others have read, write and execute permission
468 00007 他人 (others) に読み込み、書き込み、実行の許可がある。
469 .TP
470 .B S_IROTH
471 .\"O 00004 others have read permission
472 00004 他人に読み込みの許可がある。
473 .TP
474 .B S_IWOTH
475 .\"O 00002 others have write permission
476 00002 他人に書き込みの許可がある。
477 .TP
478 .B S_IXOTH
479 .\"O 00001 others have execute permission
480 00001 他人に実行の許可がある。
481 .RE
482 .TP
483 .\"O .BR O_DIRECT " (Since Linux 2.4.10)"
484 .BR O_DIRECT " (Linux 2.4.10 以降)"
485 .\"O Try to minimize cache effects of the I/O to and from this file.
486 .\"O In general this will degrade performance, but it is useful in
487 .\"O special situations, such as when applications do their own caching.
488 .\"O File I/O is done directly to/from user space buffers.
489 このファイルに対する I/O のキャッシュの効果を最小化しようとする。
490 このフラグを使うと、一般的に性能が低下する。
491 しかしアプリケーションが独自にキャッシングを行っているような
492 特別な場合には役に立つ。
493 ファイルの I/O はユーザー空間バッファに対して直接行われる。
494 .\"O The
495 .\"O .B O_DIRECT
496 .\"O flag on its own makes at an effort to transfer data synchronously,
497 .\"O but does not give the guarantees of the
498 .\"O .B O_SYNC
499 .\"O that data and necessary metadata are transferred.
500 .B O_DIRECT
501 フラグ自身はデータを同期で転送しようとはするが、
502 .B O_SYNC
503 のようにデータと必要なメタデータの転送が保証されるわけではない。
504 .\"O To guarantee synchronous I/O the
505 .\"O .B O_SYNC
506 .\"O must be used in addition to
507 .\"O .BR O_DIRECT .
508 同期 I/O を保証するためには、
509 .B O_DIRECT
510 に加えて
511 .B O_SYNC
512 を使用しなければならない。
513 .\"O See
514 .\"O .B NOTES
515 .\"O below for further discussion.
516 「注意」の節 (下記) の議論も参照。
517 .sp
518 .\"O A semantically similar (but deprecated) interface for block devices
519 .\"O is described in
520 .\"O .BR raw (8).
521 ブロックデバイスに対する似通った意味のインターフェースが
522 .BR raw (8)
523 で説明されている (但し、このインタフェースは非推奨である)。
524 .TP
525 .B O_DIRECTORY
526 .\"O If \fIpathname\fP is not a directory, cause the open to fail.
527 .\"O .\" But see the following and its replies:
528 .\"O .\" http://marc.theaimsgroup.com/?t=112748702800001&r=1&w=2
529 .\"O .\" [PATCH] open: O_DIRECTORY and O_CREAT together should fail
530 .\"O .\" O_DIRECTORY | O_CREAT causes O_DIRECTORY to be ignored.
531 .\"O This flag is Linux-specific, and was added in kernel version 2.1.126, to
532 .\"O avoid denial-of-service problems if
533 .\"O .BR opendir (3)
534 .\"O is called on a
535 .\"O FIFO or tape device, but should not be used outside of the
536 .\"O implementation of
537 .\"O .BR opendir (3).
538 \fIpathname\fP がディレクトリでなければオープンは失敗する。
539 .\" 以下の記事とそのリプライを参照のこと。
540 .\" http://marc.theaimsgroup.com/?t=112748702800001&r=1&w=2
541 .\" [PATCH] open: O_DIRECTORY and O_CREAT together should fail
542 .\" O_DIRECTORY | O_CREAT を指定すると O_DIRECTORY が無視されてしまう。
543 このフラグは Linux 特有であり、
544 .BR opendir (3)
545 が FIFO やテープデバイスに対してコールされた場合の
546 サービス不能 (denial-of-service) 攻撃を避けるために
547 カーネル 2.1.126 で追加された。
548 しかしこれは
549 .BR opendir (3)
550 の実装以外では使用するべきではない。
551 .TP
552 .B O_EXCL
553 .\"O Ensure that this call creates the file:
554 .\"O if this flag is specified in conjunction with
555 .\"O .BR O_CREAT ,
556 .\"O and
557 .\"O .I pathname
558 .\"O already exists, then
559 .\"O .BR open ()
560 .\"O will fail.
561 .\"O The behavior of
562 .\"O .B O_EXCL
563 .\"O is undefined if
564 .\"O .B O_CREAT
565 .\"O is not specified.
566 この呼び出しでファイルが作成されることを保証する。
567 このフラグが
568 .B O_CREAT
569 と一緒に指定され、
570 .I pathname
571 のファイルが既に存在した場合、
572 .BR open ()
573 は失敗する。
574 .B O_CREAT
575 が指定されなかった場合の
576 .B O_EXCL
577 の動作は未定義である。
578
579 .\"O When these two flags are specified, symbolic links are not followed:
580 .\"O .\" POSIX.1-2001 explicitly requires this behavior.
581 .\"O if
582 .\"O .I pathname
583 .\"O is a symbolic link, then
584 .\"O .BR open ()
585 .\"O fails regardless of where the symbolic link points to.
586 これら二つのフラグが指定された際、シンボリックリンクは辿られない。
587 .\" POSIX.1-2001 では明示的にこの動作を要求している。
588 .I pathname
589 がシンボリックリンクの場合、
590 シンボリックリンクがどこを指しているかに関わらず
591 .BR open ()
592 は失敗する。
593
594 .\"O On NFS,
595 .\"O .B O_EXCL
596 .\"O is only supported when using NFSv3 or later on kernel 2.6 or later.
597 NFS では、
598 .B O_EXCL
599 は、Linux 2.6 以降で NFSv3 以降を使っている場合でのみサポートされる。
600 .\"O In NFS environments where
601 .\"O .B O_EXCL
602 .\"O support is not provided, programs that rely on it
603 .\"O for performing locking tasks will contain a race condition.
604 .\"O Portable programs that want to perform atomic file locking using a lockfile,
605 .\"O and need to avoid reliance on NFS support for
606 .\"O .BR O_EXCL ,
607 .\"O can create a unique file on
608 .\"O the same file system (e.g., incorporating hostname and PID), and use
609 .\"O .BR link (2)
610 .\"O to make a link to the lockfile.
611 .B O_EXCL
612 サポートが提供されていない NFS 環境では、このフラグに頼って
613 ロック処理を実行するプログラムは競合状態 (race condition) に出会う
614 可能性がある。
615 ロックファイルを使用して不可分 (atomic) なファイルロックを実現し、
616 NFS が
617 .B O_EXCL
618 をサポートしているかに依存しないようにしたい場合、
619 移植性のある方法は、同じファイルシステム上に他と名前の重ならない
620 ファイル (例えばホスト名と PID を組み合わせた名前) を作成し、
621 .BR link (2)
622 を使用してそのロックファイルへのリンクを作成することである。
623 .\"O If
624 .\"O .BR link (2)
625 .\"O returns 0, the lock is successful.
626 .\"O Otherwise, use
627 .\"O .BR stat (2)
628 .\"O on the unique file to check if its link count has increased to 2,
629 .\"O in which case the lock is also successful.
630 .BR link (2)
631 コールの返り値が 0 ならばロックに成功している。
632 あるいは、そのファイルに
633 .BR stat (2)
634 を使用してリンク数 (link count) が 2 になっているかをチェックする。
635 そうなっていれば、同じくロックに成功しているということである。
636 .TP
637 .B O_LARGEFILE
638 (LFS)
639 .\"O Allow files whose sizes cannot be represented in an
640 .\"O .I off_t
641 .\"O (but can be represented in an
642 .\"O .IR off64_t )
643 .\"O to be opened.
644 .\"O The
645 .\"O .B _LARGEFILE64_SOURCE
646 .\"O macro must be defined
647 .\"O (before including
648 .\"O .I any
649 .\"O header files)
650 .\"O in order to obtain this definition.
651 .\"O Setting the
652 .\"O .B _FILE_OFFSET_BITS
653 .\"O feature test macro to 64 (rather than using
654 .\"O .BR O_LARGEFILE )
655 .\"O is the preferred method of obtaining
656 .\"O method of accessing large files on 32-bit systems (see
657 .\"O .BR feature_test_macros (7)).
658 .I off_t
659 ではサイズを表せない (だだし
660 .I off64_t
661 ではサイズを表せる) ファイルをオープン可能にする。
662 この定義を有効にするためには、
663 (「どの」ヘッダファイルをインクルードするよりも前に)
664 .B _LARGEFILE64_SOURCE
665 マクロを定義しなければならない。
666 32ビットシステムにおいて大きなファイルにアクセスする方法を得たい場合、
667 .RB ( O_LARGEFILE
668 を使うよりも)
669 .B _FILE_OFFSET_BITS
670 機能検査マクロをセットする方が望ましい方法である
671 .RB ( feature_test_macros (7)
672 を参照)。
673 .TP
674 .\"O .BR O_NOATIME " (Since Linux 2.6.8)"
675 .BR O_NOATIME " (Linux 2.6.8 以降)"
676 .\"O Do not update the file last access time (st_atime in the inode)
677 .\"O when the file is
678 .\"O .BR read (2).
679 ファイルに対して
680 .BR read (2)
681 が実行されたときに、最終アクセス時刻 (inode の st_atime) を更新しない。
682 .\"O This flag is intended for use by indexing or backup programs,
683 .\"O where its use can significantly reduce the amount of disk activity.
684 このフラグはインデックス作成やバックアッププログラムで使うことを意図している。
685 これを使うとディスクに対する操作を大幅に減らすことができる。
686 .\"O This flag may not be effective on all file systems.
687 .\"O One example is NFS, where the server maintains the access time.
688 このフラグは全てのファイルシステムに対して有効であるわけではない。
689 その一例が NFS であり、サーバがアクセス時刻を管理している。
690 .\" The O_NOATIME flag also affects the treatment of st_atime
691 .\" by mmap() and readdir(2), MTK, Dec 04.
692 .TP
693 .B O_NOCTTY
694 .\"O If
695 .\"O .I pathname
696 .\"O refers to a terminal device \(em see
697 .\"O .BR tty (4)
698 .\"O \(em it will not become the process's controlling terminal even if the
699 .\"O process does not have one.
700 .I pathname
701 が端末 (terminal) デバイス
702 \(em
703 .BR tty (4)
704 参照
705 \(em
706 を指している場合に、たとえそのプロセスが制御端末を持っていなくても、
707 オープンしたファイルは制御端末にはならない。
708 .TP
709 .B O_NOFOLLOW
710 .\"O If \fIpathname\fP is a symbolic link, then the open fails.
711 .\"O This is a FreeBSD extension, which was added to Linux in version 2.1.126.
712 .\"O Symbolic links in earlier components of the pathname will still be
713 .\"O followed.
714 .\"O .\" The headers from glibc 2.0.100 and later include a
715 .\"O .\" definition of this flag; \fIkernels before 2.1.126 will ignore it if
716 .\"O .\" used\fP.
717 \fIpathname\fP がシンボリック・リンクだった場合、オープンは失敗する。
718 これは FreeBSD の拡張で、Linux には 2.1.126 より追加された。
719 pathname の前のコンポーネント (earlier component;
720 訳註: 最後のディレクトリセパレータより前の部分) が
721 シンボリック・リンクである場合には、それが指す先が参照される。
722 .\" glibc 2.0.100 以降のヘッダーにはこのフラグの定義がある。
723 .\" \fI2.1.126 以前のカーネルで使用した場合には無視される。\fP
724 .TP
725 .\"O .BR O_NONBLOCK " or " O_NDELAY
726 .BR O_NONBLOCK " または " O_NDELAY
727 .\"O When possible, the file is opened in nonblocking mode.
728 .\"O Neither the
729 .\"O .BR open ()
730 .\"O nor any subsequent operations on the file descriptor which is
731 .\"O returned will cause the calling process to wait.
732 .\"O For the handling of FIFOs (named pipes), see also
733 .\"O .BR fifo (7).
734 .\"O For a discussion of the effect of
735 .\"O .B O_NONBLOCK
736 .\"O in conjunction with mandatory file locks and with file leases, see
737 .\"O .BR fcntl (2).
738 可能ならば、ファイルは非停止 (nonblocking) モードでオープンされる。
739 .BR open ()
740 も、返したファイル・ディスクリプタに対する以後のすべての操作も
741 呼び出したプロセスを待たせることはない。
742 FIFO (ネームド・パイプ) を扱う場合には
743 .BR fifo (7)
744 も参照すること。
745 強制ファイルロック (mandatory file lock) やファイルリース (file lease)
746 と組み合わせた場合の、
747 .B O_NONBLOCK
748 の効果についての議論は、
749 .BR fcntl (2)
750 を参照すること。
751 .TP
752 .B O_SYNC
753 .\"O The file is opened for synchronous I/O.
754 .\"O Any
755 .\"O .BR write (2)s
756 .\"O on the resulting file descriptor will block the calling process until
757 .\"O the data has been physically written to the underlying hardware.
758 .\"O .IR "But see NOTES below" .
759 ファイルは同期 (synchronous) I/O モードでオープンされる。
760 .BR open ()
761 が返したファイル・ディスクリプタに対して
762 .BR write (2)
763 を行うと、必ず呼び出したプロセスをブロックし、
764 該当ハードウェアに物理的に書き込まれるまで返らない。
765 .I 以下の「注意」の章も参照。
766 .TP
767 .B O_TRUNC
768 .\"O If the file already exists and is a regular file and the open mode allows
769 .\"O writing (i.e., is
770 .\"O .B O_RDWR
771 .\"O or
772 .\"O .BR O_WRONLY )
773 .\"O it will be truncated to length 0.
774 .\"O If the file is a FIFO or terminal device file, the
775 .\"O .B O_TRUNC
776 .\"O flag is ignored.
777 .\"O Otherwise the effect of
778 .\"O .B O_TRUNC
779 .\"O is unspecified.
780 ファイルが既に存在し、通常ファイルであり、
781 書き込み可モードでオープンされている
782 (つまり、
783 .BR O_RDWR "または" O_WRONLY
784 の) 場合、長さ 0 に切り詰め (truncate) られる。
785 ファイルが FIFO または端末デバイスファイルの場合、
786 .B O_TRUNC
787 フラグは無視される。
788 それ以外の場合、
789 .B O_TRUNC
790 の効果は未定義である。
791 .PP
792 .\"O Some of these optional flags can be altered using
793 .\"O .BR fcntl (2)
794 .\"O after the file has been opened.
795 これらの選択フラグのいくつかはファイルをオープンした後でも
796 .BR fcntl (2)
797 を使用して変更することができる。
798
799 .\"O .BR creat ()
800 .\"O is equivalent to
801 .\"O .BR open ()
802 .\"O with
803 .\"O .I flags
804 .\"O equal to
805 .\"O .BR O_CREAT|O_WRONLY|O_TRUNC .
806 .BR creat ()
807
808 .I flags
809
810 .B O_CREAT|O_WRONLY|O_TRUNC
811 を指定して
812 .BR open ()
813 を行うのと等価である。
814 .\"O .SH "RETURN VALUE"
815 .SH 返り値
816 .\"O .BR open ()
817 .\"O and
818 .\"O .BR creat ()
819 .\"O return the new file descriptor, or \-1 if an error occurred
820 .\"O (in which case,
821 .\"O .I errno
822 .\"O is set appropriately).
823 .BR open ()
824
825 .BR creat ()
826 は新しいファイル・ディスクリプタを返す。
827 エラーが発生した場合は \-1 を返す
828 (その場合は
829 .I errno
830 が適切に設定される)。
831 .\"O .SH ERRORS
832 .SH エラー
833 .TP
834 .B EACCES
835 .\"O The requested access to the file is not allowed, or search permission
836 .\"O is denied for one of the directories in the path prefix of
837 .\"O .IR pathname ,
838 .\"O or the file did not exist yet and write access to the parent directory
839 .\"O is not allowed.
840 .\"O (See also
841 .\"O .BR path_resolution (7).)
842 ファイルに対する要求されたアクセスが許されていないか、
843 .I pathname
844 のディレクトリ部分の何れかのディレクトリに検索許可がなかった。
845 またはファイルが存在せず、親ディレクトリへの書き込み許可がなかった。
846 .RB ( path_resolution (7)
847 も参照すること。)
848 .TP
849 .B EEXIST
850 .\"O .I pathname
851 .\"O already exists and
852 .\"O .BR O_CREAT " and " O_EXCL
853 .\"O were used.
854 .I pathname
855 は既に存在し、
856 .BR O_CREAT " と " O_EXCL
857 が使用された。
858 .TP
859 .B EFAULT
860 .\"O .I pathname
861 .\"O points outside your accessible address space.
862 .I pathname
863 の指す領域がアクセス可能なアドレス空間にない。
864 .TP
865 .B EFBIG
866 .\"O See
867 .\"O .BR EOVERFLOW .
868 .B EOVERFLOW
869 参照。
870 .TP
871 .B EINTR
872 .\"O While blocked waiting to complete an open of a slow device
873 .\"O (e.g., a FIFO; see
874 .\"O .BR fifo (7)),
875 .\"O the call was interrupted by a signal handler; see
876 .\"O .BR signal (7).
877 遅いデバイス
878 (例えば FIFO、
879 .BR fifo (7)
880 参照) のオープンが完了するのを待って停止している間に
881 システムコールがシグナルハンドラにより割り込まれた。
882 .BR signal (7)
883 参照。
884 .TP
885 .B EISDIR
886 .\"O .I pathname
887 .\"O refers to a directory and the access requested involved writing
888 .\"O (that is,
889 .\"O .B O_WRONLY
890 .\"O or
891 .\"O .B O_RDWR
892 .\"O is set).
893 .I pathname
894 はディレクトリを参照しており、書き込み要求が含まれていた
895 (つまり
896 .B O_WRONLY
897 または
898 .B O_RDWR
899 が設定されている)。
900 .TP
901 .B ELOOP
902 .\"O Too many symbolic links were encountered in resolving
903 .\"O .IR pathname ,
904 .\"O or \fBO_NOFOLLOW\fP was specified but
905 .\"O .I pathname
906 .\"O was a symbolic link.
907 .I pathname
908 を解決する際に遭遇したシンボリック・リンクが多過ぎる。
909 または \fBO_NOFOLLOW\fP が指定されており、
910 .I pathname
911 がシンボリックリンクだった。
912 .TP
913 .B EMFILE
914 .\"O The process already has the maximum number of files open.
915 プロセスがオープンしているファイル数がすでに最大数に達している。
916 .TP
917 .B ENAMETOOLONG
918 .\"O .I pathname
919 .\"O was too long.
920 .I pathname
921 が長過ぎる。
922 .TP
923 .B ENFILE
924 .\"O The system limit on the total number of open files has been reached.
925 オープンできるファイルの合計数がシステム制限に達している。
926 .TP
927 .B ENODEV
928 .\"O .I pathname
929 .\"O refers to a device special file and no corresponding device exists.
930 .\"O (This is a Linux kernel bug; in this situation
931 .\"O .B ENXIO
932 .\"O must be returned.)
933 .I pathname
934 がデバイス・スペシャル・ファイルを参照しており、対応するデバイスが存在しない。
935 (これは Linux カーネルのバグであり、この場合には
936 .B ENXIO
937 が返されるべきである)
938 .TP
939 .B ENOENT
940 .\"O .B O_CREAT
941 .\"O is not set and the named file does not exist.
942 .\"O Or, a directory component in
943 .\"O .I pathname
944 .\"O does not exist or is a dangling symbolic link.
945 .B O_CREAT
946 が設定されておらず、かつ指定されたファイルが存在しない。
947 または、
948 .I pathname
949 のディレクトリ部分が存在しないか壊れた (dangling) シンボリック・リンクである。
950 .TP
951 .B ENOMEM
952 .\"O Insufficient kernel memory was available.
953 カーネルに利用できるメモリが不足している
954 .TP
955 .B ENOSPC
956 .\"O .I pathname
957 .\"O was to be created but the device containing
958 .\"O .I pathname
959 .\"O has no room for the new file.
960 .I pathname
961 を作成する必要があるが、
962 .I pathname
963 を含んでいるデバイスに新しいファイルのための空き容量がない。
964 .TP
965 .B ENOTDIR
966 .\"O A component used as a directory in
967 .\"O .I pathname
968 .\"O is not, in fact, a directory, or \fBO_DIRECTORY\fP was specified and
969 .\"O .I pathname
970 .\"O was not a directory.
971 .I pathname
972 に含まれるディレクトリ部分のどれかが実際にはディレクトリでない。
973 または \fBO_DIRECTORY\fP が指定されており、
974 .I pathname
975 がディレクトリでない。
976 .TP
977 .B ENXIO
978 .\"O .BR O_NONBLOCK " | " O_WRONLY
979 .\"O is set, the named file is a FIFO and
980 .\"O no process has the file open for reading.
981 .\"O Or, the file is a device special file and no corresponding device exists.
982 .BR O_NONBLOCK " | " O_WRONLY
983 が設定されており、指定したファイルが FIFO で
984 そのファイルを読み込みのためにオープンしているプロセスが存在しない。
985 または、ファイルがデバイス・スペシャル・ファイルで
986 対応するデバイスが存在しない。
987 .TP
988 .B EOVERFLOW
989 .\"O .I pathname
990 .\"O refers to a regular file that is too large to be opened.
991 .\"O The usual scenario here is that an application compiled
992 .\"O on a 32-bit platform without
993 .\"O .I -D_FILE_OFFSET_BITS=64
994 .\"O tried to open a file whose size exceeds
995 .\"O .I (2<<31)-1
996 .\"O bits;
997 .\"O see also
998 .\"O .B O_LARGEFILE
999 .\"O above.
1000 .\"O This is the error specified by POSIX.1-2001;
1001 .\"O in kernels before 2.6.24, Linux gave the error
1002 .\"O .B EFBIG
1003 .\"O for this case.
1004 .I pathname
1005 が参照しているのが、大き過ぎてオープンできない通常のファイルである。
1006 通常、このエラーが発生するは、32 ビットプラットフォーム上で
1007 .I -D_FILE_OFFSET_BITS=64
1008 を指定せずにコンパイルされたアプリケーションが、ファイルサイズが
1009 .I (2<31)-1
1010 ビットを超えるファイルを開こうとした場合である。
1011 上記の
1012 .B O_LARGEFILE
1013 も参照。
1014 これは POSIX.1-2001 で規定されているエラーである。
1015 2.6.24 より前のカーネルでは、Linux はこの場合にエラー
1016 .B EFBIG
1017 を返していた。
1018 .\" See http://bugzilla.kernel.org/show_bug.cgi?id=7253
1019 .\" "Open of a large file on 32-bit fails with EFBIG, should be EOVERFLOW"
1020 .\" Reported 2006-10-03
1021 .TP
1022 .B EPERM
1023 .\"O The
1024 .\"O .B O_NOATIME
1025 .\"O flag was specified, but the effective user ID of the caller
1026 .\"O .\" Strictly speaking, it's the file system UID... (MTK)
1027 .\"O did not match the owner of the file and the caller was not privileged
1028 .\"O .RB ( CAP_FOWNER ).
1029 .B O_NOATIME
1030 フラグが指定されたが、呼び出し元の実効ユーザー ID が
1031 .\" 厳密に言えば、呼び出し元のファイルシステム UID...(MTK)
1032 ファイルの所有者と一致せず、かつ呼び出し元に特権
1033 .RB ( CAP_FOWNER )
1034 がない。
1035 .TP
1036 .B EROFS
1037 .\"O .I pathname
1038 .\"O refers to a file on a read-only file system and write access was
1039 .\"O requested.
1040 .I pathname
1041 が読み込み専用のファイルシステム上のファイルを参照しており、
1042 書き込みアクセスが要求された。
1043 .TP
1044 .B ETXTBSY
1045 .\"O .I pathname
1046 .\"O refers to an executable image which is currently being executed and
1047 .\"O write access was requested.
1048 .I pathname
1049 が現在実行中の実行イメージを参照しており、書き込みが要求された。
1050 .TP
1051 .B EWOULDBLOCK
1052 .\"O The
1053 .\"O .B O_NONBLOCK
1054 .\"O flag was specified, and an incompatible lease was held on the file
1055 .\"O (see
1056 .\"O .BR fcntl (2)).
1057 .B O_NONBLOCK
1058 フラグが指定されたが、そのファイルには矛盾するリースが設定されていた
1059 .RB ( fcntl (2)
1060 参照)。
1061 .\"O .SH "CONFORMING TO"
1062 .SH 準拠
1063 SVr4, 4.3BSD, POSIX.1-2001.
1064 .\"O The
1065 .\"O .BR O_DIRECTORY ,
1066 .\"O .BR O_NOATIME ,
1067 .\"O and
1068 .\"O .B O_NOFOLLOW
1069 .\"O flags are Linux-specific, and one may need to define
1070 .\"O .B _GNU_SOURCE
1071 .\"O (before including
1072 .\"O .I any
1073 .\"O header files)
1074 .\"O to obtain their definitions.
1075 フラグ
1076 .BR O_DIRECTORY ,
1077 .BR O_NOATIME ,
1078 .B O_NOFOLLOW
1079 は Linux 特有のものであり、
1080 これらのフラグの定義を得るためには、
1081 (「どの」ヘッダファイルをインクルードするよりも前に)
1082 .B _GNU_SOURCE
1083 を定義する必要があるかもしれない。
1084
1085 .\"O The
1086 .\"O .BR O_CLOEXEC
1087 .\"O flag is not specified in POSIX.1-2001,
1088 .\"O but is specified in POSIX.1-2008.
1089 .BR O_CLOEXEC
1090 フラグは POSIX.1-2001 では規定されていないが、
1091 POSIX.1-2008 で規定されている。
1092
1093 .\"O .B O_DIRECT
1094 .\"O is not specified in POSIX; one has to define
1095 .\"O .B _GNU_SOURCE
1096 .\"O (before including
1097 .\"O .I any
1098 .\"O header files)
1099 .\"O to get its definition.
1100 .B O_DIRECT
1101 は POSIX では規定されていない。
1102 .B O_DIRECT
1103 の定義を得るには
1104 (「どの」ヘッダファイルをインクルードするよりも前に)
1105 .B _GNU_SOURCE
1106 を定義しなければならない。
1107 .\"O .SH NOTES
1108 .SH 注意
1109 .\"O Under Linux, the
1110 .\"O .B O_NONBLOCK
1111 .\"O  flag indicates that one wants to open
1112 .\"O but does not necessarily have the intention to read or write.
1113 Linux では、
1114 .B O_NONBLOCK
1115 フラグは、
1116 open を実行したいが read または write を実行する意図は
1117 必ずしもないことを意味する。
1118 .\"O This is typically used to open devices in order to get a file descriptor
1119 .\"O for use with
1120 .\"O .BR ioctl (2).
1121 これは
1122 .BR ioctl (2)
1123 のためのファイルディスクリプタを取得するために、
1124 デバイスをオープンするときによく用いられる。
1125
1126 .\"O Unlike the other values that can be specified in
1127 .\"O .IR flags ,
1128 .\"O the
1129 .\"O .I "access mode"
1130 .\"O values
1131 .\"O .BR O_RDONLY ", " O_WRONLY ", and " O_RDWR ,
1132 .\"O do not specify individual bits.
1133 .\"O Rather, they define the low order two bits of
1134 .\"O .IR flags ,
1135 .\"O and are defined respectively as 0, 1, and 2.
1136 「アクセスモード」の値
1137 .BR O_RDONLY ", " O_WRONLY ", " O_RDWR
1138 は、
1139 .I flags
1140 に指定できる他の値と違い、個々のビットを指定するものではなく、
1141 これらの値は
1142 .I flags
1143 の下位 2 ビットを定義する。
1144 .BR O_RDONLY ", " O_WRONLY ", " O_RDWR
1145 はそれぞれ 0, 1, 2 に定義されている。
1146 .\"O In other words, the combination
1147 .\"O .B "O_RDONLY | O_WRONLY"
1148 .\"O is a logical error, and certainly does not have the same meaning as
1149 .\"O .BR O_RDWR .
1150 言い換えると、
1151 .B "O_RDONLY | O_WRONLY"
1152 の組み合わせは論理的に間違いであり、確かに
1153 .B O_RDWR
1154 と同じ意味ではない。
1155 .\"O Linux reserves the special, nonstandard access mode 3 (binary 11) in
1156 .\"O .I flags
1157 .\"O to mean:
1158 .\"O check for read and write permission on the file and return a descriptor
1159 .\"O that can't be used for reading or writing.
1160 .\"O This nonstandard access mode is used by some Linux drivers to return a
1161 .\"O descriptor that is only to be used for device-specific
1162 .\"O .BR ioctl (2)
1163 .\"O operations.
1164 Linux では、特別な、非標準なアクセスモードとして 3 (バイナリでは 11) が
1165 予約されており
1166 .I flags
1167 に指定できる。
1168 このアクセスモードを指定すると、ファイルの読み出し/書き込み許可をチェックし、
1169 読み出しにも書き込みにも使用できないディスクリプタを返す。
1170 この非標準のアクセスモードはいくつかの Linux ドライバで使用されており、
1171 デバイス固有の
1172 .BR ioctl (2)
1173 操作にのみ使用されるディスクリプタを返すために使われている。
1174 .\" See for example util-linux's disk-utils/setfdprm.c
1175 .\" For some background on access mode 3, see
1176 .\" http://thread.gmane.org/gmane.linux.kernel/653123
1177 .\" "[RFC] correct flags to f_mode conversion in __dentry_open"
1178 .\" LKML, 12 Mar 2008
1179 .LP
1180 .\"O The (undefined) effect of
1181 .\"O .B O_RDONLY | O_TRUNC
1182 .\"O varies among implementations.
1183 .\"O On many systems the file is actually truncated.
1184 .B O_RDONLY | O_TRUNC
1185 の影響は未定義であり、その動作は実装によって異なる。
1186 多くのシステムではファイルは実際に切り詰められる。
1187 .\" Linux 2.0, 2.5: truncate
1188 .\" Solaris 5.7, 5.8: truncate
1189 .\" Irix 6.5: truncate
1190 .\" Tru64 5.1B: truncate
1191 .\" HP-UX 11.22: truncate
1192 .\" FreeBSD 4.7: truncate
1193 .PP
1194 .\"O There are many infelicities in the protocol underlying NFS, affecting
1195 .\"O amongst others
1196 .\"O .BR O_SYNC " and " O_NDELAY .
1197 NFS を実現しているプロトコルには多くの不備があり、特に
1198 .BR O_SYNC " と " O_NDELAY
1199 に影響する。
1200
1201 .\"O POSIX provides for three different variants of synchronized I/O,
1202 .\"O corresponding to the flags
1203 .\"O .BR O_SYNC ,
1204 .\"O .BR O_DSYNC ,
1205 .\"O and
1206 .\"O .BR O_RSYNC .
1207 POSIX では、3 種類の同期 I/O が提供されており、
1208 .BR O_SYNC ,
1209 .BR O_DSYNC ,
1210 .BR O_RSYNC
1211 フラグがこれに対応するものである。
1212 .\"O Currently (2.6.31), Linux only implements
1213 .\"O .BR O_SYNC ,
1214 .\"O but glibc maps
1215 .\"O .B O_DSYNC
1216 .\"O and
1217 .\"O .B O_RSYNC
1218 .\"O to the same numerical value as
1219 .\"O .BR O_SYNC .
1220 今のところ (カーネル 2.6.31)、
1221 Linux では
1222 .B O_SYNC
1223 だけが実装されているが、
1224 glibc は
1225 .B O_DSYNC
1226
1227 .B O_RSYNC
1228
1229 .B O_SYNC
1230 と同じ数値を割り当てている。
1231 .\"O Most Linux file systems don't actually implement the POSIX
1232 .\"O .B O_SYNC
1233 .\"O semantics, which require all metadata updates of a write
1234 .\"O to be on disk on returning to userspace, but only the
1235 .\"O .B O_DSYNC
1236 .\"O semantics, which require only actual file data and metadata necessary
1237 .\"O to retrieve it to be on disk by the time the system call returns.
1238 ほとんどの Linux のファイルシステムは、実際には POSIX の
1239 .B O_SYNC
1240 の動作ではなく
1241 .B O_DSYNC
1242 の動作だけを実装している。
1243 POSIX の
1244 .B O_SYNC
1245 では、
1246 .BR open ()
1247 がユーザ空間に返る際に、書き込みに関する全てのメタデータの
1248 更新がディスクに書き込まれている必要がある。
1249 一方、
1250 .B O_DSYNC
1251 では、
1252 .BR open ()
1253 が返るまでに、実際のファイルのデータとそのデータを取得するために
1254 必要なメタデータだけがディスクに書き込まれていればよい。
1255
1256 .\"O Note that
1257 .\"O .BR open ()
1258 .\"O can open device special files, but
1259 .\"O .BR creat ()
1260 .\"O cannot create them; use
1261 .\"O .BR mknod (2)
1262 .\"O instead.
1263 .BR open ()
1264 はスペシャル・ファイルをオープンすることができるが、
1265 .BR creat ()
1266 でスペシャル・ファイルを作成できない点に注意すること。
1267 代わりに
1268 .BR mknod (2)
1269 を使用する。
1270 .LP
1271 .\"O On NFS file systems with UID mapping enabled,
1272 .\"O .BR open ()
1273 .\"O may
1274 .\"O return a file descriptor but, for example,
1275 .\"O .BR read (2)
1276 .\"O requests are denied
1277 .\"O with \fBEACCES\fP.
1278 .\"O This is because the client performs
1279 .\"O .BR open ()
1280 .\"O by checking the
1281 .\"O permissions, but UID mapping is performed by the server upon
1282 .\"O read and write requests.
1283 UID マッピングを使用している NFS ファイル・システムでは、
1284 .BR open ()
1285 がファイル・ディスクリプタを返した場合でも
1286 .BR read (2)
1287 が \fBEACCES\fP で拒否される場合がある。
1288 これはクライアントがアクセス許可のチェックを行って
1289 .BR open ()
1290 を実行するが、読み込みや書き込みの際には
1291 サーバーで UID マッピングが行われるためである。
1292
1293 .\"O If the file is newly created, its
1294 .\"O .IR st_atime ,
1295 .\"O .IR st_ctime ,
1296 .\"O .I st_mtime
1297 .\"O fields
1298 .\"O (respectively, time of last access, time of last status change, and
1299 .\"O time of last modification; see
1300 .\"O .BR stat (2))
1301 .\"O are set
1302 .\"O to the current time, and so are the
1303 .\"O .I st_ctime
1304 .\"O and
1305 .\"O .I st_mtime
1306 .\"O fields of the
1307 .\"O parent directory.
1308 .\"O Otherwise, if the file is modified because of the
1309 .\"O .B O_TRUNC
1310 .\"O flag, its st_ctime and st_mtime fields are set to the current time.
1311 ファイルが新しく作成されると、
1312 ファイルの
1313 .IR st_atime ,
1314 .IR st_ctime ,
1315 .I st_mtime
1316 フィールド
1317 (それぞれ最終アクセス時刻、最終状態変更時刻、最終修正時刻である。
1318 .BR stat (2)
1319 参照) が現在時刻に設定される。
1320 さらに親ディレクトリの
1321 .I st_ctime
1322
1323 .I st_mtime
1324 も現在時刻に設定される。
1325 それ以外の場合で、O_TRUNC フラグでファイルが修正されたときは、
1326 ファイルの
1327 .I st_ctime
1328
1329 .I st_mtime
1330 フィールドが現在時刻に設定される。
1331 .SS O_DIRECT
1332 .LP
1333 .\"O The
1334 .\"O .B O_DIRECT
1335 .\"O flag may impose alignment restrictions on the length and address
1336 .\"O of userspace buffers and the file offset of I/Os.
1337 .\"O In Linux alignment
1338 .\"O restrictions vary by file system and kernel version and might be
1339 .\"O absent entirely.
1340 .\"O However there is currently no file system\-independent
1341 .\"O interface for an application to discover these restrictions for a given
1342 .\"O file or file system.
1343 .\"O Some file systems provide their own interfaces
1344 .\"O for doing so, for example the
1345 .\"O .B XFS_IOC_DIOINFO
1346 .\"O operation in
1347 .\"O .BR xfsctl (3).
1348 .B O_DIRECT
1349 フラグを使用する場合、ユーザ空間バッファの長さやアドレス、
1350 I/O のファイルオフセットに関してアラインメントの制限が課されることがある。
1351 Linux では、アラインメントの制限はファイルシステムやカーネルのバージョンに
1352 よって異なり、全く制限が存在しない場合もある。
1353 しかしながら、現在のところ、指定されたファイルやファイルシステムに対して
1354 こうした制限があるかを見つけるための、アプリケーション向けのインタフェースで
1355 ファイルシステム非依存のものは存在しない。
1356 いくつかのファイルシステムでは、制限を確認するための独自のインタフェースが
1357 提供されている。例えば、
1358 .BR xfsctl (3)
1359
1360 .B XFS_IOC_DIOINFO
1361 命令である。
1362 .LP
1363 .\"O Under Linux 2.4, transfer sizes, and the alignment of the user buffer
1364 .\"O and the file offset must all be multiples of the logical block size
1365 .\"O of the file system.
1366 .\"O Under Linux 2.6, alignment to 512-byte boundaries
1367 .\"O suffices.
1368 Linux 2.4 では、転送サイズ、
1369 ユーザーバッファのアラインメント、ファイルオフセットは、
1370 ファイルシステムの論理ブロックサイズの倍数でなければならない。
1371 Linux 2.6 では、512 バイトごとの境界に配置されていれば充分である。
1372 .LP
1373 .\"O The
1374 .\"O .B O_DIRECT
1375 .\"O flag was introduced in SGI IRIX, where it has alignment
1376 .\"O restrictions similar to those of Linux 2.4.
1377 .\"O IRIX has also a
1378 .\"O .BR fcntl (2)
1379 .\"O call to query appropriate alignments, and sizes.
1380 .\"O FreeBSD 4.x introduced
1381 .\"O a flag of the same name, but without alignment restrictions.
1382 .B O_DIRECT
1383 フラグは  SGI IRIX で導入された。SGI IRIX にも Linux 2.4 と同様の
1384 (ユーザーバッファの) アラインメントの制限がある。
1385 また、IRIX には適切な配置とサイズを取得するための
1386 .BR fcntl (2)
1387 コールがある。
1388 FreeBSD 4.x も同じ名前のフラグを導入したが、アラインメントの制限はない。
1389 .LP
1390 .\"O .B O_DIRECT
1391 .\"O support was added under Linux in kernel version 2.4.10.
1392 .\"O Older Linux kernels simply ignore this flag.
1393 .\"O Some file systems may not implement the flag and
1394 .\"O .BR open ()
1395 .\"O will fail with
1396 .\"O .B EINVAL
1397 .\"O if it is used.
1398 .B O_DIRECT
1399 が Linux でサポートされたのは、カーネルバージョン 2.4.10 である。
1400 古い Linux カーネルは、このフラグを単に無視する。
1401 .B O_DIRECT
1402 フラグをサポートしていないファイルシステムもあり、その場合は、
1403 .B O_DIRECT
1404 を使用すると
1405 .BR open ()
1406
1407 .B EINVAL
1408 で失敗する。
1409 .LP
1410 .\"O Applications should avoid mixing
1411 .\"O .B O_DIRECT
1412 .\"O and normal I/O to the same file,
1413 .\"O and especially to overlapping byte regions in the same file.
1414 .\"O Even when the file system correctly handles the coherency issues in
1415 .\"O this situation, overall I/O throughput is likely to be slower than
1416 .\"O using either mode alone.
1417 .\"O Likewise, applications should avoid mixing
1418 .\"O .BR mmap (2)
1419 .\"O of files with direct I/O to the same files.
1420 アプリケーションは、同じファイル、
1421 特に同じファイルの重複するバイト領域に対して、
1422 .B O_DIRECT
1423 と通常の I/O を混ぜて使うのは避けるべきである。
1424 ファイルシステムがこのような状況において一貫性の問題を正しく
1425 扱うことができる場合であっても、全体の I/O スループットは
1426 どちらか一方を使用するときと比べて低速になるであろう。
1427 同様に、アプリケーションは、同じファイルに対して
1428 .BR mmap (2)
1429 と直接 I/O
1430 .RB ( O_DIRECT )
1431 を混ぜて使うのも避けるべきである。
1432 .LP
1433 .\"O The behaviour of
1434 .\"O .B O_DIRECT
1435 .\"O with NFS will differ from local file systems.
1436 .\"O Older kernels, or
1437 .\"O kernels configured in certain ways, may not support this combination.
1438 .\"O The NFS protocol does not support passing the flag to the server, so
1439 .\"O .B O_DIRECT
1440 .\"O I/O will only bypass the page cache on the client; the server may
1441 .\"O still cache the I/O.
1442 NFS で
1443 .B O_DIRECT
1444 を使った場合の動作はローカルのファイルシステムの場合と違う。
1445 古いカーネルや、ある種の設定でコンパイルされたカーネルは、
1446 .B O_DIRECT
1447 と NFS の組み合わせをサポートしていないかもしれない。
1448 NFS プロトコル自体はサーバにフラグを渡す機能は持っていないので、
1449 .B O_DIRECT
1450 I/O はクライアント上のページキャッシュをバイパスするだけになり、
1451 サーバは I/O をキャッシュしているかもしれない。
1452 .\"O The client asks the server to make the I/O
1453 .\"O synchronous to preserve the synchronous semantics of
1454 .\"O .BR O_DIRECT .
1455 .\"O Some servers will perform poorly under these circumstances, especially
1456 .\"O if the I/O size is small.
1457 .\"O Some servers may also be configured to
1458 .\"O lie to clients about the I/O having reached stable storage; this
1459 .\"O will avoid the performance penalty at some risk to data integrity
1460 .\"O in the event of server power failure.
1461 .\"O The Linux NFS client places no alignment restrictions on
1462 .\"O .B O_DIRECT
1463 .\"O I/O.
1464 クライアントは、
1465 .B O_DIRECT
1466 の同期機構を保持するため、サーバに対して I/O を同期して行うように依頼する。
1467 サーバによっては、こうした状況下、特に I/O サイズが小さい場合に
1468 性能が大きく劣化する。
1469 また、サーバによっては、I/O が安定したストレージにまで行われたと、
1470 クライアントに対して嘘をつくものもある。
1471 これは、サーバの電源故障が起こった際にデータの完全性が保たれない
1472 危険は少しあるが、性能面での不利な条件を回避するために行われている。
1473 Linux の NFS クライアントでは
1474 .B O_DIRECT
1475 I/O 
1476 でのアラインメントの制限はない。
1477 .PP
1478 .\"O In summary,
1479 .\"O .B O_DIRECT
1480 .\"O is a potentially powerful tool that should be used with caution.
1481 .\"O It is recommended that applications treat use of
1482 .\"O .B O_DIRECT
1483 .\"O as a performance option which is disabled by default.
1484 まとめると、
1485 .B O_DIRECT
1486 は、注意して使うべきであるが、強力なツールとなる可能性を持っている。
1487 アプリケーションは
1488 .B O_DIRECT
1489 をデフォルトでは無効になっている性能向上のためのオプションと
1490 考えておくのがよいであろう。
1491 .PP
1492 .RS
1493 .\"O "The thing that has always disturbed me about O_DIRECT is that the whole
1494 .\"O interface is just stupid, and was probably designed by a deranged monkey
1495 .\"O on some serious mind-controlling substances." \(em Linus
1496 「O_DIRECT でいつも困るのは、インタフェース全部が本当にお馬鹿な点だ。
1497 たぶん危ないマインドコントロール剤で
1498 頭がおかしくなったサルが設計したんじゃないかな」 \(em Linus
1499 .RE
1500 .\"O .SH BUGS
1501 .SH バグ
1502 .\"O Currently, it is not possible to enable signal-driven
1503 .\"O I/O by specifying
1504 .\"O .B O_ASYNC
1505 .\"O when calling
1506 .\"O .BR open ();
1507 .\"O use
1508 .\"O .BR fcntl (2)
1509 .\"O to enable this flag.
1510 現在のところ、
1511 .BR open ()
1512 の呼び出し時に
1513 .B O_ASYNC
1514 を指定してシグナル駆動 I/O を有効にすることはできない。
1515 このフラグを有効にするには
1516 .BR fcntl (2)
1517 を使用すること。
1518 .\" FIXME . Check bugzilla report on open(O_ASYNC)
1519 .\" See http://bugzilla.kernel.org/show_bug.cgi?id=5993
1520 .\"O .SH "SEE ALSO"
1521 .SH 関連項目
1522 .BR chmod (2),
1523 .BR chown (2),
1524 .BR close (2),
1525 .BR dup (2),
1526 .BR fcntl (2),
1527 .BR link (2),
1528 .BR lseek (2),
1529 .BR mknod (2),
1530 .BR mmap (2),
1531 .BR mount (2),
1532 .BR openat (2),
1533 .BR read (2),
1534 .BR socket (2),
1535 .BR stat (2),
1536 .BR umask (2),
1537 .BR unlink (2),
1538 .BR write (2),
1539 .BR fopen (3),
1540 .BR fifo (7),
1541 .BR path_resolution (7),
1542 .BR symlink (7)