HP 3000 Manuals

Opening a Device File [ Accessing Files Programmer's Guide ] MPE/iX 5.0 Documentation


Accessing Files Programmer's Guide

Opening 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:

   *   "Device-Dependent File Characteristics" discusses those file
       characteristics affected by particular devices.

   *   "New and permanent device files" discusses the domains required by
       various input/output devices.

   *   "Opening an unlabeled magnetic tape file" shows an example of an
       HPFOPEN call that opens an unlabeled magnetic tape file (see
       example 5-5).

   *   "Opening a labeled magnetic tape file" shows an example of an
       HPFOPEN call that opens a labeled magnetic tape file (see example
       5-6).

Device-dependent file characteristics 

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 .

          Table 5-1.  Device-Dependent Restrictions 

------------------------------------------------------------------------------------------------
|                                        |                                                     |
|              DEVICE TYPE               |           RESTRICTED FILE CHARACTERISTICS           |
|                                        |                                                     |
------------------------------------------------------------------------------------------------
|                                        |                                                     |
| Terminal                               | record format option = undefined-length records     |
| (parallel input/output device)         |                                                     |
|                                        | block factor option = 1                             |
|                                        |                                                     |
|                                        | inhibit buffering option = NOBUF                    |
|                                        |                                                     |
|                                        | ASCII/binary option = ASCII                         |
|                                        |                                                     |
| Magnetic tape drive                    | No restrictions                                     |
| (serial input/output device)           |                                                     |
|                                        |                                                     |
| Line printer/plotter                   | domain option = NEW                                 |
| (serial output device)                 |                                                     |
|                                        | record format option = undefined-length records     |
|                                        |                                                     |
|                                        | access type option = Write only                     |
|                                        |                                                     |
|                                        | block factor option = 1                             |
|                                        |                                                     |
| Laser printer                          | Initially and always spooled                        |
| (serial output device)                 |                                                     |
|                                        | access type option = Write only                     |
|                                        | All other restrictions same as for line printer     |
|                                        |                                                     |
------------------------------------------------------------------------------------------------

New and permanent device files 

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.


NOTE The HPFOPEN intrinsic assumes that all files on nonshareable devices (device files) are permanent files. To maintain compatibility with MPE V/E, device files can be opened with the domain option specifying a new file, but a warning is returned in the status parameter.
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: * Indicate that the file resides on a device that is not in auto-recognition mode. No DATA command is required; the System Operator simply allocates the device. * Make the file available on an auto-recognizing device, and allocate that device. * Indicate that the file does not exist on any device; in this case, your HPFOPEN/FOPEN request is rejected. 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. Opening an unlabeled magnetic tape file 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 procedure open_unlabeled_magnetic_tape_file; const formal_designator_option = 2; {defines HPFOPEN itemnum 2 } domain_option = 3; {defines HPFOPEN itemnum 3 } access_type_option =11; {defines HPFOPEN itemnum 11 } density_option =24; {defines HPFOPEN itemnum 24 } device_class_option =42; {defines HPFOPEN itemnum 42 } type pac80 = packed array [1..80] of char; var tfile_num : integer; {required HPFOPEN filenum parameter } status : integer; {returns info if error/warning occurs} file_name : pac80; {declares HPFOPEN itemnum 2 } permanent : integer; {declares HPFOPEN itemnum 3 } update only : integer; {declares HPFOPEN itemnum 11 } device_class : pac80 {declares HPFOPEN itemnum 24 } density : integer; {declares HPFOPEN itemnum 42 } begin tfile_num :=0; status :=0; file_name :='&tapefile&'; {delimiter is "&" } permanent :=1; {search system file domain } update_only :=5; {preserves existing data } density :=1600; {select this tape density } device_class :='&tape&'; {system-configured device class name } HPFOPEN (tfile_num, status, formal_designator_option, file_name, {formaldesignator option} domain_option, permanent, {domain option} access_type_option, update_only {access type option} density_option, density, {density option} device_class_option, device_class {device class option} ); if status <> 0 then handle_file_error (tfile_num, status); end; 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). Opening a labeled magnetic tape file 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 procedure open_labeled_magnetic_tape_file; const formal_designator_option = 2; {defines HPFOPEN itemnum 2 } domain_option = 3; {defines HPFOPEN itemnum 3 } tape_label_option = 8; {defines HPFOPEN itemnum 8 } tape_expiration_option =31; {defines HPFOPEN itemnum 31 } device_class_option =42; {defines HPFOPEN itemnum 42 } type pac80 = packed array [1..80] of char; var file_num : integer; {required HPFOPEN filenum parameter } status : integer; {returns info if error/warning occurs } file_name : pac80; {declares HPFOPEN itemnum 2 } old : integer; {declares HPFOPEN itemnum 3 } tape_label : pac80; {declares HPFOPEN itemnum 8 } expire_date : pac80 {declares HPFOPEN itemnum 31 } device_class : pac80 {declares HPFOPEN itemnum 42 } begin file_num :=0; status :=0; file_name :='&labltape&'; {delimiter is "&" } old :=3; {equivalent to specifying permanent} tape_label :='&tape01&'; {ANSI tape label } expire_date :='&05/20/87&' {when data is no longer useful } device_class :='&tape&'; {system-configured device name } HPFOPEN (file_num, status, formal_designator_option, file_name, {formaldesignator option} domain_option, old, {domain option} tape_label_option, tape_label, {labeled tape label option} tape_expiration_option, expire_date, {labeled tape expiration option} device_class_option, device_class {device class option} ); if status <> 0 then handle_file_error (file_num, status); end; 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).


MPE/iX 5.0 Documentation