Open System Services System Calls Reference Manual (G06.29+, H06.08+, J06.03+)

System Functions (s and S) spt_fcntlz(2)
F_SETLKW64
Similar to F_SETLKW, except that it takes a pointer to a flock64 structure
instead of a pointer to a flock structure.
The O_NONBLOCK file status flag affects only operations against file descriptors derived from
the same open() function.
When a shared lock is set on a segment of a file, other processes can set shared locks on that seg-
ment or a portion of it. A shared lock prevents any other process from setting an exclusive lock
on any portion of the protected area. A request for a shared lock fails if the file descriptor is not
opened with read access.
An exclusive lock prevents any other process from setting a shared lock or an exclusive lock on
any portion of the protected area. A request for an exclusive lock fails if the file descriptor was
not opened with write access.
The flock and flock64 structures describe the type (l_type field), starting offset (l_whence), rela-
tive offset (l_start), size (l_len), and process ID (l_pid) of the segment of the file to be affected.
The value of l_whence is set to SEEK_SET, SEEK_CUR,orSEEK_END to indicate that the
relative offset of l_start bytes is measured from the start of the file, from the current position, or
from the end of the file, respectively. The value of l_len is the number of consecutive bytes to be
locked. The l_len value can be negative (where the definition of type off_t permits negative
values of l_len). The l_pid field is used only with F_GETLK or F_GETLK64 to return the pro-
cess ID of the process holding a blocking lock. After a successful F_GETLK or F_GETLK64
request, the value of l_whence becomes SEEK_SET.
If l_len is positive, the area affected starts at l_start and ends at l_start + l_len - 1.Ifl_len is
negative, the area affected starts at l_start + l_len and ends at l_start - 1. Lock lengths can be
negative.
Locks can start and extend beyond the current end of a file, but they cannot be negative relative
to the beginning of the file. If l_len is set to 0 (zero), a lock can be set to always extend to the
largest possible value of the file offset for that file. If such a lock also has l_start
set to 0 (zero)
and l_whence is
set to SEEK_SET, the whole file is locked.
Changing or unlocking a portion from the middle of a larger locked segment leaves a smaller
segment at either end. Locking a segment that is already locked by the calling process causes the
old lock type to be removed and the new lock type to take effect. All locks associated with a file
for a given process are removed when a file descriptor for that file is closed by that process or
when the process holding that file descriptor terminates. Locks are not inherited by a child pro-
cess in a function like fork( ), tdm_fork( ),ortdm_spawn( ).
NOTES
For file descriptors for non-regular files, the spt_fcntlz() function behaves exactly the same as
the spt_fcntlx() function. For regular files, if the spt_fcntlz() function needs to wait for
F_SETLKW or F_SETLKW64 requests, spt_fcntlz( ) blocks the thread that called the function
(instead of blocking the entire process).
This function serializes file operations on an open file. If a thread calls spt_fcntlz( ) to access a
file that already has a file operation in progress by a different thread, this thread is blocked until
the prior file operation is complete.
For C applications, a macro to map fcntl( ) to spt_fcntlz( ) is available when you use the #define
SPT_THREAD_AWARE_XNONBLOCK preprocessor directive before including spthread.h
or when you use an equivalent compiler command option to compile the application.
527186-023 Hewlett-Packard Company 7169