HPlogo Getting Started as an MPE/iX Programmer Programmer's Guide: HP 3000 Computer MPE/iX Computer Systems > Chapter 6 File System

Sharing a File

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

Accessing and controlling a file that is open only to you is a relatively simple matter. However, when several users are simultaneously accessing a file, each user must be aware of special considerations for sharing the file:

  • How will others be allowed concurrent access to the file?

  • Will concurrent access require special management?

When an HPFOPEN or FOPEN intrinsic call is issued for a file, the File System regards the request as an individual accessor of the file and establishes a unique file number and other file control information for the file. Even when a program issues several different HPFOPEN or FOPEN intrinsic calls for the same file, each call is treated as a separate accessor. Under the normal (default) security provisions of MPE/iX, when an accessor opens a file not currently in use, the access restrictions that apply to this file for other accessors depend on the access mode this first accessor requested:

  • If the first accessor opens a file for read-only access, then any other accessor can open it for any other type of access (for example, write-only or append). However, the other accessors are prohibited exclusive access.

  • If the first accessor opens a file for any other access mode (for example, write-only, append, or update), this accessor maintains exclusive access to the file until it closes it; no other accessor can access the file in any mode.

A program can override the defaults by specifying other options in HPFOPEN and FOPEN intrinsic calls. A user running this program can, in turn, override both the defaults and programmatic options by using the :FILE command. Table 6-7 “File Sharing Restriction Options” describes these options and the actions MPE/iX takes when the options are in effect and simultaneous access is attempted by other HPFOPEN or FOPEN intrinsic calls. The action depends on the current use of the file and the access requested.

Table 6-7 File Sharing Restriction Options

Access Restrictions:FILE ParametersDescription
   
Exclusive AccessEXCAfter you open a file, prohibits concurrent access in any mode through another HPFOPEN/FOPEN request by any program (including this one), until this program issues FCLOSE or terminates.
Exclusive Write AccessSEMIAfter you open a file, prohibits concurrent write access through another HPFOPEN/FOPEN request by any program (including this one), until this program issues FCLOSE or terminates.
Sharable AccessSHRAfter you open a file, allows concurrent access in any mode through another HPFOPEN/FOPEN request by any program (including this one), in any session or job (including this one).
   

 

The Exclusive Access option is useful to update a file and prevent other users or programs from reading, writing, or altering information that is about to be changed.

The Exclusive-write Access option allows other accessors to read the file but prevents them from altering it. For example, it is useful for updating a parts list, where you want to append new part numbers, without prohibiting other users from reading current part numbers.

The Sharable Access option allows a file to be shared in all access modes by requests from multiple programs. It is useful for allowing several users to read different parts of the same file. Effectively, each accessor accesses its own copy of the portion of the file in the accessor's buffer.

For detailed information on Exclusive, Exclusive-write, and Sharable Access, refer to Accessing Files Programmer's Guide (32650-90017).

The multi-access option extends the features of Sharable Access to allow a deeper level of multiple access. It makes the file simultaneously available to other accessors in the same job or session and permits them to use the record pointer and other file-control information. When several concurrently running programs (processes) are writing to the file, the effect on the file is the same as if one program were performing all output. Multi-access provides truly sequential access by several concurrently running programs.

Global multi-access permits simultaneous access to a file by processes in different jobs or sessions. Figure 6-15 “Actions Resulting from Multiaccess of Files” shows the action resulting from multi-access of files.

For detailed information on the multi-access and global multi-access options, refer to Accessing Files Programmer's Guide (32650-90017).

Figure 6-15 Actions Resulting from Multiaccess of Files

[Actions Resulting from Multiaccess of Files]

When a file is shared among two or more processes and one or more of the processes is writing to it, the processes must be properly interlocked to prevent undesirable results. The FLOCK and FUNLOCK intrinsics provide the necessary interlocking by using a Resource Identification Number (RIN) as a flag to interlock multiple accessors. For detailed information on this topic, refer to Accessing Files Programmer's Guide (32650-90017) and MPE/iX Intrinsics Reference Manual (32650-90028).