Accessing Files Programmer's Guide (32650-90885)
91
5 Opening a File
Before your program can read, write, or otherwise manipulate a file, the program must
initiate access to that file by opening it with the HPFOPEN/FOPEN intrinsic call. This call
applies to both disk files and device files. This chapter discusses how you can use HPFOPEN
to open various types of files supported by MPE/iX. Examples of program segments are
provided to illustrate HPFOPEN calls.
This chapter is divided into the following subjects:
• how the file system opens a file
• which to use: HPFOPEN or FOPEN?
• opening a disk file
• opening a system-defined file
• opening a device file
How the File System Opens a File
When you open a file, HPFOPEN/FOPEN establishes a communication link between the file
and your program by
• Determining the device on which the file resides.
• Allocating to your process the device on which the file resides. Disk files generally can
be shared concurrently among jobs and sessions. Magnetic tape and unit-record devices
are generally allocated exclusively to the requesting job or session.
If the file resides on a nonshareable device (such as magnetic tape) and you have
nonshareable device (ND) capability, HPFOPEN/FOPEN determines whether the system
operator must approve allocation of the device (such as an unlabeled magnetic tape) or
provide a particular media (such as a specific volume for a labeled magnetic tape
request or special forms for a line printer). If so, HPFOPEN/FOPEN requests the system
operator to respond appropriately.
Different processes within the same job may open and have concurrent access to a file
on the same magnetic tape or unit-record device if the file has been opened with
multiaccess option
set; however, this device cannot be accessed by another job until
all accessing processes in this job have issued a corresponding FCLOSE call.
• Verifying your right to access the file under the security provisions existing at the
account, group, and file levels.