#define INCL_DOSERRORS #define INCL_DOSFILEMGR #include <os2.h> APIRET APIENTRY DosSetFileLocks(HFILE FileHandle, PFILELOCK ppUnLockRange, PFILELOCK ppLockRange, ULONG ulTimeOut, ULONG ulFlags);Service Program Name: QP0LLIB1
The DosSetFileLocks() function locks and unlocks a range of an open file. A non-zero range indicates that a lock or unlock request is being made.
The following values are to be specified in ulFlags:
If this bit is set to 0 (the default), other processes have no access to the locked file range. The current process has exclusive access to the locked file range, which must not overlap any other locked file range.
If this bit is set to 1, the current process and other processes have shared access to the locked file range. A file range with shared access may overlap any other file range with shared access, but must not overlap any other file range with exclusive access.
No authorization is required.
If DosSetFileLocks() is not successful, the value that is returned is one of the following errors. The <bseerr.h> header file defines these values.
A general failure occurred.
This may result from damage in the system. Refer to messages in the job log for other possible causes.
An invalid file handle was found.
The file handle passed to this function is not valid.
A lock violation was found.
The requested lock and unlock ranges are both zero.
An invalid parameter was found.
A parameter passed to this function is not valid.
The byte range specified by the offset and length in the ppUnlockRange or ppLockRange parameters extends beyond 2GB minus 1 byte.
The atomic lock operation is not supported.
The file system does not support atomic lock operations.
The lock timer value is not supported.
The file system does not support the lock timer value.
The system may send the following messages from this function.
Message ID | Error Message Text |
---|---|
CPE3418 E | Possible APAR condition or hardware failure. |
CPFA0D4 E | File system error occurred. Error number &1. |
CPF3CF2 E | Error(s) occurred during running of &1 API. |
CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
Also, the following file systems do not support the atomic locking flag. If you turn on the atomic locking flag, an ERROR_ATOMIC_LOCKS_NOT_SUPPORTED error is returned.
See Code disclaimer information for information pertaining to code examples.
The following example opens, locks, and unlocks a file.
#define INCL_DOSERRORS #define INCL_DOSFILEMGR #include <os2.h> #include <stdio.h> #define NULL_RANGE 0L #define LOCK_FLAGS 0 main() { char fn[]="lock.file"; char buf[] = "Test data for locking and unlocking range of a file"; int fd; ULONG lockTimeout = 2000; /* lock timeout of 2 seconds */ FILELOCK Area; /* area of file to lock/unlock */ Area.Offset = 4; /* start locking at byte 4 */ Area.Range = 10; /* lock 10 bytes for the file */ /* Create a file for this example */ fd = creat(fn, S_IWUSR | S_IRUSR); /* Write some data to the file */ write(fd, buf, sizof(buf) -1); close(fd); /* Open the file */ if ((fd = open(fn, O_RDWR) < 0) { perror("open() error"); return; } /* Lock a range */ rc = DosSetFileLocks((HFILE)fd, NULL_RANGE, &Area, &LockTimeout, LOCK_FLAGS); if(rc != 0) /* Lock failed */ { perror("DosSetFileLocks() error"); } /* Unlock a range */ rc = DosSetFileLocks((HFILE)fd, &Area, NULL_RANGE, &LockTimeout, LOCK_FLAGS); if(rc != 0) /* Unlock failed */ { perror("DosSetFileLocks() error"); } close(fd); unlink(fn); }
Top | UNIX-Type APIs | APIs by category |