![]() |
Accessing Files Programmer's Guide
> Chapter 5 Opening a FileOpening a Device File |
|||||||||||||||||||||||||||||||||
|
Device-dependent file characteristicsCertain 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
New and permanent device filesWhen 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.
Opening an unlabeled magnetic tape fileExample 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 err/warn 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.
Opening a labeled magnetic tape fileExample 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 err/warn 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.
|