|
|
Accessing Files Programmer's Guide: HP 3000 MPE/iX Computer Systems > Chapter 5 Opening a FileOpening a Device File |
|
Device files are files that are currently being input to or output from a nonshareable device (any peripheral device except a disk). Because all file open operations are accomplished through the file system, you can open files on very different devices in a standard, consistent way, using the HPFOPEN or FOPEN intrinsics. Furthermore, the name and characteristics assigned to a file when it is defined in a program do not restrict that file to residing on the same device every time the program is run. In these cases, the file system temporarily overrides the programmatic characteristics with those characteristics required by the device. The following topics provide you with further discussions concerning device files, as well as two program examples to illustrate how to open a magnetic tape file:
Certain physical and access characteristics for device files are restricted by the devices on which the file resides. For your convenience, device-dependent restrictions for several devices are summarized in Table 5-1 “Device-Dependent Restrictions”. Table 5-1 Device-Dependent Restrictions
When a process accesses a device file (a file that resides on a nonshareable device), the device's attributes may override information passed in the domain option of the HPFOPEN/FOPEN call. Devices used for input only are considered permanent files. Devices used for output only, such as line printers, are considered new files. Serial input/output devices, such as terminals and magnetic tape drives, follow the domain option specification in your HPFOPEN/FOPEN call
When your job or session attempts to open a permanent file on a nonshareable device, MPE/iX searches for the file in the input device directory (IDD). If the file is not found, a message is transmitted to the system console requesting the system operator to locate the file by taking one of the following steps:
When you use the device name option or device class option of HPFOPEN/FOPEN to open a file on a nonshareable device (other than magnetic tape), you are requesting that an unused device be allocated to your job or session. The first available device is allocated to your job or session; the System Operator is not required to intervene. The device is immediately available if it is not being used by another job or session, or if is already allocated to your job or session by a previous HPFOPEN/FOPEN call. If the device is already allocated to your job or session, you can specify that device by passing its logical device number (LDEV) in the device name option of HPFOPEN/FOPEN. Be certain, though, that you don't invoke a file equation that overrides the LDEV. (You can use the FFILEINFO intrinsic to determine the LDEV assigned to an opened file.) When you use the device name option or device class option of HPFOPEN/FOPEN to open a file on a magnetic tape drive, operator intervention is usually required. The operator must make the tape available, unless the tape is already mounted and recognized by MPE/iX, it is auto-allocating, or if the tape drive is already allocated to the job or session. Example 5-5 is an HP Pascal/iX code segment containing an HPFOPEN intrinsic call that opens an unlabeled magnetic tape file TAPEFILE. The intrinsic call assumes that the tape drive associated with device class TAPE supports a density of 1600 bpi. Example 5-5. Opening an Unlabeled Magnetic Tape File
If the HPFOPEN call is successful, a positive integer value is returned in tfile_num, and status returns a value of zero. The file is now open and can be accessed with file system intrinsics. If an error or warning condition is encountered by HPFOPEN, status returns a nonzero value, thus invoking the error-handling procedure handle_file_error. In appendix A, "HP Pascal/iX Program Examples," Example A-1 uses a similar procedure to open an unlabeled magnetic tape file. For more information about HPFOPEN parameters, refer to the MPE/iX Intrinsics Reference Manual (32650-90028). Example 5-6 is an HP Pascal/iX code segment containing an HPFOPEN intrinsic call that opens a labeled magnetic tape file labltape. Use of the HPFOPEN labeled tape label option indicates to the file system that the file is opened as a labeled magnetic tape file. Example 5-6. Opening a Labeled Magnetic Tape File
If the HPFOPEN call is successful, a positive integer value is returned in file_num and status returns a value of zero. The magnetic tape files is now open and ready to be accessed. If an error or warning condition is encountered by HPFOPEN, status returns a nonzero value, thus invoking the error-handling procedure handle_file_error. In appendix A "HP Pascal/iX Program Examples," Example A-2 uses a similar procedure to open a labeled magnetic tape file. For more information about HPFOPEN parameters, refer to the MPE/iX Intrinsics Reference Manual (32650-90028). |
|