fcntl.2
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 2 代码 · 共 584 行 · 第 1/2 页
2
584 行
.IP F_GETLK 13When \fIrequest\fR is set to F_GETLK:.spThe .PN fcntlcall gets the lock information for a read or write locked region.In the call, you pass a lock description in a variable of type.I struct flock pointed to by.I arg..spIf the region defined in the.I flockstructure is already locked by a process other than thecaller, a description of the existing lockis returned in the .I flock structure.If no lock is found that would prevent this lock from being created,then the structure is passed back unchanged except for the lock typewhich is set to F_UNLCK..spThe.I flock structure is defined as follows:.EXstruct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid;};.EE\fBData Passed in \fIflock\fR:.spIn the data you pass in.I flock,the .I l_typevalue defines the lock type to be tested for: F_RDLCK fora read lock and F_WRLCK for a write lock. .spThe.I l_whence value defines the point from which the starting byte of the region is to bemeasured. If.I l_whence is 0, the value in.I l_startis taken as the starting byte of the region.If.I l_whence is 1,the current file offset plus the value of.I l_startis taken as the starting point.If.I l_whenceis 2,the file size plus the value of.I l_startis taken as the starting point..spThe.I l_lenvalue is the length of the region to be tested, in bytes.If.I l_len is zero, the length to be tested extends to the end of file.If .I l_lenis zero and.I l_startis zero, the whole file is to be tested.If.I l_lenis negative, the area affected starts at \fIl_start\fP + \fIl_len\fPand ends at \fIl_start\fP - 1..spThe.I l_pidvalue has no significance in the data passed..sp\fBData Returned in \fIflock\fR:.spThe .I l_type value can be F_RDLCK if the region passed is under a read lock.F_WRLCK means that the region passed is under a write lock.F_UNLCK means that the region is not currently locked by anyprocess that would prevent this lock from being created;for example, the region might be locked by the caller..spThe .IR l_whence ,.IR l_start ,and.IR l_lenvalues have similar meanings as discussed under Data Passed,except that they define the region currently underread or write lock..spThe .I l_pid value is only used with F_GETLK to return the value for ablocking lock. An example of a blocking lock is a write lock currentlyset by a process other than the calling process..IP F_SETLK 13When \fIrequest\fR is set to F_SETLK:.spYou set or clear a file region lock according to the variable of .I l_typein the.I struct flockpointed to by .IR arg .(The .I flockstructure is shown under the description of F_GETLK,preceding.).spThe .I l_type valueis used to establish read (F_RDLCK) and write (F_WRLCK) locks,as well as remove either type of lock (F_UNLCK).If a read or write lock cannot be set, .PN fcntlwill return immediately with anerror value of \-1..IP F_SETLKW 13When \fIrequest\fR is set to F_SETLKW:.spThe .PN fcntlcall takes the same action as forF_SETLK,except that if a read or write lock is blocked by other locks,the process sleeps until the segment is free to be locked..PPFiles and region locking are supported over the Network FileSystem (NFS) services if you have enabled the NFS lockingservice..SH Return Values.NXR "fcntl system call" "return value"Upon successful completion, the value returned depends uponthe.I requestargumentas follows:.sp .5v.nf.ta .0i 1i F_DUPFD A new file descriptor. F_GETFD Value of flag (only the low-order bit is defined). F_GETFL Value of flags. F_GETOWN Value of file descriptor owner. other Value other than \-1..fi.sp .5vOtherwise, a value of \-1 is returned and.I errnois set to indicate the error..SH Diagnostics.NXR "fcntl system call" "diagnostics"The.PN fcntlfails if under the following conditions: .TP 15[EBADF]The .I fildesargument is not a valid open file descriptor..TP[EBADF]The environment defined is POSIX, the \fIrequest\fP argument is F_SETLK or F_SETLKW, the type of lock, \fIl_type\fP, is a shared lock (F_RDLCK),and \fIfildes\fP is not a valid file descriptor open for reading, or thetype of lock, \fIl_type\fP, is an exclusive lock (F_WRLCK), and\fIfildes\fP is not a valid file descriptor open for writing..TP 15[EFAULT]The .I argis pointing to an address outside the process's allocated space..TP 15[EINVAL]The.I requestargumentis F_DUPFD, and.I argis negative or greater than the maximum allowable number.For further information, see .MS getdtablesize 2 ..TP 15[EINVAL]The.I requestargumentis F_SETSYN, to change the write mode of a file tosynchronous, and this operation is not valid for the file descriptor. For example, the filewas opened for read-only operations..TP 15[EINVAL]The.I requestargument isF_GETLK,F_SETLK, or SETLKW and the data .I argpoints to is not valid..TP[EINVAL] The.I requestargument is invalid..TP[EINVAL] The \fIfildes\fP argument refers to a file that does not supportlocking..TP 15[EACCES]The.I requestargumentisF_SETLK, the type of lock (.I l_type)is a read(F_RDLCK) or write (F_WRLCK) lock, and the region of thefile to be locked is already write locked by another process.Or, the type is a write lock and the regionof the file to be locked is already read or writelocked by another process.Or,the file is remotely mounted and the NFS locking service is not enabled..TP 15[EMFILE]The.I requestargument isF_DUPFD, and the maximum allowed number of file descriptors is currentlyopen, or no file descriptors greater than or equal to \fIarg\fP areavailable..TP 15[ENOSPC]The.I requestargument isF_SETLKorF_SETLKW,the type of lock is a read or write lock,and there are no more file locking headers available(too many files have segments locked).Or, there are no more record locks available(too many file segments locked)..TP 15[EDEADLK]The.I requestargument isF_SETLKW,and the lock is blocked by some lock from another processthat is sleeping (waiting) for that lock to become free.This detection avoids a deadlock situation..TP 15[EOPNOTSUPP]Attempting an operation that is not valid forthe file descriptor. This can occur if the file descriptorargument, \fIfd\fR, pointsto a socket address, and the.I requestargument is only valid for files..TP[EINTR]The \fIrequest\fP argument is F_SETLKW and the function wasinterrupted by a signal..SH EnvironmentThe .PN fcntldescription differs from the POSIX and XPG3 definitions in that ENOLCK isnot a possible error condition..SH See Alsoclose(2), execve(2), getdtablesize(2), open(2), sigvec(2), lockd(8c)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?