Using Mapped Access to a File

The MPE/iX File System emplo ys access to mapped ￿les, accessible through the use of pointers in the HPFOPEN intrinsic. A mapped ￿le is a ￿le that can be accessed directly through machine loads and stores, b ypassing File System in trinsics normally used for disc ￿les.

Mapped access is not a vailable through the standard Input/Output statemen ts of most programming languages. Th us, the programmatic use of HPFOPEN adds capability to programs. You can achieve mapped access to a ￿le b y declaring a poin ter in a program and passing it to the HPFOPEN intrinsic. The poin ter is initialized to poin t to the beginning of the data area of the opened ￿le.

After HPFOPEN returns the address of the ￿le, simply reference the poin ter as an array or an y type you want. The machine architecture translates the address to a ￿le page and ensures integrity and protection of the ￿le.

Standard disc ￿les with ￿xed-length or unde￿ned-length record formats are allow ed any type of access (Read, Write, Read/Write, and so on) when opened for mapped access. The following ￿le types are allowed Read Only access when opened for mapped access:

Standard disc ￿les with v ariable-length record formats KSAM ￿les (with COPY mode enabled)The following ￿le types cannot be opened for mapped access: Relative I/O (RIO) ￿les Message (MSG) ￿les Circular (CIR) ￿les KSAM ￿les (with COPY mode disabled) Device ￿les

The File System pro vides protection b y keeping a list of ￿le righ ts. When a page fault or protection fault occurs, it c hecks the list. If y ou pass the securit y check, your protection ID is placed in a range of pages allowing access to the ￿le.

All File System and data transfer in trinsics applicable to the ￿le can be used with a mapped ￿le. When mixing FREAD and FWRITE calls with mapped access, y ou must consider the ￿le's data type (ASCII or binary), record format, and record size to ensure that data written to the ￿le using mapped access mak es sense when read by FREAD.

When you open a ￿le using mapped access and write data to it, y ou must use the FPOINT and FCONTROL intrinsics to reset end-of-￿le ( EOF) before closing the ￿le. Otherwise, all data written to the ￿le is lost when y ou close it. In the case of a newly created ￿le, the EOF initially points to record zero. Mapped accessing of a ￿le b ypasses File System services that, otherwise, automatically set v arious File System poin ters, including EOF and the logical record poin ter. You are responsible for resetting EOF prior to closing the ￿le.

For detailed information on the adv antages of mapped access to ￿les, refer to Accessing Files Programmer's Guide (32650-90017).

Device File Buffers

A bu￿er is an area in memory used b y the File System to hold one bloc k (one physical record) of a ￿le. When a program reads a record from a bu￿ered ￿le, a bloc k is brought into the bu￿er. For detailed information, refer to Accessing Files Pr ogrammer's Guide (32650-90017).

6-34 File System