File Accessing Modes


 

Any file may be opened or prepared in one of four access modes; SHARE, SHARENF, EXCLUSIVE, or READ. Files may also be accessed in modes other than the ones they were originally created in or may be accessed in more than one mode at a time within the rules for each mode described in the following subsections.

 

EXCLUSIVE File Accessing

 

The EXCLUSIVE access mode is optional for all prepare and open operations and designates limited accessibility to the file. The following rules apply to the EXCLUSIVE access mode:

  1. An attempt to open a file in EXCLUSIVE mode that is currently being used in SHARE or SHARENF mode or is write-protected will generate an error.

  2. A system open on the file is only performed upon execution of an open or prepare operation. The file remains open until the file is explicitly closed or the program terminates.

  3. The data is not automatically flushed to disk after each operation nor is the system directory continuously updated. Data remains in memory until the internal buffer is full or a close, open, or prepare instruction is executed for this same logical file name.

  4. Data files opened in EXCLUSIVE mode are not protected against premature termination of the program since the system directory is not being continuously updated.

  5. How users of other programs will be affected by a file opened in EXCLUSIVE mode depends upon the multi-user system in use. In most multi-user implementations, a file opened in EXCLUSIVE mode is locked and unavailable for SHARE, SHARENF, or EXCLUSIVE mode access by other programs. Files opened in EXCLUSIVE mode may only be accessed by other programs that use READ mode for the file.

  6. Throughput from files opened in EXCLUSIVE mode is faster than those in SHARE or SHARENF mode.

  7. EXCLUSIVE mode is solely recommended for inquiry only files or files that just one user will be allowed to update.

 

 

READ (Only) File Accessing

 

The READ access mode is optional for prepare and open operations and designates the file is used for inquiry (read only) purposes. The following rules apply to the READ access mode:

  1. READ mode accesses files that were opened in either EXCLUSIVE, SHARE, or SHARENF mode by another process or are write-protected. An attempt to perform an output operation to a file opened in READ mode by the program will generate an I/O error.

  2. A system open on the file is only performed upon execution of an open or prepare operation. The file remains open until the file is closed or the program terminates.

  3. Throughput from files opened in READ mode is faster than those in SHARE or SHARENF mode.

  4. READ mode is useful for inquiry only purposes.

  5. If a program has a file open in SHARE mode and also in READ or EXCLUSIVE mode, the results are indeterminate.

 

 

SHARE File Accessing

 

The SHARE access mode is the default mode for all file prepare and open operations and designates that the file is shareable. The following rules apply to the SHARE access mode:

  1. An attempt to open a file already opened in EXCLUSIVE mode by another program or a file that is write-protected will generate a trappable I/O error.

  2. SHARE mode files offer the maximum data integrity of the four access modes.

  3. Any file opened in SHARE mode will have its contents and directory entry continuously updated for each transaction that takes place. For this reason, files accessed in SHARE mode are protected from premature termination of the program due to errors or system failure as well as being flushed for data secure multi-user access. Due to the efforts required to insure the aforementioned, overall throughput using SHARE mode is somewhat less than that of SHARENF, EXCLUSIVE, or READ mode files.

  4. Even in SHARE mode, it still remains the responsibility of the programmer to design the application for correct multi-user access (through use of FILEPI, etc.)

 

SHARE or SHARENF mode must be used if a physical text file is updated by more than one user simultaneously or through more than one key file within the program.

 

The actual file access mode constants that have been defined are as follows:

 

Constant

Value

Meaning

SA_EOR_MASK

0x0000000F

Mask for all EOR bit definitions

SA_EOR_CR

0x00000001

Mode input requests EOR type CR only

SA_EOR_CRLF

0x00000002

Mode input requests EOR type CRLF

SA_EOR_LF

0x00000004

Mode input requests EOR type LF only

SA_EOR_LFCR

0x00000008

Mode input requests EOR type LFCR

SA_OPEN_MASK

0x00000070

File mode mask in open or prepare.

SA_SHARE

0x00000000

Share mode requested in open or prepare

SA_EXCLUSIVE

0x00000010

Exclusive mode requested in open or prepare

SA_SHARENF

0x00000020

Share NoFlush requested in open or prepare

SA_READ

0x00000040

Read mode requested in open or prepare

SA_PREPOVERMFD

0x00000200

DO NOT Prep using SUNDM

SA_NOPREPTRUNC

0x00000400

Prep AAM or ISI file with truncating text file

SA_FIXED

0x00001000

Records are fixed length; otherwise variable length

SA_COMPRESSED

0x00002000

Records are compressed; otherwise uncompressed

 

 



Sunaccess Reference Associative Access Method Managed File Support