Getting Started as an MPE/iX Programmer Programmer's Guide: HP 3000 Computer MPE/iX Computer Systems > Chapter 6 File SystemSharing a File |
|
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:
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:
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
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). 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). |