.\" Copyright 1997 Nicolas Lichtmaier .\" Created Thu Aug 7 00:44:00 ART 1997 .\" .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2 of .\" the License, or (at your option) any later version. .\" .\" The GNU General Public License's references to "object code" .\" and "executables" are to be interpreted as the output of any .\" document formatting or typesetting system, including .\" intermediate and printed output. .\" .\" This manual is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" Added section stuff, aeb, 2002-04-22. .\" Corrected include file, drepper, 2003-06-15. .\" .\" Japanese Version Copyright (c) 2000-2002 Yuichi SATO .\" all rights reserved. .\" Translated Tue Jul 11 19:02:58 JST 2000 .\" by Yuichi SATO .\" Updated & Modified Mon Jul 15 02:10:29 JST 2002 by Yuichi SATO .\" Updated 2010-04-18, Akihiro MOTOKI , LDP v3.24 .\" .\"WORD: apply 適用 .\"WORD: remove 解除 .\"WORD: exclusive 排他 .\"WORD: descriptor ディスクリプタ .\"WORD: .\" .TH LOCKF 3 2010-09-20 "GNU" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O lockf \- apply, test or remove a POSIX lock on an open file lockf \- オープンされたファイルに対する POSIX ロックの適用・テスト・解除を行う .\"O .SH SYNOPSIS .SH 書式 .B #include .sp .BI "int lockf(int " fd ", int " cmd ", off_t " len ); .sp .in -4n .\"O Feature Test Macro Requirements for glibc (see .\"O .BR feature_test_macros (7)): glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .BR lockf (): .ad l .RS 4 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED .RE .ad .\"O .SH DESCRIPTION .SH 説明 .\"O Apply, test or remove a POSIX lock on a section of an open file. オープンされたファイルのセクションに対して、 POSIX ロックの適用・テスト・解除をする。 .\"O The file is specified by .\"O .IR fd , .\"O a file descriptor open for writing, the action by .\"O .IR cmd , ファイルは .I fd で指定される。 .I fd は書き込みのためにオープンしたファイルディスクリプタである。 アクションは .I cmd で指定される。 .\"O and the section consists of byte positions .\"O .IR pos .. pos + len \-1 .\"O if .\"O .I len .\"O is positive, and .\"O .IR pos - len .. pos \-1 .\"O if .\"O .I len .\"O is negative, where .\"O .I pos .\"O is the current file position, and if .I pos を現在のファイル位置とすると、 .I len が正の場合、セクションはバイト位置 .IR pos .. pos + len \-1 となり、 .I len が負の場合、セクションはバイト位置 .IR pos - len .. pos \-1 となる。 .\"O .I len .\"O is zero, the section extends from the current file position to .\"O infinity, encompassing the present and future end-of-file positions. .I len が 0 の場合、セクションは現在のファイル位置から無限大までとなる (つまり現在の、あるいは変更された場合は将来の、ファイル終端位置まで)。 .\"O In all cases, the section may extend past current end-of-file. どの場合においても、セクションは以前のファイル終端よりも拡大されうる。 .LP .\"O On Linux, .\"O .BR lockf () .\"O is just an interface on top of .\"O .BR fcntl (2) .\"O locking. Linux では、 .BR lockf () は単に .BR fcntl (2) のロックへのインターフェースである。 .\"O Many other systems implement .\"O .BR lockf () .\"O in this way, but note that POSIX.1-2001 leaves the relationship between .\"O .BR lockf () .\"O and .\"O .BR fcntl (2) .\"O locks unspecified. .\"O A portable application should probably avoid mixing calls .\"O to these interfaces. 多くの他のシステムで .BR lockf () はこのように実装されているが、 POSIX.1-2001 では .BR lockf () と .BR fcntl (2) のロックとの関係は規定されていない。 おそらく、移植性が必要なアプリケーションでは、 .BR lockf () と .BR fcntl (2) のロックを混ぜて呼び出すのは避けるべきであろう。 .LP .\"O Valid operations are given below: 有効なオプションを以下に挙げる。 .TP .B F_LOCK .\"O Set an exclusive lock on the specified section of the file. .\"O If (part of) this section is already locked, the call .\"O blocks until the previous lock is released. ファイルの指定されたセクションに排他ロックを設定する。 そのセクション (の一部) が既にロックされていた場合、 前のロックが解除されるまで関数の呼び出しがブロックされる。 .\"O If this section overlaps an earlier locked section, .\"O both are merged. このセクションが前にロックされているセクションと重なった場合、 2 つのセクションは結合される。 .\"O File locks are released as soon as the process holding the locks .\"O closes some file descriptor for the file. .\"O A child process does not .\"O inherit these locks. ロックを保持しているプロセスが、 そのファイルのファイルディスクリプタをクローズすると、 ファイルロックは解放される。 子プロセスはロックを継承しない。 .TP .B F_TLOCK .\"O Same as .\"O .B F_LOCK .\"O but the call never blocks and returns an error instead if the file is .\"O already locked. .B F_LOCK と同様であるが、ファイルが既にロックされている場合、 関数の呼び出しはブロックを行わずにエラーを返す。 .TP .B F_ULOCK .\"O Unlock the indicated section of the file. .\"O This may cause a locked section to be split into two locked sections. ファイルの指定されたセクションのロックを解除する。 これによりロックされたセクションが 2 つに分割されるかもしれない。 .TP .B F_TEST .\"O Test the lock: return 0 if the specified section .\"O is unlocked or locked by this process; return \-1, set .\"O .I errno .\"O to .\"O .B EAGAIN .\"O .RB ( EACCES .\"O on some other systems), .\"O if another process holds a lock. 次のようにロックのテストをする。 指定されたセクションがロックされていないか、 このプロセスによりロックされている場合、0 を返す。 他のプロセスがロックを保持している場合、\-1 を返し、 .I errno を .B EAGAIN (いくつかの他のシステムでは .BR EACCES ) に設定する。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O On success, zero is returned. .\"O On error, \-1 is returned, and .\"O .I errno .\"O is set appropriately. 成功した場合、0 が返される。 エラーの場合、\-1 が返され、 .I errno がエラーに対応した値に設定される。 .\"O .SH ERRORS .SH エラー .TP .\"O .BR EACCES " or " EAGAIN .BR EACCES " もしくは " EAGAIN .\"O The file is locked and .\"O .B F_TLOCK .\"O or .\"O .B F_TEST .\"O was specified, or the operation is prohibited because the file has .\"O been memory-mapped by another process. ロックされたファイルに対して、 .B F_TLOCK または .B F_TEST が指定されている。 または、ファイルが他のプロセスによりメモリーマップされており、 指定された操作が禁止されている。 .TP .B EBADF .\"O .I fd .\"O is not an open file descriptor. .I fd がオープンされたファイルのディスクリプタではない。 .TP .B EDEADLK .\"O The command was .\"O .B T_LOCK .\"O and this lock operation would cause a deadlock. コマンドが .B T_LOCK であり、このロック操作を行うとデッドロックが発生してしまう。 .TP .B EINVAL .\"O An invalid operation was specified in .\"O .IR fd . .I fd に無効な操作が指定された。 .TP .B ENOLCK .\"O Too many segment locks open, lock table is full. 非常に多くのセグメントロックが開かれ、ロックテーブルが一杯である。 .\"O .SH CONFORMING TO .SH 準拠 SVr4, POSIX.1-2001. .\"O .SH "SEE ALSO" .SH 関連項目 .\"O .BR fcntl (2), .\"O .BR flock (2) .\"O .br .\"O There are also .\"O .I locks.txt .\"O and .\"O .I mandatory-locking.txt .\"O in the kernel source directory .\"O .IR Documentation/filesystems . .\"O (On older kernels, these files are directly under the .\"O .I Documentation/ .\"O directory, and .\"O .I mandatory-locking.txt .\"O is called .\"O .IR mandatory.txt .) .BR fcntl (2), .BR flock (2) .br カーネルソースの .I Documentation/filesystems ディレクトリにある .I locks.txt と .I mandatory-locking.txt (以前のカーネルでは、これらのファイルは .I Documentation ディレクトリ直下にあり、 .I mandatory-locking.txt は .I mandatory.txt という名前であった。)