There are two general locking schemes, advisory locking and mandatory locking. Advisory locks have no effect on clients that do not explicitly check for a lock.
Mandatory locks do not require clients to explicitly check for locks, but represent a security risk because it is possible to interfere with the normal operation of a system by placing mandatory locks on essential files. For this reason mandatory locks are excluded from the POSIX.1 standard. A platform file system usually supports either advisory or mandatory locking but not both.
Sending the lock:start:len: message to a
CfsFileDescriptor instance sets a segment lock on the file associated with the
CfsFileDescriptor instance. The first argument is one of the file locking constants described in the table in the preceding section. The second argument is an integer specifying the zero-based offset of the first byte to be locked. The third argument is an integer specifying the number of bytes to be locked. If the specified locking constant is not supported, a
CfsError instance is answered. To release a lock, use the
unlock:start:len: message. The arguments are identical. Examples are as follows:
When releasing a lock, the value of the lock type, start, and length arguments must be exactly the same as those used to set the lock. Otherwise the unlock operation can fail or have unpredictable behavior. Using the
size message when releasing a lock as shown in the previous example is
dangerous, because the size might have changed since the lock was set. Instead, save the parameters used when locking and reuse these values when releasing the lock. An example follows: