HP-UX Reference (11i v3 07/02) - 2 System Calls (vol 5)

f
fcntl(2) fcntl(2)
F_UNSHARE Removes an existing share reservation.
A read lock prevents any other process from write-locking the protected area. More than one read lock can
exist for a given segment of a file at a given time. The file descriptor on which a read lock is being placed
must have been opened with read access.
A write lock prevents any other process from read-locking or write-locking the protected area. Only one
write lock may exist for a given segment of a file at a given time. The file descriptor on which a write lock
is being placed must have been opened with write access.
The structure flock describes the type (
l_type), starting offset (l_whence), relative offset
(
l_start), size (l_len), and process ID (
l_pid) of the segment of the file to be affected. The process
ID field is only used with the
F_GETLK cmd to return the value of a block in lock. Locks can start and
extend beyond the current end of a file, but cannot be negative relative to the beginning of the file. A lock
can be set to always extend to the end of file by setting
l_len to zero (0). If such a lock also has
l_start set to zero (0), the whole file will be locked. Changing or unlocking a segment from the middle
of a larger locked segment leaves two smaller segments for either end. Locking a segment 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 the process holding that file descriptor terminates. Locks are not inherited by a child process in
a fork() system call.
When enforcement-mode file and record locking is activated on a file (see chmod(2)), future
creat(),
open(), read(), write(), truncate(), and ftruncate() system calls on the file are affected by
the record locks in effect.
File Share Reservations
File share reservations are an advisory form of access control among cooperating processes, on both local
and remote machines. They are most commonly used by DOS or Windows emulators and DOS based NFS
clients. The fcntl() system call can be used to set file share reservations via the
F_SHARE command.
A share reservation is described by an fshare structure defined in
<sys/fcntl.h>
as follows:
struct fshare {
short f_access;
short f_deny;
long f_id;
};
The structure fshare describes the type of access (f_access), to be requested on the open file descrip-
tor. If the command succeeds it also specifies what type of access to deny other processes (
f_deny), A sin-
gle process on the same file may hold several non-conflicting reservations by specifying an identifier,
(
f_id), unique to the process with each share reservation request.
Valid f_access values are:
R_RDACC Set a file share reservation for read-only access.
R_WRACC Set a file share reservation for write-only access.
R_RWACC Set a file share reservation for read-write access.
Valid f_deny values are:
F_COMPAT Set a file share reservation to compatibility mode.
F_RDDNY Set a file share reservation to deny read access to other processes.
F_WRDNY Set a file share reservation to deny write access to other processes.
F_RWDNY Set a file share reservation to deny read and write access to other processes.
F_NODNY Set a file share reservation to not deny read or write access to other processes.
Oplocks
An oplock is a type of caching hint used mostly by CIFS clients so they may cache data locally. This helps
increase performance by not having to read data across a network each time a file operation is performed.
The oplock guarantees that no other remote process is accessing the file in a way that might lead to data
inconsistencies.
HP-UX 11i Version 3: February 2007 3 Hewlett-Packard Company 105