Creating a Lock on a File or Directory

When you lock a file, other users cannot make changes to it. When a directory is locked, no files within the directory can be changed by other users.

You can lock a file or directory by using the CREATE LOCK command.

To create a lock on a file, specify the file name, file type, and dirid, followed by the type of lock and the duration:
CREate LOCk filename filetype dirid SHAre|EXClusive|UPDate SESsion|LASting
To lock a directory, specify the dirid followed by the type of lock and the duration:
CREate LOCk dirid SHAre|EXClusive|UPDate SESsion|LASting

When you lock a file or directory, you must specify the duration of the lock. A SESSION lock is automatically unlocked at the end of your CMS session or when communication with your file pool is broken. A LASTING lock can only be removed with the DELETE LOCK command.

If you have read authority to a file or directory, you can only create a SHARE lock on that file or directory. If you have write authority, you can create any type of lock (SHARE, EXCLUSIVE, or UPDATE) on the file or directory.

The following table shows the meaning of each type of lock for a file or directory.

Type File Directory
UPDATE Other users may read the file while you are reading or updating it. They cannot change, rename, relocate, or erase the file. The person who locked the directory can read from or write to any files for which that person is authorized. Other users may only read files in the directory; they cannot write to the files (even if they have write authority to them). Nor can they create, delete, rename, or relocate any base file, alias, or subdirectory in the directory.
EXCLUSIVE Other users cannot read from or write to the file. Other users cannot read from or write to any of the base files or aliases in the directory. Also, they cannot create, erase, rename, or relocate any base files or aliases until the directory is unlocked.
SHARE Other users can read the file while you are reading it. No one, including the person who locked the file, can update the file until it is unlocked. Also, no users can rename, relocate, or erase the file. Other users and the person who locked the directory can read from files in the directory (if they are authorized to do so). No users (including the person who created the lock) can update any files or subdirectories in the directory. Nor can they create, erase, rename, or relocate any base files, aliases, or subdirectories until the directory is unlocked.

Note: If you create a lock on an alias, it is the same as locking the base file—the owner of the base file and other users with aliases to the file will be affected by the lock.

Except for UPDATE the above lock types apply only to file control directories and to files within file control directories. (Remember that, by default, the directories you create are file control directories.)