- /* see if it's locked by another fork.
- * NOTE: this guarantees that any existing locks must be at most
- * read locks. we use ADLOCK_WR/RD because F_RD/WRLCK aren't
- * guaranteed to be ORable. */
- if (adf_findxlock(adf, fork, ADLOCK_WR |
- ((type & ADLOCK_WR) ? ADLOCK_RD : 0),
- lock.l_start, lock.l_len) > -1) {
- errno = EACCES;
- return -1;
- }
-
- /* look for any existing lock that we may have */
- i = adf_findlock(adf, fork, ADLOCK_RD | ADLOCK_WR, lock.l_start, lock.l_len);
- adflock = (i < 0) ? NULL : adf->adf_lock + i;
-
- /* here's what we check for:
- 1) we're trying to re-lock a lock, but we didn't specify an update.
- 2) we're trying to free only part of a lock.
- 3) we're trying to free a non-existent lock. */
- if ( (!adflock && (lock.l_type == F_UNLCK))
- ||
- (adflock
- && !(type & ADLOCK_UPGRADE)
- && ((lock.l_type != F_UNLCK)
- || (adflock->lock.l_start != lock.l_start)
- || (adflock->lock.l_len != lock.l_len) ))
- ) {
- errno = EINVAL;
- return -1;
- }