OSDN Git Service

(split) Convert release and draft pages to UTF-8.
[linuxjm/LDP_man-pages.git] / draft / man2 / fcntl.2
1 '\" t
2 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\"
4 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
5 .\"                 and Copyright (C) 1993 Michael Haardt, Ian Jackson;
6 .\"                 and Copyright (C) 1998 Jamie Lokier;
7 .\"                 and Copyright (C) 2002 Michael Kerrisk.
8 .\"
9 .\" Permission is granted to make and distribute verbatim copies of this
10 .\" manual provided the copyright notice and this permission notice are
11 .\" preserved on all copies.
12 .\"
13 .\" Permission is granted to copy and distribute modified versions of this
14 .\" manual under the conditions for verbatim copying, provided that the
15 .\" entire resulting derived work is distributed under the terms of a
16 .\" permission notice identical to this one.
17 .\"
18 .\" Since the Linux kernel and libraries are constantly changing, this
19 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
20 .\" responsibility for errors or omissions, or for damages resulting from
21 .\" the use of the information contained herein.  The author(s) may not
22 .\" have taken the same level of care in the production of this manual,
23 .\" which is licensed free of charge, as they might when working
24 .\" professionally.
25 .\"
26 .\" Formatted or processed versions of this manual, if unaccompanied by
27 .\" the source, must acknowledge the copyright and authors of this work.
28 .\"
29 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
30 .\" Modified 1995-09-26 by Andries Brouwer <aeb@cwi.nl>
31 .\" and again on 960413 and 980804 and 981223.
32 .\" Modified 1998-12-11 by Jamie Lokier <jamie@imbolc.ucc.ie>
33 .\" Applied correction by Christian Ehrhardt - aeb, 990712
34 .\" Modified 2002-04-23 by Michael Kerrisk <mtk.manpages@gmail.com>
35 .\"     Added note on F_SETFL and O_DIRECT
36 .\"     Complete rewrite + expansion of material on file locking
37 .\"     Incorporated description of F_NOTIFY, drawing on
38 .\"             Stephen Rothwell's notes in Documentation/dnotify.txt.
39 .\"     Added description of F_SETLEASE and F_GETLEASE
40 .\" Corrected and polished, aeb, 020527.
41 .\" Modified 2004-03-03 by Michael Kerrisk <mtk.manpages@gmail.com>
42 .\"     Modified description of file leases: fixed some errors of detail
43 .\"     Replaced the term "lease contestant" by "lease breaker"
44 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
45 .\"     Added notes on capability requirements
46 .\" Modified 2004-12-08, added O_NOATIME after note from Martin Pool
47 .\" 2004-12-10, mtk, noted F_GETOWN bug after suggestion from aeb.
48 .\" 2005-04-08 Jamie Lokier <jamie@shareable.org>, mtk
49 .\"     Described behavior of F_SETOWN/F_SETSIG in
50 .\"     multithreaded processes, and generally cleaned
51 .\"     up the discussion of F_SETOWN.
52 .\" 2005-05-20, Johannes Nicolai <johannes.nicolai@hpi.uni-potsdam.de>,
53 .\"     mtk: Noted F_SETOWN bug for socket file descriptor in Linux 2.4
54 .\"     and earlier.  Added text on permissions required to send signal.
55 .\" 2009-09-30, Michael Kerrisk
56 .\"     Note obsolete F_SETOWN behavior with threads.
57 .\"     Document F_SETOWN_EX and F_GETOWN_EX
58 .\"
59 .\" Japanese Version Copyright (c) 1996 Takeshi Ueno
60 .\" and Copyright (c) 2005, 2006, 2008 Akihiro MOTOKI
61 .\"
62 .\" Translated 1996-07-03, Takeshi Ueno <tueno@vio.co.jp>
63 .\" Modified 1998-09-10, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
64 .\" Modified 1999-08-14, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
65 .\" Updated & Modified 2001-04-03, Yuichi SATO <ysato@h4.dion.ne.jp>
66 .\" Updated & Modified 2005-03-15, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
67 .\" Updated & Modified 2005-04-22, Akihiro MOTOKI
68 .\" Updated & Modified 2005-10-14, Akihiro MOTOKI
69 .\" Updated & Modified 2005-11-19, Akihiro MOTOKI, LDP v2.14
70 .\" Updated 2006-04-16, Akihiro MOTOKI, LDP v2.29
71 .\" Updated 2008-02-11, Akihiro MOTOKI, LDP v2.77
72 .\" Updated 2008-09-19, Akihiro MOTOKI, LDP v3.09
73 .\" Updated 2010-04-23, Akihiro MOTOKI, LDP v3.24
74 .\"
75 .\"WORD:        asynchronous I/O        非同期 I/O
76 .\"WORD:        descriptor              ディスクリプタ
77 .\"WORD:        open file description   オープンファイル記述
78 .\"WORD:        feature test macro      機能検査マクロ
79 .\"WORD:        I/O availability signal I/O が利用可能になったことを示すシグナル
80 .\"
81 .TH FCNTL 2 2009-10-17 "Linux" "Linux Programmer's Manual"
82 .\"O .SH NAME
83 .SH 名前
84 .\"O fcntl \- manipulate file descriptor
85 fcntl \- ファイルディスクリプタの操作を行う
86 .\"O .SH SYNOPSIS
87 .SH 書式
88 .nf
89 .B #include <unistd.h>
90 .B #include <fcntl.h>
91 .sp
92 .BI "int fcntl(int " fd ", int " cmd ", ... /* " arg " */ );"
93 .fi
94 .\"O .SH DESCRIPTION
95 .SH 説明
96 .\"O .BR fcntl ()
97 .\"O performs one of the operations described below on the open file descriptor
98 .\"O .IR fd .
99 .\"O The operation is determined by
100 .\"O .IR cmd .
101 .BR fcntl ()
102 は、オープンされたファイルディスクリプタ
103 .I fd
104 に関して下記の操作を行う。操作は
105 .I cmd
106 によって決まる:
107
108 .\"O .BR fcntl ()
109 .\"O can take an optional third argument.
110 .\"O Whether or not this argument is required is determined by
111 .\"O .IR cmd .
112 .\"O The required argument type is indicated in parentheses after each
113 .\"O .I cmd
114 .\"O name (in most cases, the required type is
115 .\"O .IR long ,
116 .\"O and we identify the argument using the name
117 .\"O .IR arg ),
118 .\"O or
119 .\"O .I void
120 .\"O is specified if the argument is not required.
121 .BR fcntl ()
122 はオプションとして第三引き数をとることができる。
123 第三引き数が必要かどうかは
124 .I cmd
125 により決まる。
126 必要な引き数の型は
127 .I cmd
128 名の後ろの括弧内で指定されている
129 (ほとんどの場合、必要な型は
130 .I long
131 であり、この引き数を表すのに
132 .I arg
133 という名前を使っている)。
134 引き数が必要ない場合には
135 .I void
136 が指定されている。
137 .\"O .SS "Duplicating a file descriptor"
138 .SS "ファイルディスクリプタの複製"
139 .TP
140 .BR F_DUPFD " (\fIlong\fP)"
141 .\"O Find the lowest numbered available file descriptor
142 .\"O greater than or equal to
143 .\"O .I arg
144 .\"O and make it be a copy of
145 .\"O .IR fd .
146 .\"O This is different from
147 .\"O .BR dup2 (2),
148 .\"O which uses exactly the descriptor specified.
149 利用可能なファイルディスクリプタのうち、
150 .I arg
151 以上で最小のものを探し、
152 .I fd
153 のコピーとする。これは別の形の
154 .BR dup2 (2)
155 である。
156 .BR dup2 (2)
157 では指定されたディスクリプタが使われる点が違う。
158 .IP
159 .\"O On success, the new descriptor is returned.
160 成功すると、新しいディスクリプタが返される。
161 .IP
162 .\"O See
163 .\"O .BR dup (2)
164 .\"O for further details.
165 詳細は
166 .BR dup (2)
167 を参照のこと。
168 .TP
169 .\"O .BR F_DUPFD_CLOEXEC " (\fIlong\fP; since Linux 2.6.24)"
170 .BR F_DUPFD_CLOEXEC " (\fIlong\fP; Linux 2.6.24 以降)"
171 .\"O As for
172 .\"O .BR F_DUPFD ,
173 .\"O but additionally set the
174 .\"O close-on-exec flag for the duplicate descriptor.
175 .B F_DUPFD
176 と同様だが、それに加えて複製されたディスクリプタに対して
177 close-on-exec フラグをセットする。
178 .\"O Specifying this flag permits a program to avoid an additional
179 .\"O .BR fcntl ()
180 .\"O .B F_SETFD
181 .\"O operation to set the
182 .\"O .B FD_CLOEXEC
183 .\"O flag.
184 このフラグを指定することで、プログラムは
185 .B FD_CLOEXEC
186 フラグをセットするために
187 .BR fcntl ()
188
189 .B F_SETFD
190 操作を追加で行う必要がなくなる。
191 .\"O For an explanation of why this flag is useful,
192 .\"O see the description of
193 .\"O .B O_CLOEXEC
194 .\"O in
195 .\"O .BR open (2).
196 このフラグがなぜ有用かについては、
197 .BR open (2)
198
199 .B O_CLOEXEC
200 の説明を参照のこと。
201 .\"O .SS "File descriptor flags"
202 .SS "ファイルディスクリプタ・フラグ"
203 .\"O The following commands manipulate the flags associated with
204 .\"O a file descriptor.
205 .\"O Currently, only one such flag is defined:
206 .\"O .BR FD_CLOEXEC ,
207 .\"O the close-on-exec flag.
208 .\"O If the
209 .\"O .B FD_CLOEXEC
210 .\"O bit is 0, the file descriptor will remain open across an
211 .\"O .BR execve (2),
212 .\"O otherwise it will be closed.
213 以下のコマンドを使って、ファイルディスクリプタに関連するフラグ
214 を操作することができる。
215 現在のところ、定義されているフラグは一つだけである:
216 .B FD_CLOEXEC
217 (close-on-exec フラグ)。
218 .B FD_CLOEXEC
219 ビットが 0 なら、ファイルディスクリプタは
220 .BR execve (2)
221 を行ってもオープンされたままだが、そうでない場合はクローズされる。
222 .TP
223 .BR F_GETFD " (\fIvoid\fP)"
224 .\"O Read the file descriptor flags;
225 .\"O .I arg
226 .\"O is ignored.
227 ファイルディスクリプタ・フラグを読み出す。
228 .I arg
229 は無視される。
230 .TP
231 .BR F_SETFD " (\fIlong\fP)"
232 .\"O Set the file descriptor flags to the value specified by
233 .\"O .IR arg .
234 ファイルディスクリプタ・フラグに
235 .I arg
236 で指定した値を設定する。
237 .\"O .SS "File status flags"
238 .SS "ファイル状態フラグ"
239 .\"O Each open file description has certain associated status flags,
240 .\"O initialized by
241 .\"O .BR open (2)
242 .\"O .\" or
243 .\"O .\" .BR creat (2),
244 .\"O and possibly modified by
245 .\"O .BR fcntl ().
246 .\"O Duplicated file descriptors
247 .\"O (made with
248 .\"O .BR dup (2),
249 .\"O .BR fcntl (F_DUPFD),
250 .\"O .BR fork (2),
251 .\"O etc.) refer to the same open file description, and thus
252 .\"O share the same file status flags.
253 オープンファイル記述 (open file description) には、
254 ファイル記述毎に設定される状態フラグがいくつかある。これらのフラグは
255 .BR open (2)
256 .\" や
257 .\" .BR creat (2)
258 によって初期化され、
259 .BR fcntl (2)
260 により変更することもできる。これらは、
261 .RB ( dup (2),
262 .BR fcntl (F_DUPFD),
263 .BR fork (2)
264 などで) 複製されたファイルディスクリプタ同士は
265 同じオープンファイル記述を参照する。
266 そのため、
267 同じファイル状態フラグが共有される。
268
269 .\"O The file status flags and their semantics are described in
270 .\"O .BR open (2).
271 ファイル状態フラグとその意味は
272 .BR open (2)
273 で説明されている。
274 .TP
275 .BR F_GETFL " (\fIvoid\fP)"
276 .\"O Read the file status flags;
277 .\"O .I arg
278 .\"O is ignored.
279 ファイル状態フラグを読み出す。
280 .I arg
281 は無視される。
282 .TP
283 .BR F_SETFL " (\fIlong\fP)"
284 .\"O Set the file status flags to the value specified by
285 .\"O .IR arg .
286 .\"O File access mode
287 .\"O .RB ( O_RDONLY ", " O_WRONLY ", " O_RDWR )
288 .\"O and file creation flags
289 .\"O (i.e.,
290 .\"O .BR O_CREAT ", " O_EXCL ", " O_NOCTTY ", " O_TRUNC )
291 .\"O in
292 .\"O .I arg
293 .\"O are ignored.
294 ファイル状態フラグに
295 .I arg
296 で指定された値を設定する。
297 .I arg
298 のうち、ファイルのアクセスモード
299 .RB ( O_RDONLY ", " O_WRONLY ", " O_RDWR )
300 とファイル作成フラグ (すなわち
301 .BR O_CREAT ", " O_EXCL ", " O_NOCTTY ", " O_TRUNC )
302 に関するビットは無視される。
303 .\"O On Linux this command can only change the
304 .\"O .BR O_APPEND ,
305 .\"O .BR O_ASYNC ,
306 .\"O .BR O_DIRECT ,
307 .\"O .BR O_NOATIME ,
308 .\"O and
309 .\"O .B O_NONBLOCK
310 .\"O flags.
311 Linux では、このコマンドで変更できるのは
312 .BR O_APPEND ,
313 .BR O_ASYNC ,
314 .BR O_DIRECT ,
315 .BR O_NOATIME ,
316 .B O_NONBLOCK
317 フラグだけである。
318 .\"O .\" FIXME . According to POSIX.1-2001, O_SYNC should also be modifiable
319 .\"O .\" via fcntl(2), but currently Linux does not permit this
320 .\"O .\" See http://bugzilla.kernel.org/show_bug.cgi?id=5994
321 .\" FIXME . POSIX.1-2001 によると、 O_SYNC も fcntl(2) で変更できるべきだが、
322 .\" 現在のところ Linux では許可されていない。
323 .\" http://bugzilla.kernel.org/show_bug.cgi?id=5994 参照
324 .\"O .SS "Advisory locking"
325 .SS "アドバイザリ・ロック"
326 .\"O .BR F_GETLK ", " F_SETLK " and " F_SETLKW
327 .\"O are used to acquire, release, and test for the existence of record
328 .\"O locks (also known as file-segment or file-region locks).
329 .\"O The third argument,
330 .\"O .IR lock ,
331 .\"O is a pointer to a structure that has at least the following fields
332 .\"O (in unspecified order).
333 .BR F_GETLK ", " F_SETLK ", " F_SETLKW
334 は、レコード・ロックの獲得/解放/テストのために使用する
335 (レコード・ロックはファイルセグメント・ロックや
336 ファイル領域ロックとも呼ばれる)。
337 三番目の引き数
338 .I lock
339 は、以下に示すフィールドを含む構造体へのポインタである
340 (フィールドの順序は関係なく、構造体に他のフィールドがあってもよい)。
341 .in +4n
342 .nf
343 .sp
344 struct flock {
345     ...
346     short l_type;    /* Type of lock: F_RDLCK,
347                         F_WRLCK, F_UNLCK */
348     short l_whence;  /* How to interpret l_start:
349                         SEEK_SET, SEEK_CUR, SEEK_END */
350     off_t l_start;   /* Starting offset for lock */
351     off_t l_len;     /* Number of bytes to lock */
352     pid_t l_pid;     /* PID of process blocking our lock
353                         (F_GETLK only) */
354     ...
355 };
356 .fi
357 .in
358 .P
359 .\"O The
360 .\"O .IR l_whence ", " l_start ", and " l_len
361 .\"O fields of this structure specify the range of bytes we wish to lock.
362 .\"O Bytes past the end of the file may be locked,
363 .\"O but not bytes before the start of the file.
364 この構造体の
365 .IR l_whence ", " l_start ", " l_len
366 フィールドで、ロックを行いたいバイト範囲を指定する。
367 ファイルの末尾より後ろのバイトをロックすることはできるが、
368 ファイルの先頭より前のバイトをロックすることはできない。
369
370 .\"O .I l_start
371 .\"O is the starting offset for the lock, and is interpreted
372 .\"O relative to either:
373 .\"O the start of the file (if
374 .\"O .I l_whence
375 .\"O is
376 .\"O .BR SEEK_SET );
377 .\"O the current file offset (if
378 .\"O .I l_whence
379 .\"O is
380 .\"O .BR SEEK_CUR );
381 .\"O or the end of the file (if
382 .\"O .I l_whence
383 .\"O is
384 .\"O .BR SEEK_END ).
385 .\"O In the final two cases,
386 .\"O .I l_start
387 .\"O can be a negative number provided the
388 .\"O offset does not lie before the start of the file.
389 .I l_start
390 はロックを行う領域の開始オフセットである。
391 その意味は
392 .I l_whence
393 により異なる:
394 .I l_whence
395
396 .B SEEK_SET
397 の場合はファイルの先頭からのオフセット、
398 .I l_whence
399
400 .B SEEK_CUR
401 の場合は現在のファイルオフセットからのオフセット、
402 .I l_whence
403
404 .B SEEK_END
405 の場合はファイルの末尾からのオフセットと解釈される。
406 後ろの2つの場合には、
407 ファイルの先頭より前にならない範囲で、
408 .I l_start
409 に負の値を指定することができる。
410
411 .\"O .I l_len
412 .\"O specifies the number of bytes to be locked.
413 .\"O If
414 .\"O .I l_len
415 .\"O is positive, then the range to be locked covers bytes
416 .\"O .I l_start
417 .\"O up to and including
418 .\"O .IR l_start + l_len \- 1 .
419 .\"O Specifying 0 for
420 .\"O .I l_len
421 .\"O has the special meaning: lock all bytes starting at the
422 .\"O location specified by
423 .\"O .IR l_whence " and " l_start
424 .\"O through to the end of file, no matter how large the file grows.
425 .I l_len
426 はロックしたいバイト数を示す。
427 .I l_len
428 が正の場合、ロックされるバイト範囲は
429 .I l_start
430 以上
431 .IR l_start + l_len \- 1
432 以下となる。
433 .I l_len
434 に 0 を指定した場合は特別な意味を持つ:
435 .IR l_whence " and " l_start
436 で指定される位置からファイルの末尾までの全てのバイトをロックする
437 (ファイルがどんなに大きくなったとしてもファイルの末尾までロックする)。
438
439 .\"O POSIX.1-2001 allows (but does not require)
440 .\"O an implementation to support a negative
441 .\"O .I l_len
442 .\"O value; if
443 .\"O .I l_len
444 .\"O is negative, the interval described by
445 .\"O .I lock
446 .\"O covers bytes
447 .\"O .IR l_start + l_len
448 .\"O up to and including
449 .\"O .IR l_start \-1.
450 .\"O This is supported by Linux since kernel versions 2.4.21 and 2.5.49.
451 POSIX.1-2001 では、負の値の
452 .I l_len
453 をサポートする実装を認めている (必須ではない)。
454 .I l_len
455 が負の場合、ロックされるバイト範囲は
456 .IR l_start + l_len
457 以上
458 .IR l_start \-1
459 以下となる。
460 この動作はカーネル 2.4.21 以降および 2.5.49 以降の Linux で
461 サポートされている。
462
463 .\"O The
464 .\"O .I l_type
465 .\"O field can be used to place a read
466 .\"O .RB ( F_RDLCK )
467 .\"O or a write
468 .\"O .RB ( F_WRLCK )
469 .\"O lock on a file.
470 .\"O Any number of processes may hold a read lock (shared lock)
471 .\"O on a file region, but only one process may hold a write lock
472 .\"O (exclusive lock).
473 .\"O An exclusive lock excludes all other locks,
474 .\"O both shared and exclusive.
475 .I l_type
476 フィールドは、ファイルに対して読み出しロック
477 .RB ( F_RDLCK )
478 と書き込みロック
479 .RB ( F_WRLCK )
480 のどちらを
481 設定するかを指定する。
482 ファイルのある領域に対して、読み出しロック (共有ロック) を保持できる
483 プロセス数に制限はないが、書き込みロック (排他ロック) を保持できる
484 のは一つのプロセスだけである。排他ロックを設定すると、(共有ロックか
485 排他ロックにかかわらず) 他のロックは何も設定できない。
486 .\"O A single process can hold only one type of lock on a file region;
487 .\"O if a new lock is applied to an already-locked region,
488 .\"O then the existing lock is converted to the new lock type.
489 .\"O (Such conversions may involve splitting, shrinking, or coalescing with
490 .\"O an existing lock if the byte range specified by the new lock does not
491 .\"O precisely coincide with the range of the existing lock.)
492 一つのプロセスは、ファイルのある領域に対して一種類のロックしか保持できない。
493 新規のロックがロックが設定されている領域に対して適用されると、既存のロック
494 は新規のロックの種別に変換される
495 (新規のロックで指定されたバイト範囲が既存ロックの範囲と一致する場合以外では、
496 変換の過程で既存のロックの分割、縮小、結合が行われることがある)。
497 .TP
498 .BR F_SETLK " (\fIstruct flock *\fP)"
499 .\"O Acquire a lock (when
500 .\"O .I l_type
501 .\"O is
502 .\"O .B F_RDLCK
503 .\"O or
504 .\"O .BR F_WRLCK )
505 .\"O or release a lock (when
506 .\"O .I l_type
507 .\"O is
508 .\"O .BR F_UNLCK )
509 .\"O on the bytes specified by the
510 .\"O .IR l_whence ", " l_start ", and " l_len
511 .\"O fields of
512 .\"O .IR lock .
513 .RI ( l_type
514
515 .B F_RDLCK
516
517 .B F_WRLCK
518 の場合は) ロックの獲得を、
519 .RB ( F_UNLCK
520 の場合は) ロックの解放を、
521 .I flock
522 構造体のフィールド
523 .IR l_whence ", " l_start ", " l_len
524 で指定された範囲のバイトに対して行う。
525 .\"O If a conflicting lock is held by another process,
526 .\"O this call returns \-1 and sets
527 .\"O .I errno
528 .\"O to
529 .\"O .B EACCES
530 .\"O or
531 .\"O .BR EAGAIN .
532 指定されたロックが他のプロセスが設定しているロックと衝突する場合は、
533 \-1 を返し、
534 .I errno
535
536 .B EACCES
537
538 .B EAGAIN
539 を設定する。
540 .TP
541 .BR F_SETLKW " (\fIstruct flock *\fP)"
542 .\"O As for
543 .\"O .BR F_SETLK ,
544 .\"O but if a conflicting lock is held on the file, then wait for that
545 .\"O lock to be released.
546 .B F_SETLK
547 と同様だが、こちらではそのファイルに対して衝突するロックが
548 適用されていた場合に、そのロックが解放されるのを待つ点が異なる。
549 .\"O If a signal is caught while waiting, then the call is interrupted
550 .\"O and (after the signal handler has returned)
551 .\"O returns immediately (with return value \-1 and
552 .\"O .I errno
553 .\"O set to
554 .\"O .BR EINTR ;
555 .\"O see
556 .\"O .BR signal (7)).
557 待っている間にシグナルを受けた場合は、システムコールは中断され、
558 (シグナルハンドラが戻った直後に) 返り値 \-1 を返す (また
559 .I errno
560
561 .B EINTR
562 が設定される;
563 .BR signal (7)
564 参照)。
565 .TP
566 .BR F_GETLK " (\fIstruct flock *\fP)"
567 .\"O On input to this call,
568 .\"O .I lock
569 .\"O describes a lock we would like to place on the file.
570 このコールの呼び出し時には、
571 .I lock
572 にはそのファイルに適用しようとするロックに関する情報が入っている。
573 .\"O If the lock could be placed,
574 .\"O .BR fcntl ()
575 .\"O does not actually place it, but returns
576 .\"O .B F_UNLCK
577 .\"O in the
578 .\"O .I l_type
579 .\"O field of
580 .\"O .I lock
581 .\"O and leaves the other fields of the structure unchanged.
582 ロックを適用できる場合には、
583 .BR fcntl ()
584 は実際にはロックを行わず、構造体
585 .I lock
586
587 .I l_type
588 フィールドに
589 .B F_UNLCK
590 を設定し、他のフィールドは変更せずに、復帰する。
591 .\"O If one or more incompatible locks would prevent
592 .\"O this lock being placed, then
593 .\"O .BR fcntl ()
594 .\"O returns details about one of these locks in the
595 .\"O .IR l_type ", " l_whence ", " l_start ", and " l_len
596 .\"O fields of
597 .\"O .I lock
598 .\"O and sets
599 .\"O .I l_pid
600 .\"O to be the PID of the process holding that lock.
601 違う種別のロックが (一つもしくは複数) 適用されていて
602 ロックを適用できないような場合には、
603 .BR fcntl ()
604 は、原因となったロックの一つについての詳細情報を構造体
605 .I lock
606 のフィールド
607 .IR l_type ", " l_whence ", " l_start ", " l_len
608 に格納し、また
609 .I l_pid
610 にロックを保持しているプロセスの PID を設定して、復帰する。
611 .P
612 .\"O In order to place a read lock,
613 .\"O .I fd
614 .\"O must be open for reading.
615 .\"O In order to place a write lock,
616 .\"O .I fd
617 .\"O must be open for writing.
618 .\"O To place both types of lock, open a file read-write.
619 読み出しロックを適用するには、
620 .I fd
621 は読み出し用にオープンされていなければならない。
622 書き込みロックを適用するには、
623 .I fd
624 は書き込み用にオープンされていなければならない。
625 読み書き両方のロックを適用するには、読み書き両用で
626 ファイルをオープンしなければならない。
627 .P
628 .\"O As well as being removed by an explicit
629 .\"O .BR F_UNLCK ,
630 .\"O record locks are automatically released when the process
631 .\"O terminates or if it closes
632 .\"O .I any
633 .\"O file descriptor referring to a file on which locks are held.
634 レコードのロックは、
635 .B F_UNLCK
636 により明示的に削除されるだけでなく、
637 プロセスが終了したときや、ロックが適用されているファイルを参照している
638 ファイルディスクリプタのいずれかがクローズされた場合にも解放される。
639 このロックの解放は自動的に行われる。
640 .\"O .\" (Additional file descriptors referring to the same file
641 .\"O .\" may have been obtained by calls to
642 .\"O .\" .BR open "(2), " dup "(2), " dup2 "(2), or " fcntl ().)
643 .\" .RB ( open "(2), " dup "(2), " dup2 "(2), " fcntl ()
644 .\" の呼び出しによって同じファイルを参照するファイルディスクリプタが
645 .\" 他にもできているかもしれない)
646 .\"O This is bad: it means that a process can lose the locks on
647 .\"O a file like
648 .\"O .I /etc/passwd
649 .\"O or
650 .\"O .I /etc/mtab
651 .\"O when for some reason a library function decides to open, read
652 .\"O and close it.
653 この動作はまずい: あるプロセスが
654 .I /etc/passwd
655
656 .I /etc/mtab
657 といったファイルにロックを適用しているときに、
658 あるライブラリ関数が何かの理由で同じファイルを open, read, close
659 すると、そのファイルへのロックが失われることになる。
660 .P
661 .\"O Record locks are not inherited by a child created via
662 .\"O .BR fork (2),
663 .\"O but are preserved across an
664 .\"O .BR execve (2).
665 レコードのロックは
666 .BR fork (2)
667 で作成された子プロセスには継承されないが、
668 .BR execve (2)
669 の前後では保存される。
670 .P
671 .\"O Because of the buffering performed by the
672 .\"O .BR stdio (3)
673 .\"O library, the use of record locking with routines in that package
674 .\"O should be avoided; use
675 .\"O .BR read (2)
676 .\"O and
677 .\"O .BR write (2)
678 .\"O instead.
679 .BR stdio (3)
680 ではバッファリングが行われるので、
681 stdio 関連の関数ではレコードのロックの使用は回避される;
682 代わりに
683 .BR read (2)
684
685 .BR write (2)
686 を使用すること。
687 .\"O .SS "Mandatory locking"
688 .SS "強制ロック (mandatory locking)"
689 .\"O (Non-POSIX.)
690 .\"O The above record locks may be either advisory or mandatory,
691 .\"O and are advisory by default.
692 上述のロックにはアドバイザリ・ロック (advisory lock) と強制ロック (mandatory
693 lock) の二種類があるが、デフォルトではアドバイザリ・ロックとなる。
694
695 .\"O Advisory locks are not enforced and are useful only between
696 .\"O cooperating processes.
697 アドバイザリ・ロックに強制力はなく、協調して動作するプロセス間でのみ
698 有効である。
699
700 .\"O Mandatory locks are enforced for all processes.
701 強制ロックは全てのプロセスに対して効果がある。
702 .\"O If a process tries to perform an incompatible access (e.g.,
703 .\"O .BR read (2)
704 .\"O or
705 .\"O .BR write (2))
706 .\"O on a file region that has an incompatible mandatory lock,
707 .\"O then the result depends upon whether the
708 .\"O .B O_NONBLOCK
709 .\"O flag is enabled for its open file description.
710 .\"O If the
711 .\"O .B O_NONBLOCK
712 .\"O flag is not enabled, then
713 .\"O system call is blocked until the lock is removed
714 .\"O or converted to a mode that is compatible with the access.
715 .\"O If the
716 .\"O .B O_NONBLOCK
717 .\"O flag is enabled, then the system call fails with the error
718 .\"O .BR EAGAIN .
719 あるプロセスが互換性のない強制ロックが適用されたファイル領域に対して
720 .RB ( read (2)
721
722 .BR write (2)
723 により) 互換性のないアクセスを実行しようとした場合、
724 アクセスの結果は
725 そのファイルのオープンファイル記述で
726 .B O_NONBLOCK
727 フラグが有効になっているかにより決まる。
728 .B O_NONBLOCK
729 フラグが有効になっていないときは、ロックが削除されるか、
730 ロックがアクセスと互換性のあるモードに変換されるまで、
731 システムコールは停止 (block) される。
732 .B O_NONBLOCK
733 フラグが有効になっているときは、システムコールはエラー
734 .B EAGAIN
735 で失敗する。
736
737 .\"O To make use of mandatory locks, mandatory locking must be enabled
738 .\"O both on the file system that contains the file to be locked,
739 .\"O and on the file itself.
740 .\"O Mandatory locking is enabled on a file system
741 .\"O using the "\-o mand" option to
742 .\"O .BR mount (8),
743 .\"O or the
744 .\"O .B MS_MANDLOCK
745 .\"O flag for
746 .\"O .BR mount (2).
747 .\"O Mandatory locking is enabled on a file by disabling
748 .\"O group execute permission on the file and enabling the set-group-ID
749 .\"O permission bit (see
750 .\"O .BR chmod (1)
751 .\"O and
752 .\"O .BR chmod (2)).
753 強制ロックを使用するためには、ロック対象のファイルが含まれるファイルシステム
754 と、ロック対象のファイル自身の両方について、強制ロックが有効になっていなけれ
755 ばならない。ファイルシステムについて強制ロックを有効にするには、
756 .BR mount (8)
757 に "\-o mand" オプションを渡すか、
758 .BR mount (2)
759
760 .B MS_MANDLOCK
761 フラグを指定する。ファイルについて強制ロックを有効にするには、
762 そのファイルのグループ実行許可 (group execute permission) を無効とし、
763 かつ set-group-ID 許可ビットを有効にする
764 .RB ( chmod (1)
765
766 .BR chmod (2)
767 を参照)。
768
769 .\"O The Linux implementation of mandatory locking is unreliable.
770 .\"O See BUGS below.
771 Linux の強制ロックの実装は信頼性に欠けるものである。
772 下記の「バグ」の節を参照のこと。
773 .\"O .SS "Managing signals"
774 .SS "シグナルの管理"
775 .\"O .BR F_GETOWN ,
776 .\"O .BR F_SETOWN ,
777 .\"O .BR F_GETOWN_EX ,
778 .\"O .BR F_SETOWN_EX ,
779 .\"O .BR F_GETSIG
780 .\"O and
781 .\"O .B F_SETSIG
782 .\"O are used to manage I/O availability signals:
783 .BR F_GETOWN ,
784 .BR F_SETOWN ,
785 .BR F_GETOWN_EX ,
786 .BR F_SETOWN_EX ,
787 .BR F_GETSIG ,
788 .B F_SETSIG
789 は、I/O が利用可能になったことを示すシグナルを管理するために使用される。
790 .TP
791 .BR F_GETOWN " (\fIvoid\fP)"
792 .\"O Return (as the function result)
793 .\"O the process ID or process group currently receiving
794 .\"O .B SIGIO
795 .\"O and
796 .\"O .B SIGURG
797 .\"O signals for events on file descriptor
798 .\"O .IR fd .
799 .\"O Process IDs are returned as positive values;
800 .\"O process group IDs are returned as negative values (but see BUGS below).
801 .\"O .I arg
802 .\"O is ignored.
803 ファイルディスクリプタ
804 .I fd
805 のイベントに対するシグナル
806 .B SIGIO
807 および
808 .B SIGURG
809 を受けているプロセスのプロセスID かプロセスグループを
810 (関数の結果として) 返す。
811 プロセスID は正の値として返される。
812 プロセスグループID は負の値として返される (下記のバグの章を参照)。
813 .I arg
814 は無視される。
815 .TP
816 .BR F_SETOWN " (\fIlong\fP)"
817 .\"O Set the process ID or process group ID that will receive
818 .\"O .B SIGIO
819 .\"O and
820 .\"O .B SIGURG
821 .\"O signals for events on file descriptor
822 .\"O .IR fd
823 .\"O to the ID given in
824 .\"O .IR arg .
825 .\"O A process ID is specified as a positive value;
826 .\"O a process group ID is specified as a negative value.
827 ファイルディスクリプタ
828 .I fd
829 のイベント発生を知らせるシグナル
830 .B SIGIO
831
832 .B SIGURG
833 を受けるプロセスの
834 プロセス ID またはプロセスグループID を
835 .I arg
836 で指定された ID に設定する。
837 プロセスID は正の値として指定し、
838 プロセスグループID は負の値として指定する。
839 .\"O Most commonly, the calling process specifies itself as the owner
840 .\"O (that is,
841 .\"O .I arg
842 .\"O is specified as
843 .\"O .BR getpid (2)).
844 ほとんどの場合、呼び出し元プロセスは所有者として自分自身を指定する
845 (つまり
846 .I arg
847
848 .BR getpid (2)
849 を指定する)。
850
851 .\"O .\" From glibc.info:
852 .\" glibc.info より:
853 .\"O If you set the
854 .\"O .B O_ASYNC
855 .\"O status flag on a file descriptor by using the
856 .\"O .B F_SETFL
857 .\"O command of
858 .\"O .BR fcntl (),
859 .\"O a
860 .\"O .B SIGIO
861 .\"O signal is sent whenever input or output becomes possible
862 .\"O on that file descriptor.
863 .\"O .B F_SETSIG
864 .\"O can be used to obtain delivery of a signal other than
865 .\"O .BR SIGIO .
866 .BR fcntl ()
867
868 .B F_SETFL
869 コマンドを使用してファイルディスクリプタに
870 .B O_ASYNC
871 状態フラグを設定した場合には、そのファイルディスクリプタへの
872 入出力が可能になる度に
873 .B SIGIO
874 シグナルが送られる。
875 .B F_SETSIG
876
877 .B SIGIO
878 以外の別のシグナルの配送を受けられるように
879 するのにも使うことができる。
880 .\"O If this permission check fails, then the signal is
881 .\"O silently discarded.
882 許可 (permission) のチェックで失敗した場合には、
883 シグナルは黙って捨てられる。
884
885 .\"O Sending a signal to the owner process (group) specified by
886 .\"O .B F_SETOWN
887 .\"O is subject to the same permissions checks as are described for
888 .\"O .BR kill (2),
889 .\"O where the sending process is the one that employs
890 .\"O .B F_SETOWN
891 .\"O (but see BUGS below).
892 .B F_SETOWN
893 により指定された所有者のプロセス (またはプロセスグループ) に
894 シグナルを送る際には、
895 .BR kill (2)
896 に書かれているのと同じ許可のチェックが行われる。
897 このとき、シグナルを送信するプロセスは
898 .B F_SETOWN
899 を使ったプロセスである
900 (但し、下記の「バグ」の章を参照のこと)。
901
902 .\"O If the file descriptor
903 .\"O .I fd
904 .\"O refers to a socket,
905 .\"O .B F_SETOWN
906 .\"O also selects
907 .\"O the recipient of
908 .\"O .B SIGURG
909 .\"O signals that are delivered when out-of-band
910 .\"O data arrives on that socket.
911 .\"O .RB ( SIGURG
912 .\"O is sent in any situation where
913 .\"O .BR select (2)
914 .\"O would report the socket as having an "exceptional condition".)
915 ファイルディスクリプタがソケットを参照している場合は、
916 .B F_SETOWN
917 を使用して、ソケットに帯域外 (out-of-band) データが届いた時に
918 .B SIGURG
919 シグナルを配送する相手を選択することもできる
920 .RB ( SIGURG
921 が送られた場合には
922 .BR select (2)
923 がソケットが「特別な状態」にあると報告することだろう)。
924 .\"O .\" The following appears to be rubbish.  It doesn't seem to
925 .\"O .\" be true according to the kernel source, and I can write
926 .\"O .\" a program that gets a terminal-generated SIGIO even though
927 .\"O .\" it is not the foreground process group of the terminal.
928 .\"O .\" -- MTK, 8 Apr 05
929 .\"O .\"
930 .\"O .\" If the file descriptor
931 .\"O .\" .I fd
932 .\"O .\" refers to a terminal device, then SIGIO
933 .\"O .\" signals are sent to the foreground process group of the terminal.
934 .\" 以下の記述はゴミだろう。
935 .\" カーネルソースを見るとこの記述は間違っているようだし、
936 .\" プログラムを書いてみたところ、端末のフォアグランド・プロセスグループで
937 .\" なくても、端末が生成した SIGIO シグナルを受けとる。
938 .\" -- MTK, 8 Apr 05
939 .\"
940 .\" ファイルディスクリプタが端末デバイスを参照している場合には、
941 .\" SIGIO シグナルはその端末のフォアグランド・プロセスグループへと送られる。
942
943 .\"O The following was true in 2.6.x kernels up to and including
944 .\"O kernel 2.6.11:
945 バージョン 2.6.11 以前の 2.6.x カーネルでは、以下に示す動作であった。
946 .RS
947 .IP
948 .\"O If a nonzero value is given to
949 .\"O .B F_SETSIG
950 .\"O in a multithreaded process running with a threading library
951 .\"O that supports thread groups (e.g., NPTL),
952 .\"O then a positive value given to
953 .\"O .B F_SETOWN
954 .\"O has a different meaning:
955 .\"O .\" The relevant place in the (2.6) kernel source is the
956 .\"O .\" 'switch' in fs/fcntl.c::send_sigio_to_task() -- MTK, Apr 2005
957 .\"O instead of being a process ID identifying a whole process,
958 .\"O it is a thread ID identifying a specific thread within a process.
959 スレッドグループをサポートしているスレッドライブラリ (例えば NPTL) を
960 使って動作しているマルチスレッド・プロセスで
961 .B F_SETSIG
962 に 0 以外の値を指定した場合、
963 .B F_SETOWN
964 に正の値を渡すと、その意味が違ってくる:
965 .\" The relevant place in the (2.6) kernel source is the
966 .\" 'switch' in fs/fcntl.c::send_sigio_to_task() -- MTK, Apr 2005
967 プロセス全体を示すプロセスID ではなく、プロセス内の特定の
968 スレッドを示すスレッドID と解釈される。
969 .\"O Consequently, it may be necessary to pass
970 .\"O .B F_SETOWN
971 .\"O the result of
972 .\"O .BR gettid (2)
973 .\"O instead of
974 .\"O .BR getpid (2)
975 .\"O to get sensible results when
976 .\"O .B F_SETSIG
977 .\"O is used.
978 したがって、
979 .B F_SETSIG
980 を使う場合には、きちんと結果を受け取るには、
981 .B F_SETOWN
982 に渡す値を
983 .BR getpid (2)
984 ではなく
985 .BR gettid (2)
986 の返り値にする必要があるだろう。
987 .\"O (In current Linux threading implementations,
988 .\"O a main thread's thread ID is the same as its process ID.
989 .\"O This means that a single-threaded program can equally use
990 .\"O .BR gettid (2)
991 .\"O or
992 .\"O .BR getpid (2)
993 .\"O in this scenario.)
994 (現状の Linux スレッド実装では、メイン・スレッドのスレッドID は
995 そのスレッドのプロセスID と同じである。つまり、
996 シグナル・スレッドのプログラムではこの場合
997 .BR gettid (2)
998
999 .BR getpid (2)
1000 は全く同じように使うことができる。)
1001 .\"O Note, however, that the statements in this paragraph do not apply
1002 .\"O to the
1003 .\"O .B SIGURG
1004 .\"O signal generated for out-of-band data on a socket:
1005 .\"O this signal is always sent to either a process or a process group,
1006 .\"O depending on the value given to
1007 .\"O .BR F_SETOWN .
1008 .\"O .\" send_sigurg()/send_sigurg_to_task() bypasses
1009 .\"O .\" kill_fasync()/send_sigio()/send_sigio_to_task()
1010 .\"O .\" to directly call send_group_sig_info()
1011 .\"O .\"        -- MTK, Apr 2005 (kernel 2.6.11)
1012 ただし、注意すべき点として、この段落で述べたことは、
1013 ソケットの帯域外データが届いたときに生成される
1014 .B SIGURG
1015 シグナルにはあてはまらない。
1016 このシグナルは常にプロセスかプロセスグループに送られ、
1017 送信先は
1018 .B F_SETOWN
1019 に渡された値にしたがって決められる。
1020 .\" send_sigurg()/send_sigurg_to_task() bypasses
1021 .\" kill_fasync()/send_sigio()/send_sigio_to_task()
1022 .\" to directly call send_group_sig_info()
1023 .\"     -- MTK, Apr 2005 (kernel 2.6.11)
1024 .RE
1025 .IP
1026 .\"O The above behavior was accidentally dropped in Linux 2.6.12,
1027 .\"O and won't be restored.
1028 .\"O From Linux 2.6.32 onwards, use
1029 .\"O .BR F_SETOWN_EX
1030 .\"O to target
1031 .\"O .B SIGIO
1032 .\"O and
1033 .\"O .B SIGURG
1034 .\"O signals at a particular thread.
1035 上記の動作は、Linux 2.6.12 で図らずも削除され、
1036 元に戻されない予定である。
1037 Linux 2.6.32 以降で、特定のスレッド宛にシグナル
1038 .B SIGIO
1039
1040 .B SIGURG
1041 を送るには
1042 .B F_SETOWN_EX
1043 を使うこと。
1044 .TP
1045 .\"O .BR F_GETOWN_EX " (struct f_owner_ex *) (since Linux 2.6.32)"
1046 .BR F_GETOWN_EX " (struct f_owner_ex *) (Linux 2.6.32 以降)"
1047 .\"O Return the current file descriptor owner settings
1048 .\"O as defined by a previous
1049 .\"O .BR F_SETOWN_EX
1050 .\"O operation.
1051 .\"O The information is returned in the structure pointed to by
1052 .\"O .IR arg ,
1053 .\"O which has the following form:
1054 直前の
1055 .B F_SETOWN_EX
1056 操作で定義された現在のファイルディスクリプタの所有者設定
1057 を返す。情報は
1058 .I arg
1059 が指す構造体に格納されて返される。構造体は以下の通りである。
1060 .nf
1061 .in +4n
1062
1063 struct f_owner_ex {
1064     int   type;
1065     pid_t pid;
1066 };
1067
1068 .in
1069 .fi
1070 .\"O The
1071 .\"O .I type
1072 .\"O field will have one of the values
1073 .\"O .BR F_OWNER_TID ,
1074 .\"O .BR F_OWNER_PID ,
1075 .\"O or
1076 .\"O .BR F_OWNER_PGRP .
1077 .I type
1078 フィールドは、
1079 .B F_OWNER_TID ,
1080 .B F_OWNER_PID ,
1081 .B F_OWNER_PGRP
1082 のいずれか一つの値となる。
1083 .\"O The
1084 .\"O .I pid
1085 .\"O field is a positive integer representing a thread ID, process ID,
1086 .\"O or process group ID.
1087 .\"O See
1088 .\"O .B F_SETOWN_EX
1089 .\"O for more details.
1090 .I pid
1091 フィールドは、スレッド ID、プロセス ID、プロセスグループ ID を
1092 表す正の整数である。詳細は
1093 .B F_SETOWN_EX
1094 を参照。
1095 .TP
1096 .\"O .BR F_SETOWN_EX " (struct f_owner_ex *) (since Linux 2.6.32)"
1097 .BR F_SETOWN_EX " (struct f_owner_ex *) (Linux 2.6.32 以降)"
1098 .\"O This operation performs a similar task to
1099 .\"O .BR F_SETOWN .
1100 .\"O It allows the caller to direct I/O availability signals
1101 .\"O to a specific thread, process, or process group.
1102 この操作は
1103 .B F_SETOWN
1104 と同様の処理を行う。
1105 この操作を使うと、I/O が利用可能になったことを示すシグナルを、
1106 特定のスレッド、プロセス、プロセスグループに送ることができる
1107 ようになる。
1108 .\"O The caller specifies the target of signals via
1109 .\"O .IR arg ,
1110 .\"O which is a pointer to a
1111 .\"O .IR f_owner_ex
1112 .\"O structure.
1113 .\"O The
1114 .\"O .I type
1115 .\"O field has one of the following values, which define how
1116 .\"O .I pid
1117 .\"O is interpreted:
1118 呼び出し元は、
1119 .I arg
1120 経由でシグナルの配送先を指定する。
1121 .I arg
1122
1123 .I f_owner_ex
1124 構造体へのポインタである。
1125 .I type
1126 フィールドは以下のいずれかの値を取り、
1127 この値により
1128 .I pid
1129 がどのように解釈されるかが規定される。
1130 .RS
1131 .TP
1132 .BR F_OWNER_TID
1133 .\"O Send the signal to the thread whose thread ID
1134 .\"O (the value returned by a call to
1135 .\"O .BR clone (2)
1136 .\"O or
1137 .\"O .BR gettid (2))
1138 .\"O is specified in
1139 .\"O .IR pid .
1140 スレッド ID が
1141 .I pid
1142 で指定された値のスレッドにそのシグナルを送る
1143 (スレッド ID は
1144 .BR clone (2)
1145
1146 .BR gettid (2)
1147 の呼び出しで返される値である)。
1148 .TP
1149 .BR F_OWNER_PID
1150 .\"O Send the signal to the process whose ID
1151 .\"O is specified in
1152 .\"O .IR pid .
1153 ID が
1154 .I pid
1155 で指定された値のプロセスにそのシグナルを送る。
1156 .TP
1157 .BR F_OWNER_PGRP
1158 .\"O Send the signal to the process group whose ID
1159 .\"O is specified in
1160 .\"O .IR pid .
1161 .\"O (Note that, unlike with
1162 .\"O .BR F_SETOWN ,
1163 .\"O a process group ID is specified as a positive value here.)
1164 ID が
1165 .I pid
1166 で指定された値のプロセスグループにそのシグナルを送る。
1167 .RB ( F_SETOWN
1168 と異なり、プロセスグループ ID には正の値を指定する点に注意すること。)
1169 .RE
1170 .TP
1171 .BR F_GETSIG " (\fIvoid\fP)"
1172 .\"O Return (as the function result)
1173 .\"O the signal sent when input or output becomes possible.
1174 .\"O A value of zero means
1175 .\"O .B SIGIO
1176 .\"O is sent.
1177 .\"O Any other value (including
1178 .\"O .BR SIGIO )
1179 .\"O is the
1180 .\"O signal sent instead, and in this case additional info is available to
1181 .\"O the signal handler if installed with
1182 .\"O .BR SA_SIGINFO .
1183 .\"O .I arg
1184 .\"O is ignored.
1185 入力や出力が可能になった場合に送るシグナルを
1186 (関数の結果として) 返す。
1187 値ゼロは
1188 .B SIGIO
1189 を送ることを意味する。
1190 .RB ( SIGIO
1191 を含む) 他の値はいずれも、
1192 .B SIGIO
1193 の代わりに送るシグナル番号を表す。
1194 後者の場合、シグナルハンドラを
1195 .B SA_SIGINFO
1196 フラグ付きで設定すれば、ハンドラで追加の情報を得ることができる。
1197 .I arg
1198 は無視される。
1199 .TP
1200 .BR F_SETSIG " (\fIlong\fP)"
1201 .\"O Set the signal sent when input or output becomes possible
1202 .\"O to the value given in
1203 .\"O .IR arg .
1204 .\"O A value of zero means to send the default
1205 .\"O .B SIGIO
1206 .\"O signal.
1207 .\"O Any other value (including
1208 .\"O .BR SIGIO )
1209 .\"O is the signal to send instead, and in this case additional info
1210 .\"O is available to the signal handler if installed with
1211 .\"O .BR SA_SIGINFO .
1212 入力や出力が可能になった場合に送るシグナルを
1213 .I arg
1214 に指定された値に設定する。
1215 値ゼロは
1216 .B SIGIO
1217 を送ることを意味する。
1218 .RB ( SIGIO
1219 を含む) 他の値はいずれも、
1220 .B SIGIO
1221 の代わりに送るシグナル番号を表す。
1222 後者の場合、シグナルハンドラを
1223 .B SA_SIGINFO
1224 フラグ付きで設定すれば、
1225 ハンドラで追加の情報を得ることができる。
1226 .\"
1227 .\" The following was true only up until 2.6.11:
1228 .\"
1229 .\"O .\" Additionally, passing a nonzero value to
1230 .\"O .\" .B F_SETSIG
1231 .\"O .\" changes the signal recipient from a whole process to a specific thread
1232 .\"O .\" within a process.
1233 .\"O .\" See the description of
1234 .\"O .\" .B F_SETOWN
1235 .\"O .\" for more details.
1236 .\" また、
1237 .\" .B F_SETSIG
1238 .\" に 0 以外の値を渡すと、シグナルの受信者をプロセス全体から
1239 .\" プロセス内の特定のスレッドに変更される。詳細は
1240 .\" .B F_SETOWN
1241 .\" の説明を参照のこと。
1242
1243 .\"O By using
1244 .\"O .B F_SETSIG
1245 .\"O with a nonzero value, and setting
1246 .\"O .B SA_SIGINFO
1247 .\"O for the
1248 .\"O signal handler (see
1249 .\"O .BR sigaction (2)),
1250 .\"O extra information about I/O events is passed to
1251 .\"O the handler in a
1252 .\"O .I siginfo_t
1253 .\"O structure.
1254 .B F_SETSIG
1255 にゼロ以外の値を設定し、シグナルハンドラに
1256 .B SA_SIGINFO
1257 フラグを設定すると、
1258 .RB ( sigaction (2)
1259 を参照) I/O イベントに関する追加の情報が
1260 .I siginfo_t
1261 構造体でシグナルハンドラへ渡される。
1262 .\"O If the
1263 .\"O .I si_code
1264 .\"O field indicates the source is
1265 .\"O .BR SI_SIGIO ,
1266 .\"O the
1267 .\"O .I si_fd
1268 .\"O field gives the file descriptor associated with the event.
1269 .\"O Otherwise,
1270 .\"O there is no indication which file descriptors are pending, and you
1271 .\"O should use the usual mechanisms
1272 .\"O .RB ( select (2),
1273 .\"O .BR poll (2),
1274 .\"O .BR read (2)
1275 .\"O with
1276 .\"O .B O_NONBLOCK
1277 .\"O set etc.) to determine which file descriptors are available for I/O.
1278 .I si_code
1279 フィールドが示すシグナルの原因が
1280 .B SI_SIGIO
1281 である場合、
1282 .I si_fd
1283 フィールドにはイベントに対応するファイルディスクリプタが入っている。
1284 それ以外の場合は、どのファイルディスクリプタが利用可能かを示す情報は
1285 ないので、どのファイルディスクリプタで I/O が可能かを判断するためには
1286 通常の機構
1287 .RB ( select (2),
1288 .BR poll (2),
1289 .B O_NONBLOCK
1290 を設定した
1291 .BR read (2)
1292 など) を使用しなければならない。
1293
1294 .\"O By selecting a real time signal (value >=
1295 .\"O .BR SIGRTMIN ),
1296 .\"O multiple I/O events may be queued using the same signal numbers.
1297 .\"O (Queuing is dependent on available memory).
1298 .\"O Extra information is available
1299 .\"O if
1300 .\"O .B SA_SIGINFO
1301 .\"O is set for the signal handler, as above.
1302 リアルタイムシグナル (値が
1303 .B SIGRTMIN
1304 以上) を選択している場合は、
1305 同じシグナル番号を持つ複数の I/O イベントがキューに入ることがある
1306 (キューに入れるかどうかは利用可能なメモリに依存している)。
1307 上記と同様、 
1308 .B SA_SIGINFO
1309 が設定されている場合、シグナルハンドラのための追加の情報が得られる。
1310
1311 .\"O Note that Linux imposes a limit on the
1312 .\"O number of real-time signals that may be queued to a
1313 .\"O process (see
1314 .\"O .BR getrlimit (2)
1315 .\"O and
1316 .\"O .BR signal (7))
1317 .\"O and if this limit is reached, then the kernel reverts to
1318 .\"O delivering
1319 .\"O .BR SIGIO ,
1320 .\"O and this signal is delivered to the entire
1321 .\"O process rather than to a specific thread.
1322 .\" See fs/fcntl.c::send_sigio_to_task() (2.4/2.6) sources -- MTK, Apr 05
1323 以下の点に注意すること。
1324 Linux では一つのプロセスに対してキューに入れられるリアルタイム
1325 シグナルの数に上限が設けられており
1326 .RB ( getrlimit (2)
1327
1328 .BR signal (7)
1329 を参照)、この上限に達するとカーネルは
1330 .B SIGIO
1331 シグナルを配送する。この
1332 .B SIGIO
1333 シグナルは、指定されたスレッドではなくプロセス全体に送られる。
1334 .PP
1335 .\"O Using these mechanisms, a program can implement fully asynchronous I/O
1336 .\"O without using
1337 .\"O .BR select (2)
1338 .\"O or
1339 .\"O .BR poll (2)
1340 .\"O most of the time.
1341 これらの機構を使用することで、ほとんどの場合で
1342 .BR select (2)
1343
1344 .BR poll (2)
1345 を使用せずに完全な非同期 I/O を実装することができる。
1346 .PP
1347 .\"O The use of
1348 .\"O .BR O_ASYNC ,
1349 .\"O .BR F_GETOWN ,
1350 .\"O .B F_SETOWN
1351 .\"O is specific to BSD and Linux.
1352 .BR O_ASYNC ,
1353 .BR F_GETOWN ,
1354 .B F_SETOWN
1355 の使用は BSD と Linux に特有である。
1356 .\"O .BR F_GETOWN_EX ,
1357 .\"O .BR F_SETOWN_EX ,
1358 .\"O .BR F_GETSIG ,
1359 .\"O and
1360 .\"O .B F_SETSIG
1361 .\"O are Linux-specific.
1362 .\"O POSIX has asynchronous I/O and the
1363 .\"O .I aio_sigevent
1364 .\"O structure to achieve similar things; these are also available
1365 .\"O in Linux as part of the GNU C Library (Glibc).
1366 .BR F_GETOWN_EX ,
1367 .BR F_SETOWN_EX ,
1368 .BR F_GETSIG ,
1369 .B F_SETSIG
1370 は Linux 固有である。POSIX には、同様のことを行うために、非同期 I/O と
1371 .I aio_sigevent
1372 構造体がある。Linux では、GNU C ライブラリ (Glibc) の一部として
1373 これらも利用可能である。
1374 .\"O .SS Leases
1375 .SS "リース (leases)"
1376 .\"O .B F_SETLEASE
1377 .\"O and
1378 .\"O .B F_GETLEASE
1379 .\"O (Linux 2.4 onwards) are used (respectively) to establish a new lease,
1380 .\"O and retrieve the current lease, on the open file description
1381 .\"O referred to by the file descriptor
1382 .\"O .IR fd .
1383 (Linix 2.4 以降で利用可能)
1384 .B F_SETLEASE
1385 は、
1386 .I fd
1387 が参照するオープンファイル記述に対して新しいリースを設定するのに使用される。
1388 .B F_GETLEASE
1389 は、
1390 .I fd
1391 が参照するオープンファイル記述に対して設定されている
1392 現在のリースを取得するのに使用される。
1393 .\"O A file lease provides a mechanism whereby the process holding
1394 .\"O the lease (the "lease holder") is notified (via delivery of a signal)
1395 .\"O when a process (the "lease breaker") tries to
1396 .\"O .BR open (2)
1397 .\"O or
1398 .\"O .BR truncate (2)
1399 .\"O the file referred to by that file descriptor.
1400 ファイルのリースにより、
1401 あるプロセス ("lease breaker") がそのファイルディスクリプタが参照
1402 しているファイルに対して
1403 .BR open (2)
1404
1405 .BR truncate (2)
1406 を行おうとした際に、リースを保持しているプロセス ("lease holder") へ
1407 (シグナルの配送による) 通知が行われるという機構が提供される。
1408 .TP
1409 .BR F_SETLEASE " (\fIlong\fP)"
1410 .\"O Set or remove a file lease according to which of the following
1411 .\"O values is specified in the integer
1412 .\"O .IR arg :
1413 .I arg
1414 の内容に基いてファイルのリースの設定、削除を行う。整数
1415 .I arg
1416 には以下の値が指定できる:
1417
1418 .RS
1419 .TP
1420 .B F_RDLCK
1421 .\"O Take out a read lease.
1422 .\"O This will cause the calling process to be notified when
1423 .\"O the file is opened for writing or is truncated.
1424 .\"O .\" The following became true in kernel 2.6.10:
1425 .\"O .\" See the man-pages-2.09 Changelog for further info.
1426 .\"O A read lease can only be placed on a file descriptor that
1427 .\"O is opened read-only.
1428 読み出しリースを取得する。これにより、
1429 そのファイルが書き込み用にオープンされたり、ファイルが切り詰められた場合に、
1430 呼び出し元のプロセスに通知が行われるようになる。
1431 .\" 以下の内容はカーネル 2.6.10 で実装された。
1432 .\" より詳しい情報は man-pages-2.09 の Changelog を参照。
1433 読み出しリースを設定できるのは、読み出し専用でオープンされている
1434 ファイルディスクリプタに対してのみである。
1435 .TP
1436 .B F_WRLCK
1437 .\"O Take out a write lease.
1438 .\"O This will cause the caller to be notified when
1439 .\"O the file is opened for reading or writing or is truncated.
1440 .\"O A write lease may be placed on a file only if there are no
1441 .\"O other open file descriptors for the file.
1442 書き込みリースを取得する。これにより、
1443 (読み出し用か書き込み用にかかわらず) そのファイルがオープンされたり、
1444 ファイルが切り詰められた場合に、呼び出し元のプロセスに通知が行われるようになる。
1445 書き込みリースは、そのファイルに対するオープンされたファイルディスクリプタが
1446 他にない場合にのみ設定できる。
1447 .TP
1448 .B F_UNLCK
1449 .\"O Remove our lease from the file.
1450 そのファイルからリースを削除する。
1451 .RE
1452 .P
1453 .\"O Leases are associated with an open file description (see
1454 .\"O .BR open (2)).
1455 .\"O This means that duplicate file descriptors (created by, for example,
1456 .\"O .BR fork (2)
1457 .\"O or
1458 .\"O .BR dup (2))
1459 .\"O refer to the same lease, and this lease may be modified
1460 .\"O or released using any of these descriptors.
1461 .\"O Furthermore, the lease is released by either an explicit
1462 .\"O .B F_UNLCK
1463 .\"O operation on any of these duplicate descriptors, or when all
1464 .\"O such descriptors have been closed.
1465 リースはオープンファイル記述に対して関連付けられる
1466 .RB ( open (2)
1467 参照)。
1468 つまり、
1469 .RB ( fork (2)
1470
1471 .BR dup (2)
1472 などにより作成された) ファイルディスクリプタの複製は同じリースを参照し、
1473 複製も含めたどのファイルディスクリプタを使ってもこのリースを変更したり
1474 解放したりできる。
1475 また、これらのファイルディスクリプタのいずれかに対して
1476 .B F_UNLCK
1477 操作が明示的に実行された場合や、すべてのファイルディスクリプタが
1478 閉じられた場合にも、リースは解放される。
1479 .P
1480 .\"O Leases may only be taken out on regular files.
1481 .\"O An unprivileged process may only take out a lease on a file whose
1482 .\"O UID (owner) matches the file system UID of the process.
1483 .\"O A process with the
1484 .\"O .B CAP_LEASE
1485 .\"O capability may take out leases on arbitrary files.
1486 リースの取得は通常のファイル (regular file) に対してのみ可能である。
1487 非特権プロセスがリースを取得できるのは、UID (所有者) がプロセスの
1488 ファイルシステム UID と一致するファイルに対してだけである。
1489 .B CAP_LEASE
1490 ケーパビリティを持つプロセスは任意のファイルに対してリースを取得できる。
1491 .TP
1492 .BR F_GETLEASE " (\fIvoid\fP)"
1493 .\"O Indicates what type of lease is associated with the file descriptor
1494 .\"O .I fd
1495 .\"O by returning either
1496 .\"O .BR F_RDLCK ", " F_WRLCK ", or " F_UNLCK ,
1497 .\"O indicating, respectively, a read lease , a write lease, or no lease.
1498 .\"O .I arg
1499 .\"O is ignored.
1500 ファイルディスクリプタ
1501 .I fd
1502 に対して設定されているリースの種別を取得する。
1503 .BR F_RDLCK ", " F_WRLCK ", " F_UNLCK
1504 のいずれかが返される。
1505 .BR F_RDLCK ", " F_WRLCK
1506 はそれぞれ、読み出しリース、書き込みリースが設定されていることを示し、
1507 .B F_UNLCK
1508 はリースが何も設定されていないことを示す。
1509 .I arg
1510 は無視される。
1511 .PP
1512 .\"O When a process (the "lease breaker") performs an
1513 .\"O .BR open (2)
1514 .\"O or
1515 .\"O .BR truncate (2)
1516 .\"O that conflicts with a lease established via
1517 .\"O .BR F_SETLEASE ,
1518 .\"O the system call is blocked by the kernel and
1519 .\"O the kernel notifies the lease holder by sending it a signal
1520 .\"O .RB ( SIGIO
1521 .\"O by default).
1522 あるプロセス ("lease folder") が
1523 .B F_SETLEASE
1524 で設定されたリースと矛盾するような
1525 .BR open (2)
1526
1527 .BR truncate (2)
1528 を実行した場合、
1529 そのシステムコールはカーネルによって停止され、
1530 カーネルは lease holder にシグナル (デフォルトでは
1531 .BR SIGIO )
1532 を送って通知を行う。
1533 .\"O The lease holder should respond to receipt of this signal by doing
1534 .\"O whatever cleanup is required in preparation for the file to be
1535 .\"O accessed by another process (e.g., flushing cached buffers) and
1536 .\"O then either remove or downgrade its lease.
1537 lease holder はこのシグナルを受信したときにはきちんと対応すべきである。
1538 具体的には、別のプロセスがそのファイルにアクセスするための準備として
1539 必要な後片付け (例えば、キャッシュされたバッファのフラッシュ) を
1540 すべて行ってから、そのファイルのリースの削除または格下げを行う。
1541 .\"O A lease is removed by performing an
1542 .\"O .B F_SETLEASE
1543 .\"O command specifying
1544 .\"O .I arg
1545 .\"O as
1546 .\"O .BR F_UNLCK .
1547 リースを削除をするには、
1548 .I arg
1549
1550 .B F_UNLCK
1551 を指定して
1552 .B F_SETLEASE
1553 を実行する。
1554 .\"O If the lease holder currently holds a write lease on the file,
1555 .\"O and the lease breaker is opening the file for reading,
1556 .\"O then it is sufficient for the lease holder to downgrade
1557 .\"O the lease to a read lease.
1558 .\"O This is done by performing an
1559 .\"O .B F_SETLEASE
1560 .\"O command specifying
1561 .\"O .I arg
1562 .\"O as
1563 .\"O .BR F_RDLCK .
1564 lease holder がファイルに書き込みリースを保持していて、
1565 lease breaker が読み出し用にそのファイルをオープンしている場合、
1566 lease holder が保持しているリースを読み出しリースに格下げすれば
1567 十分である。これをするには、
1568 .I arg
1569
1570 .B F_RDLCK
1571 を指定して
1572 .B F_SETLEASE
1573 を実行する。
1574
1575 .\"O If the lease holder fails to downgrade or remove the lease within
1576 .\"O the number of seconds specified in
1577 .\"O .I /proc/sys/fs/lease-break-time
1578 .\"O then the kernel forcibly removes or downgrades the lease holder's lease.
1579 lease holder が
1580 .I /proc/sys/fs/lease-break-time
1581 で指定された秒数以内にリースの格下げか削除を行えなかった場合、
1582 カーネルは強制的にその lease holder のリースを削除もしくは格下げを行う。
1583
1584 .\"O Once the lease has been voluntarily or forcibly removed or downgraded,
1585 .\"O and assuming the lease breaker has not unblocked its system call,
1586 .\"O the kernel permits the lease breaker's system call to proceed.
1587 一度リースの削除か格下げが自発的もしくは強制的に行われると、
1588 lease breaker がまだシステムコールを再開していない場合には、
1589 カーネルが lease breaker のシステムコールの続行を許可する。
1590
1591 .\"O If the lease breaker's blocked
1592 .\"O .BR open (2)
1593 .\"O or
1594 .\"O .BR truncate (2)
1595 .\"O is interrupted by a signal handler,
1596 .\"O then the system call fails with the error
1597 .\"O .BR EINTR ,
1598 .\"O but the other steps still occur as described above.
1599 lease breaker が実行した
1600 .BR open (2)
1601
1602 .BR truncate (2)
1603 が停止中にシグナルハンドラにより中断された場合、
1604 そのシステムコールは
1605 .B EINTR
1606 エラーで失敗するが、上で述べた他の処理は
1607 そのまま行われる。
1608 .\"O If the lease breaker is killed by a signal while blocked in
1609 .\"O .BR open (2)
1610 .\"O or
1611 .\"O .BR truncate (2),
1612 .\"O then the other steps still occur as described above.
1613 .BR open (2)
1614
1615 .BR truncate (2)
1616 が停止中に lease breaker がシグナルにより kill された場合、
1617 上で述べた他の処理はそのまま行われる。
1618 .\"O If the lease breaker specifies the
1619 .\"O .B O_NONBLOCK
1620 .\"O flag when calling
1621 .\"O .BR open (2),
1622 .\"O then the call immediately fails with the error
1623 .\"O .BR EWOULDBLOCK ,
1624 .\"O but the other steps still occur as described above.
1625 lease breaker が
1626 .BR open (2)
1627 を呼ぶ際に
1628 .B O_NONBLOCK
1629 フラグを指定した場合、そのシステムコールは
1630 .B EWOULDBLOCK
1631 エラーで直ちに失敗するが、上で述べた他の処理はそのまま行われる。
1632
1633 .\"O The default signal used to notify the lease holder is
1634 .\"O .BR SIGIO ,
1635 .\"O but this can be changed using the
1636 .\"O .B F_SETSIG
1637 .\"O command to
1638 .\"O .BR fcntl ().
1639 .\"O If a
1640 .\"O .B F_SETSIG
1641 .\"O command is performed (even one specifying
1642 .\"O .BR SIGIO ),
1643 .\"O and the signal
1644 .\"O handler is established using
1645 .\"O .BR SA_SIGINFO ,
1646 .\"O then the handler will receive a
1647 .\"O .I siginfo_t
1648 .\"O structure as its second argument, and the
1649 .\"O .I si_fd
1650 .\"O field of this argument will hold the descriptor of the leased file
1651 .\"O that has been accessed by another process.
1652 .\"O (This is useful if the caller holds leases against multiple files).
1653 lease holder への通知に使われるデフォルトのシグナルは
1654 .B SIGIO
1655 だが、
1656 .BR fcntl ()
1657
1658 .B F_SETSIG
1659 コマンドで変更することができる。
1660 .B F_SETSIG
1661 コマンドが実行され
1662 .RB ( SIGIO
1663 を指定された場合も含む)、
1664 .B SA_SIGINFO
1665 フラグ付きでシグナルハンドラが設定されている場合には、
1666 ハンドラの第二引き数として
1667 .I siginfo_t
1668 構造体が渡され、この引き数の
1669 .I si_fd
1670 フィールドには別のプロセスがアクセスしたリース設定済みファイルの
1671 ディスクリプタが入っている
1672 (この機能は複数のファイルに対してリースを設定する場合に有用である)。
1673 .\"O .SS "File and directory change notification (dnotify)"
1674 .SS "ファイルやディレクトリの変更の通知 (dnotify)"
1675 .TP
1676 .BR F_NOTIFY " (\fIlong\fP)"
1677 .\"O (Linux 2.4 onwards)
1678 (Linux 2.4 以降)
1679 .\"O Provide notification when the directory referred to by
1680 .\"O .I fd
1681 .\"O or any of the files that it contains is changed.
1682 .\"O The events to be notified are specified in
1683 .\"O .IR arg ,
1684 .\"O which is a bit mask specified by ORing together zero or more of
1685 .\"O the following bits:
1686 .I fd
1687 で参照されるディレクトリか、その中にあるファイルに変更があった場合に
1688 通知を行う。どのイベントを通知するかは
1689 .I arg
1690 で指定する。
1691 .I arg
1692 はビットマスクで、以下のビットの 0個以上の論理和をとったものを指定する。
1693 .RS
1694 .sp
1695 .PD 0
1696 .TP 12
1697 .B DN_ACCESS
1698 .\"O A file was accessed (read, pread, readv)
1699 ファイルへのアクセスがあった (read, pread, readv)
1700 .TP
1701 .B DN_MODIFY
1702 .\"O A file was modified (write, pwrite, writev, truncate, ftruncate).
1703 ファイルの内容が変更された (write, pwrite, writev, truncate, ftruncate).
1704 .TP
1705 .B DN_CREATE
1706 .\"O A file was created (open, creat, mknod, mkdir, link, symlink, rename).
1707 ファイルが作成された (open, creat, mknod, mkdir, link, symlink, rename).
1708 .TP
1709 .B DN_DELETE
1710 .\"O A file was unlinked (unlink, rename to another directory, rmdir).
1711 ファイルが削除 (unlink) された (unlink, 別のディレクトリへの rename, rmdir)
1712 .TP
1713 .B DN_RENAME
1714 .\"O A file was renamed within this directory (rename).
1715 ディレクトリ内でのファイル名の変更があった (rename)
1716 .TP
1717 .B DN_ATTRIB
1718 .\"O The attributes of a file were changed (chown, chmod, utime[s]).
1719 ファイル属性が変更された (chown, chmod, utime[s])
1720 .PD
1721 .RE
1722 .IP
1723 .\"O (In order to obtain these definitions, the
1724 .\"O .B _GNU_SOURCE
1725 .\"O feature test macro must be defined.)
1726 (上記の定義を利用するには
1727 .B _GNU_SOURCE
1728 機能検査マクロを定義しなければならない。)
1729
1730 .\"O Directory notifications are normally "one-shot", and the application
1731 .\"O must reregister to receive further notifications.
1732 ディレクトリの変更通知は通常「一回限り (one-shot)」であり、
1733 アプリケーション側でその後さらに通知を受信したい場合は
1734 再登録しなければならない。
1735 .\"O Alternatively, if
1736 .\"O .B DN_MULTISHOT
1737 .\"O is included in
1738 .\"O .IR arg ,
1739 .\"O then notification will remain in effect until explicitly removed.
1740 .I arg
1741
1742 .B DN_MULTISHOT
1743 が含まれていた場合には、
1744 変更通知は明示的に解除されるまで有効状態が継続する。
1745
1746 .\"O .\" The following does seem a poor API-design choice...
1747 .\" 以下は API の設計がまずいと思うのだが...
1748 .\"O A series of
1749 .\"O .B F_NOTIFY
1750 .\"O requests is cumulative, with the events in
1751 .\"O .I arg
1752 .\"O being added to the set already monitored.
1753 .B F_NOTIFY
1754 要求は積算されていく。つまり、
1755 .I arg
1756 で指定されたイベントがすでにモニタされている
1757 イベント集合に加算される形になる。
1758 .\"O To disable notification of all events, make an
1759 .\"O .B F_NOTIFY
1760 .\"O call specifying
1761 .\"O .I arg
1762 .\"O as 0.
1763 すべてのイベントの通知を無効にするには、
1764 .I arg
1765 に 0 を指定して
1766 .B F_NOTIFY
1767 を呼び出す必要がある。
1768
1769 .\"O Notification occurs via delivery of a signal.
1770 通知はシグナルの配送で行われる。
1771 .\"O The default signal is
1772 .\"O .BR SIGIO ,
1773 .\"O but this can be changed using the
1774 .\"O .B F_SETSIG
1775 .\"O command to
1776 .\"O .BR fcntl ().
1777 デフォルトのシグナルは
1778 .B SIGIO
1779 だが、
1780 .BR fcntl ()
1781
1782 .B F_SETSIG
1783 コマンドで変更することができる。
1784 .\"O In the latter case, the signal handler receives a
1785 .\"O .I siginfo_t
1786 .\"O structure as its second argument (if the handler was
1787 .\"O established using
1788 .\"O .BR SA_SIGINFO )
1789 .\"O and the
1790 .\"O .I si_fd
1791 .\"O field of this structure contains the file descriptor which
1792 .\"O generated the notification (useful when establishing notification
1793 .\"O on multiple directories).
1794 後者の場合には、
1795 .RB ( SA_SIGINFO
1796 フラグ付きでシグナルハンドラが設定されている場合には)
1797 ハンドラの第二引き数として
1798 .I siginfo_t
1799 構造体が渡され、この構造体の
1800 .I si_fd
1801 フィールドには通知の行われたファイルディスクリプタが入っている
1802 (この機能は複数のディレクトリに対して通知を設定する場合に有用である)。
1803
1804 .\"O Especially when using
1805 .\"O .BR DN_MULTISHOT ,
1806 .\"O a real time signal should be used for notification,
1807 .\"O so that multiple notifications can be queued.
1808 特に
1809 .B DN_MULTISHOT
1810 を使う場合は、通知にはリアルタイムシグナルを使うべきである。
1811 それは、リアルタイムシグナルを使うことで、複数の通知をキューに入れる
1812 ことができるからである。
1813
1814 .\"O .B NOTE:
1815 .\"O New applications should use the
1816 .\"O .I inotify
1817 .\"O interface (available since kernel 2.6.13),
1818 .\"O which provides a much superior interface for obtaining notifications of
1819 .\"O file system events.
1820 .\"O See
1821 .\"O .BR inotify (7).
1822 .B 注意:
1823 新しくアプリケーションを書く際には、(カーネル 2.6.13 以降で利用可能となった)
1824 .I inotify
1825 インタフェースを使用すべきである。
1826 .I inotify
1827 はファイルシステムイベントの通知を取得するための
1828 ずっと優れたインタフェースである。
1829 .BR inotify (7)
1830 を参照。
1831 .\"O .SH "RETURN VALUE"
1832 .SH 返り値
1833 .\"O For a successful call, the return value depends on the operation:
1834 成功した場合の返り値は操作の種類により違う:
1835 .TP 0.9i
1836 .B F_DUPFD
1837 .\"O The new descriptor.
1838 新しいディスクリプタを返す。
1839 .TP
1840 .B F_GETFD
1841 .\"O Value of file descriptor flags.
1842 ファイルディスクリプタ・フラグの値を返す。
1843 .TP
1844 .B F_GETFL
1845 .\"O Value of file status flags.
1846 ファイル状態フラグの値を返す。
1847 .TP
1848 .B F_GETLEASE
1849 .\"O Type of lease held on file descriptor.
1850 ファイルディスクリプタに対して保持されているリースの種別を返す。
1851 .TP
1852 .B F_GETOWN
1853 .\"O Value of descriptor owner.
1854 ディスクリプタの所有者を返す。
1855 .TP
1856 .B F_GETSIG
1857 .\"O Value of signal sent when read or write becomes possible, or zero
1858 .\"O for traditional
1859 .\"O .B SIGIO
1860 .\"O behavior.
1861 読み込みや書き出しが可能になった時に送られるシグナルの値、もしくは
1862 伝統的な
1863 .B SIGIO
1864 動作の場合にはゼロを返す。
1865 .TP
1866 .\"O All other commands
1867 .\"O Zero.
1868 他の全てのコマンドは 0 を返す。
1869 .PP
1870 .\"O On error, \-1 is returned, and
1871 .\"O .I errno
1872 .\"O is set appropriately.
1873 エラーの時は \-1 が返され、
1874 .I errno
1875 に適切な値が設定される。
1876 .\"O .SH ERRORS
1877 .SH エラー
1878 .TP
1879 .\"O .BR EACCES " or " EAGAIN
1880 .BR EACCES " か " EAGAIN
1881 .\"O Operation is prohibited by locks held by other processes.
1882 他のプロセスが保持しているロックによって操作が禁止されている。
1883 .TP
1884 .B EAGAIN
1885 .\"O The operation is prohibited because the file has been memory-mapped by
1886 .\"O another process.
1887 そのファイルは他のプロセスによってメモリ・マップされているため、
1888 操作が禁止されている。
1889 .TP
1890 .B EBADF
1891 .\"O .I fd
1892 .\"O is not an open file descriptor, or the command was
1893 .\"O .B F_SETLK
1894 .\"O or
1895 .\"O .B F_SETLKW
1896 .\"O and the file descriptor open mode doesn't match with the
1897 .\"O type of lock requested.
1898 .I fd
1899 がオープンされたファイルディスクリプタでない。
1900 あるいはコマンドが
1901 .B F_SETLK
1902 または
1903 .B F_SETLKW
1904 だったが、対象のファイルディスクリプタのオープンモードが
1905 必要となるロックの型にマッチしていない。
1906 .TP
1907 .\"O .B EDEADLK
1908 .\"O It was detected that the specified
1909 .\"O .B F_SETLKW
1910 .\"O command would cause a deadlock.
1911 .B EDEADLK
1912 指定された
1913 .B F_SETLKW
1914 コマンドを実行した場合にはデッドロックになることが検出された。
1915 .TP
1916 .B EFAULT
1917 .\"O .I lock
1918 .\"O is outside your accessible address space.
1919 .I lock
1920 が利用可能なアドレス空間の外部にある。
1921 .TP
1922 .B EINTR
1923 .\"O For
1924 .\"O .BR F_SETLKW ,
1925 .\"O the command was interrupted by a signal; see
1926 .\"O .BR signal (7).
1927 .\"O For
1928 .\"O .BR F_GETLK " and " F_SETLK ,
1929 .\"O the command was interrupted by a signal before the lock was checked or
1930 .\"O acquired.
1931 .\"O Most likely when locking a remote file (e.g., locking over
1932 .\"O NFS), but can sometimes happen locally.
1933 .B F_SETLKW
1934 コマンドがシグナルにより割り込まれた
1935 .RB ( signal (7)
1936 参照)。
1937 .BR F_GETLK " と " F_SETLK
1938 の場合、ロックを確認したり取得したりする前にシグナルによって割り込まれた。
1939 これはたいていリモートのファイルをロックする場合
1940 (例えば NFS 上でロックする場合) に起こる。
1941 しかしローカルでも起こる場合がある。
1942 .TP
1943 .B EINVAL
1944 .\"O For
1945 .\"O .BR F_DUPFD ,
1946 .\"O .I arg
1947 .\"O is negative or is greater than the maximum allowable value.
1948 .\"O For
1949 .\"O .BR F_SETSIG ,
1950 .\"O .I arg
1951 .\"O is not an allowable signal number.
1952 .BR F_DUPFD で、
1953 .I arg
1954 が負か、もしくは許される最大値よりも大きい。
1955 .B F_SETSIG
1956 の場合、
1957 .I arg
1958 が利用可能なシグナル番号ではない。
1959 .TP
1960 .B EMFILE
1961 .\"O For
1962 .\"O .BR F_DUPFD ,
1963 .\"O the process already has the maximum number of file descriptors open.
1964 .BR F_DUPFD で、
1965 プロセスがすでに最大数までファイルディスクリプタをオープンしている。
1966 .TP
1967 .B ENOLCK
1968 .\"O Too many segment locks open, lock table is full, or a remote locking
1969 .\"O protocol failed (e.g., locking over NFS).
1970 オープンされているロックの数が多過ぎて、ロック・テーブルがいっぱいである。
1971 または remote locking protocol (例えば NFS 上のロック) が失敗した。
1972 .TP
1973 .B EPERM
1974 .\"O Attempted to clear the
1975 .\"O .B O_APPEND
1976 .\"O flag on a file that has the append-only attribute set.
1977 追加専用属性が設定されたファイルの
1978 .B O_APPEND
1979 フラグをクリアしようと試みた。
1980 .\"O .SH "CONFORMING TO"
1981 .SH 準拠
1982 .\"O SVr4, 4.3BSD, POSIX.1-2001.
1983 SVr4, 4.3BSD, POSIX.1-2001.
1984 .\"O Only the operations
1985 .\"O .BR F_DUPFD ,
1986 .\"O .BR F_GETFD ,
1987 .\"O .BR F_SETFD ,
1988 .\"O .BR F_GETFL ,
1989 .\"O .BR F_SETFL ,
1990 .\"O .BR F_GETLK ,
1991 .\"O .BR F_SETLK ,
1992 .\"O .BR F_SETLKW ,
1993 .\"O .BR F_GETOWN ,
1994 .\"O and
1995 .\"O .B F_SETOWN
1996 .\"O are specified in POSIX.1-2001.
1997 POSIX.1-2001 で規定されている操作は、
1998 .BR F_DUPFD ,
1999 .BR F_GETFD ,
2000 .BR F_SETFD ,
2001 .BR F_GETFL ,
2002 .BR F_SETFL ,
2003 .BR F_GETLK ,
2004 .BR F_SETLK ,
2005 .BR F_SETLKW ,
2006 .BR F_GETOWN ,
2007 .B F_SETOWN
2008 だけである。
2009
2010 .\"O .B F_DUPFD_CLOEXEC
2011 .\"O is specified in POSIX.1-2008.
2012 .B F_DUPFD_CLOEXEC
2013 は POSIX.1-2008 で規定されている。
2014
2015 .\"O .BR F_GETOWN_EX ,
2016 .\"O .BR F_SETOWN_EX ,
2017 .\"O .BR F_GETSIG ,
2018 .\"O .BR F_SETSIG ,
2019 .\"O .BR F_NOTIFY ,
2020 .\"O .BR F_GETLEASE ,
2021 .\"O and
2022 .\"O .B F_SETLEASE
2023 .\"O are Linux-specific.
2024 .\"O (Define the
2025 .\"O .B _GNU_SOURCE
2026 .\"O macro to obtain these definitions.)
2027 .BR F_GETOWN_EX ,
2028 .BR F_SETOWN_EX ,
2029 .BR F_GETSIG ,
2030 .BR F_SETSIG ,
2031 .BR F_NOTIFY ,
2032 .BR F_GETLEASE ,
2033 .B F_SETLEASE
2034 は Linux 固有である (これらの定義を有効にするには
2035 .B _GNU_SOURCE
2036 マクロを定義すること)。
2037 .\" .PP
2038 .\"O .\" SVr4 documents additional EIO, ENOLINK and EOVERFLOW error conditions.
2039 .\" SVr4 には他に EFAULT, EINTR, EIO, ENOLINK, EOVERFLOW エラー状態についての
2040 .\" 記述がある。
2041 .\"O .SH NOTES
2042 .SH 注意
2043 .\"O The errors returned by
2044 .\"O .BR dup2 (2)
2045 .\"O are different from those returned by
2046 .\"O .BR F_DUPFD .
2047 エラーの際の返り値が
2048 .BR dup2 (2)
2049
2050 .B F_DUPFD
2051 では異なっている。
2052
2053 .\"O Since kernel 2.0, there is no interaction between the types of lock
2054 .\"O placed by
2055 .\"O .BR flock (2)
2056 .\"O and
2057 .\"O .BR fcntl ().
2058 カーネル 2.0 以降では、
2059 .BR flock (2)
2060
2061 .BR fcntl ()
2062 が設定するロック種別の間に相互作用はない。
2063
2064 .\"O Several systems have more fields in
2065 .\"O .I "struct flock"
2066 .\"O such as, for example,
2067 .\"O .IR l_sysid .
2068 .\"O .\" e.g., Solaris 8 documents this field in fcntl(2), and Irix 6.5
2069 .\"O .\" documents it in fcntl(5).  mtk, May 2007
2070 .\"O Clearly,
2071 .\"O .I l_pid
2072 .\"O alone is not going to be very useful if the process holding the lock
2073 .\"O may live on a different machine.
2074 システムによっては、
2075 .I "struct flock"
2076 に上記以外のフィールドがあるものもある (例えば
2077 .IR l_sysid )。
2078 .\" e.g., Solaris 8 documents this field in fcntl(2), and Irix 6.5
2079 .\" documents it in fcntl(5).  mtk, May 2007
2080 はっきりと言えることは、ロックを保持しているプロセスが別のマシンに存在
2081 する場合には、
2082 .I l_pid
2083 だけはあまり役にたたないだろうということである。
2084 .\"O .SH BUGS
2085 .SH バグ
2086 .\"O A limitation of the Linux system call conventions on some
2087 .\"O architectures (notably i386) means that if a (negative)
2088 .\"O process group ID to be returned by
2089 .\"O .B F_GETOWN
2090 .\"O falls in the range \-1 to \-4095, then the return value is wrongly
2091 .\"O interpreted by glibc as an error in the system call;
2092 .\"O .\" glibc source: sysdeps/unix/sysv/linux/i386/sysdep.h
2093 .\"O that is, the return value of
2094 .\"O .BR fcntl ()
2095 .\"O will be \-1, and
2096 .\"O .I errno
2097 .\"O will contain the (positive) process group ID.
2098 いくつかのアーキテクチャ (特に i386) における Linux システムコールの慣習
2099 のため以下の制限が存在する。
2100 .B F_GETOWN
2101 が返す (負の) プロセスグループID が \-1 から \-4095 の範囲に入った場合、
2102 glibc はこの返り値をシステムコールでエラーが起こったと
2103 間違って解釈してしまう。つまり、
2104 .BR fcntl ()
2105 の返り値は \-1 となり、
2106 .I errno
2107 には (正の) プロセスグループID が設定されることになる。
2108 .\"O The Linux-specific
2109 .\"O .BR F_SETOWN_EX
2110 .\"O and
2111 .\"O .BR F_GETOWN_EX
2112 .\"O operations avoid this problem.
2113 Linux 固有の
2114 .B F_SETOWN_EX
2115
2116 .B F_GETOWN_EX
2117 ではこの問題を回避できる。
2118 .\"O .\" mtk, Dec 04: some limited testing on alpha and ia64 seems to
2119 .\"O .\" indicate that ANY negative PGID value will cause F_GETOWN
2120 .\"O .\" to misinterpret the return as an error. Some other architectures
2121 .\"O .\" seem to have the same range check as i386.
2122 .\" mtk, Dec 04: alpha と ia64 では、少しテストしてみた限り、
2123 .\" 「どんな」負の PGID でも F_GETOWN でエラーが起こったと間違って
2124 .\" 解釈されてしまうようだ。他のいくつかのアーキテクチャでは、
2125 .\" i386 と同様の範囲のチェックが行われているようだ。
2126
2127 .\"O In Linux 2.4 and earlier, there is bug that can occur
2128 .\"O when an unprivileged process uses
2129 .\"O .B F_SETOWN
2130 .\"O to specify the owner
2131 .\"O of a socket file descriptor
2132 .\"O as a process (group) other than the caller.
2133 .\"O In this case,
2134 .\"O .BR fcntl ()
2135 .\"O can return \-1 with
2136 .\"O .I errno
2137 .\"O set to
2138 .\"O .BR EPERM ,
2139 .\"O even when the owner process (group) is one that the caller
2140 .\"O has permission to send signals to.
2141 .\"O Despite this error return, the file descriptor owner is set,
2142 .\"O and signals will be sent to the owner.
2143 Linux 2.4 以前では、非特権プロセスが
2144 .B F_SETOWN
2145 を使って、ソケットのファイルディスクリプタの所有者に
2146 呼び出し元以外のプロセス (やプロセスグループ) を指定すると
2147 発生するバグがある。この場合、
2148 呼び出し元が所有者として指定したプロセス (やプロセスグループ) に
2149 シグナルを送る許可を持っていたとしても、
2150 .BR fcntl ()
2151 が \-1 を返し
2152 .I errno
2153
2154 .B EPERM
2155 を設定することがある。
2156 このエラーが返ったにもかかわらず、ファイルディスクリプタの所有者
2157 は設定され、シグナルはその所有者に送られる。
2158
2159 .\"O The implementation of mandatory locking in all known versions of Linux
2160 .\"O is subject to race conditions which render it unreliable:
2161 .\"O .\" http://marc.info/?l=linux-kernel&m=119013491707153&w=2
2162 .\"O a
2163 .\"O .BR write (2)
2164 .\"O call that overlaps with a lock may modify data after the mandatory lock is
2165 .\"O acquired;
2166 .\"O a
2167 .\"O .BR read (2)
2168 .\"O call that overlaps with a lock may detect changes to data that were made
2169 .\"O only after a write lock was acquired.
2170 .\"O Similar races exist between mandatory locks and
2171 .\"O .BR mmap (2).
2172 .\"O It is therefore inadvisable to rely on mandatory locking.
2173 これまでの Linux の全てのバージョンにおける強制ロックの実装は、
2174 競合条件下で強制ロックが不完全になるような場合がある。
2175 .\" http://marc.info/?l=linux-kernel&m=119013491707153&w=2
2176 ロックと重なって実行された
2177 .BR write (2)
2178 の呼び出しは強制ロックが獲得された後にもデータを変更することができる。
2179 ロックと重なって実行された
2180 .BR read (2)
2181 の呼び出しは強制ロックが獲得された後になって行われたデータの変更を
2182 検出することができる。
2183 同様の競合条件が強制ロックと
2184 .BR mmap (2)
2185 の間にも存在する。それゆえ、強制ロックに頼るのはお薦めできない。
2186 .\"O .SH "SEE ALSO"
2187 .SH 関連項目
2188 .BR dup2 (2),
2189 .BR flock (2),
2190 .BR open (2),
2191 .BR socket (2),
2192 .BR lockf (3),
2193 .BR capabilities (7),
2194 .BR feature_test_macros (7)
2195 .P
2196 .\"O See also
2197 .\"O .IR locks.txt ,
2198 .\"O .IR mandatory-locking.txt ,
2199 .\"O and
2200 .\"O .I dnotify.txt
2201 .\"O in the kernel source directory
2202 .\"O .IR Documentation/filesystems/ .
2203 .\"O (On older kernels, these files are directly under the
2204 .\"O .I Documentation/
2205 .\"O directory, and
2206 .\"O .I mandatory-locking.txt
2207 .\"O is called
2208 .\"O .IR mandatory.txt .)
2209 カーネルソースの
2210 .IR Documentation/filesystems/
2211 ディレクトリ内の
2212 .IR locks.txt ,
2213 .IR mandatory-locking.txt ,
2214 .I dnotify.txt
2215 も参照のこと。
2216 (以前のカーネルでは、これらのファイルは
2217 .I Documentation/
2218 ディレクトリ直下にあり、
2219 .I mandatory-locking.txt
2220
2221 .I mandatory.txt
2222 という名前であった。)