5.2 File Locks

All DFS application file, record, and field locks must be provided and managed by the DFS application NLM. OS utilities that are designed to perform reorganization or relocation of DFS files use an exclusive lock on the file, so that the lock fails if the file is currently in use by an application NLM. An application NLM need only lock the file with a shared or nonexclusive lock to ensure that an OS utility NLM has not exclusively locked the file for operations such as reorganization.

An application NLM should make sure that the current connection ID matches the connection ID of the client so that OS Auditing is meaningful. However, auditing of database record and field accesses require that the database application NLM perform its own auditing, since DFS is not aware of the actual record and field definitions.

5.2.1 Input and Output

An open file is in one of two possible modes: normal mode or direct mode. In a normal open mode, any of the valid opens are used. For direct open mode, the DFSsopen function is used. If a file is already open in normal mode and DFSsopen is called, the file changes from the normal mode to the direct mode.

In this condition, any files in the normal open mode can continue to be read, but attempts to write to the file fail. Programs using the direct mode can read and write to the file successfully. The only way to write to files in the normal open mode again is by closing all direct mode opens, and closing and re-opening the normal mode open.

When a file is successfully opened for direct file I/O by calling DFSsopen, the server opens the file, flushes all cache entries for the file, and flags the file so that future I/Os do not use caching and TTS functions. Subsequent file I/O must be done using the I/O functions DFSRead, DFSReadNoWait, DFSWrite, or DFSWriteNoWait. The "no wait" versions of these functions do not block execution of the thread until completion, thus allowing a single thread to have multiple outstanding DFS I/O functions.

When direct file I/O operations are completed, the file must be closed by calling DFSclose. The file must not be used for normal I/O writes until all handles are relinquished for the file by calling DFSclose, followed by a normal open. If a normal open exists, it must be closed and reopened for read/writes.

When a file is in Direct mode, writes must not be made to areas of the file where a hole exists (sparse files) or beyond the file’s currently allocated last block address. Read operations to these areas are indicated successful and the data area is zeroed.

Also, a file cannot be extended while in Direct mode by writing beyond its current extents. A separate call to DFSExpandFile must be made to extend a file or to fill in holes in a file area.