HPlogo Accessing Files Programmer's Guide > Chapter 2 Creating A File

The HPFOPEN Intrinsic

MPE documents

Complete PDF
Table of Contents
Index

E0300 Edition 6 ♥
E0692 Edition 5

The HPFOPEN intrinsic establishes access to a disk or device file and enables you to create a file on a shareable device. HPFOPEN is used to define a file's physical characteristics, including file and record structure. Its syntax is

  HPFOPEN (filenum, status, [, itemnum, item]...);

The HPFOPEN optional parameters are a superset of the options provided in the FOPEN intrinsic and provide more efficient access to files.

NOWAIT I/O


Sometimes a programmer wants an application to read or write a record, but does not want it to wait for I/O to complete. For such an application, waiting is wasting time when it could be doing other processing. Timeouts do not adequately address this problem. The programmer wants this application to start an I/O, continue processing immediately, and check periodically to see if the I/O has finished.

MPE/iX provides a way to solve this problem with NOWAIT I/O. This feature is requested by enabling the NOWAIT I/O option (item #16) in HPFOPEN.

When using NOWAIT I/O, the process must make at least two intrinsic calls to perform the I/O, one to start it and one to finish it. MPE/iX still handles the file in the same way; but instead of waiting for the I/O to complete, MPE/iX returns control to the application so that the application can do some useful processing.

NOWAIT I/O has been available to users of standard files for a long time, but to use it on standard files requires privileged mode. On standard files the mechanics of NOWAIT I/O prevent MPE/iX from protecting a process from corrupting its own stack; however, because message files work differently, NOWAIT I/O on message files does not require privileged mode.

NOWAIT I/O intrinsics


To perform a NOWAIT I/O, the FREAD or FWRITE intrinsic must be called to initiate the transfer. These intrinsics return immediately, and no data is transferred yet. The return value for FREAD is set to zero and is not needed. To complete the transfer, either IODONTWAIT or IOWAIT must be called. IODONTWAIT tests whether the I/O has finished. If it has, the intrinsic returns a condition code of CCE and the file number as the return value. If the I/O has not completed, CCE and a zero return value are passed back. If IOWAIT is called, it waits until the I/O has finished, like a normal WAIT I/O FREAD or FWRITE.

Only one NOWAIT I/O can be outstanding against a file by a particular accessor at a time; however, an accessor can have NOWAIT I/Os outstanding against several files at the same time. These I/Os can be completed by a "generalized" IODONTWAIT or IOWAIT: the file number parameter is zero or is omitted. In this case, these intrinsics report on the first I/O to complete, returning the file number for that file. If the call to one of these intrinsics is in a loop, then that one call can be used to complete all the NOWAIT I/Os.

Aborting NOWAIT I/O


Occasionally, after a process has started a NOWAIT I/O with FREAD or FWRITE, something occurs that causes completion of that I/O to be no longer needed. Perhaps the process is "shutting down" and does not want to wait for the I/O (that is, to issue IOWAIT or IODONTWAIT).

MPE/iX lets the process abort NOWAIT I/Os that have not yet completed by using FCONTROL with a control code of 43. A condition code of CCE is returned if the I/O was aborted; in this case, nothing more needs to be done. CCG is returned if the I/O has already completed; in this case, IODONTWAIT or IOWAIT must be called to clear it. CCL and FSERR 79, No NOWAIT I/O pending for special file are returned if there was nothing to abort.

Limitations


Currently, MPE/iX does not support NOWAIT I/O to message files across a network. In most cases, this is not an important limitation, because it is rare that both readers and writers to the same message file need to use NOWAIT I/O. If the file is made local to the accessor that needs NOWAIT I/O, the other accessor can then do WAIT I/O across the network.

More information on these intrinsics is found in the MPE/iX Intrinsics Reference Manual. For detailed information about WAIT and NOWAIT, consult the Interprocess Communications Programmers' Guide.

The following lists the optional parameters you can use to specify a file's physical characteristics, as well as the default values for each.

Itemnum, Item Description

Optional parameters you can use to specify file access and device control characteristics are described elsewhere in this manual. For more details on the HPFOPEN intrinsic, refer to the MPE/iX Intrinsics Reference Manual.




Chapter 2 Creating A File


The FOPEN Intrinsic