Record Selection and Data Transfer [ Getting Started as an MPE/iX Programmer Programmer's Guide ] MPE/iX 5.0 Documentation
Getting Started as an MPE/iX Programmer Programmer's Guide
Record Selection and Data Transfer
Data is transferred in the File System by a mechanism including records,
record pointers, and the intrinsics for transferring them.
Record Pointers
The File System uses record pointers to find specific records for use.
Record pointers block and deblock records and indicate specific records
in a file. A file opened with the inhibit buffering option parameter set
to BUF (the default) is accessed by using a record pointer. (A file
opened with the inhibit buffering option parameter set to NOBUF is
accessed via a block pointer.)
NOTE Buffering does not apply to ordinary disk files.
Pointer Initialization
When you open a file, the HPFOPEN or FOPEN intrinsic sets the record
pointer to record 0 (the first record in the file) for all operations.
If you have opened the file with Append access (using the access type
option parameter), MPE/iX moves the record pointer to the end of the file
prior to a write operation. This ensures that any data you write to the
file is added to the end of the file instead of written over existing
data. (Append and other access types are described later in this
manual.) Following initialization, the record pointer can remain in
position at the head of your file, or it can be moved by the intrinsics
used in record selection (for example, FREAD, FWRITE, and FPOINT).
Record Selection
Various File System intrinsics are designed to transfer records to and
from files. The record pointer indicates the specific location where a
file can be accessed. Records can be transferred to or from this
location, or the pointer can be moved to another place in the file you
wish to access.
There are five methods of record selection for accessing a file:
* Sequential access, in which you transfer data to and from the
place the record pointer currently indicates.
* Random access, in which you use FPOINT to move the record pointer
before transferring data, or you use FREADDIR to choose it at
access time.
* Update access, in which you choose a record and write a new record
over it.
* RIO access, in which you access only records that are activated.
* Mapped access is a special type of access available only through
the HPFOPEN intrinsic, in which you bypass File System data
transfer mechanisms by referencing the file by using a pointer
declared in your program.
For detailed information on record selection methods and the intrinsics
used for data transfer, refer to Accessing Files Programmer's Guide
(32650-90017).
Mapped Access to Disc Files
MPE/iX employs a "mapped files" technique for performing disc file
access. File access efficiency is improved when code and data portions
of files required for processing reside in memory. Accessing memory is
faster than performing physical disc I/O operations. The mapped files
technique eliminates file system buffering and optimizes global system
memory management.
File mapping is based on MPE/iX demand paged virtual memory, which uses
to advantage the large amount of virtual memory on the system. When a
file is opened, it is logically mapped into virtual memory. An open file
and its contents are referenced by virtual addresses. Each byte of each
opened file has a unique virtual address.
File mapping improves I/O performance without imposing additional CPU
overhead or sacrificing data integrity and protection. Traditional disc
caching schemes for increasing I/O performance impose a CPU overhead
penalty. The 900 Series hardware and system architecture allow MPE/iX to
perform file mapping without incurring this penalty. System hardware
performs the virtual to physical address translations for locating
portions of the mapped files, thus eliminating CPU overhead for this
function.
If the required pages are not in memory, the MPE/iX Memory Manager
fetches them directly from disc and places them in memory. This
eliminates File System buffering. Pages are "prefetched" to reduce the
amount of physical disc I/O. Prefetching means that the page specified
for fetching and the group of pages surrounding it are a fetched all at
once. This improves efficiency because the processor is likely to
require pages that are located near each other. Two benefits of this
are:
* Eliminating unnecessary data movement in memory improves system
performance.
* Memory space usage is optimized.
MPE/iX File System access intrinsics are built on the mapped file
technique. Programs using file access methods supported by MPE file
types and intrinsics obtain the benefits of file mapping without
requiring changes.
You can directly access mapped files when programming in Native Mode
languages with pointers by using the HPFOPEN intrinsic. For example, you
can obtain the advantage of File System naming and data protection for
accessing array type structures and developing specialized access
methods.
You can write programs that address files through virtual memory, instead
of calling File System intrinsics for disc reading and writing. The file
interface provides opening and closing of user mapped files with normal
naming and security, but with improved LOAD and STORE speed on file
references.
Multiple Record Transfers
In most applications, programs conduct input and output in normal
recording mode, where each read or write request transfers one logical
record to or from the stack. In specialized applications, however, you
may want a program to read or write, in a single operation, data that
exceeds the logical record length defined for the input or output file.
For example, multirecord transfer may be preferable, as a good
programming practice, for applications that run only on MPE/iX.
You can bypass the normal record-by-record input and output, instead
receiving large data transfers by specifying multirecord mode (MR) by
using the multirecord option parameter in the HPFOPEN or FOPEN call, or
by using the :FILE command. For detailed information and examples on
multiple record transfers, refer to Accessing Files Programmer's Guide
(32650-90017).
Data Transfer Control Operations
To move a record pointer to a particular place without necessarily
transferring data, the following intrinsics perform three types of record
selection:
* FSPACE, provides spacing. It moves the record pointer backward or
forward.
* FPOINT, provides pointing. It resets the record pointer.
* FCONTROL, provides rewinding. It resets the record pointer to
record 0.
For detailed information and examples on spacing, pointing, and
rewinding, refer to Accessing Files Programmer's Guide (32650-90017).
For detail information on FSPACE, FPOINT, and FCONTROL, refer to MPE/iX
Intrinsics Reference Manual (32650-90028).
Reading from a File
There are several ways to move data to a program from a disc file or
device file. The File System intrinsics used for reading data from a
file are:
* FREAD reads a logical record or a portion of a record from a file
to a program.
* FREADDIR reads a specific logical record or portion of a record
from a random access opened disc file to a program.
* READ reads a character string from the job or session input device
($STDIN) to a program.
* READX reads a character string from the job or session input
device, ($STDINX) to a program.
* FREADLABEL reads a user file label from a disc file or labeled
magnetic tape file to a program.
* By referencing a pointer to an open mapped file.
If the standard input device ($STDIN) and the standard list device
($STDLIST) are opened with an HPFOPEN or FOPEN intrinsic call, the FREAD
and FWRITE intrinsics can be used with them. For example, you can use
the FREAD intrinsic to transfer information entered from a terminal to a
buffer in the stack, and you can use the FWRITE intrinsic to directly
transfer information from the stack to the standard list device.
You can use the FREADDIR intrinsic to read a record from a file opened by
the HPFOPEN or FOPEN intrinsic and transfer the record to an array in the
stack. When FREADDIR reaches the end of a file, the end-of-file
condition code CCG is returned. If FREADDIR does not successfully read
information, a CCL condition code is returned.
When a labeled tape file has been opened, you can use the FREAD intrinsic
to read data from the opened file. The system uses the block size,
record size, and file format on the tape label to determine the amount of
data to read. You can call FGETINFO or FFILEINFO to obtain these values.
You can use the FREADLABEL intrinsic to read a user-defined label on a
labeled magnetic tape file. To read a user-defined header, a program
must call FREADLABEL before issuing the first FREAD for the file.
Execution of the first FREAD causes MPE/iX to skip past any unread
user-defined header labels.
Other specialized read intrinsics are READX and FREADLABEL.
For detailed information on reading a file, refer to Accessing Files
Programmer's Guide (32650-90017).
Writing to a File
You can move data from a program to a disc file or to a device file in
several ways. The File System intrinsics used for writing the data are
as follows:
* FWRITE writes a logical or physical record or portion of a record
from your program to a file on any device.
* FWRITEDIR writes a specific logical record from a program to a
disc file.
* PRINT prints a character string from a program to the job or
session listing device, $STDLIST.
* FWRITELABEL writes a user file label from your program onto a disc
file or labeled magnetic tape file.
* By assigning a value to a location specified by a pointer to an
open mapped file.
If the standard input device ($STDIN) and the standard list device
($STDLIST) are opened with an HPFOPEN or FOPEN intrinsic call, the FREAD
and FWRITE intrinsics can be used with these devices. For example, the
FWRITE intrinsic can be used to transfer information from a buffer in
your process stack directly to the standard list device.
A program can use the FWRITEDIR intrinsic to read records from one file
and write them, in reverse order, into a second file. You can use the
FGETINFO intrinsic to locate EOF in the file to be read. This
information is returned to the program in a variable.
You can write to either a labeled or an unlabeled magnetic tape file.
Writing to a labeled tape file differs from writing to an unlabeled tape
file when the user program attempts to write over or beyond the physical
end-of-tape (EOT) marker.
For detailed information on writing to a file, refer to Accessing Files
Programmer's Guide (32650-90017).
Updating a File
The FUPDATE intrinsic updates a logical record of a disc file. It
affects the last logical record (or block for NOBUF files) accessed by
any intrinsic call for the file named and writes information from a
buffer in the stack into this record. Following the update operation,
the record pointer is set to indicate the next record position.
As a physical data storage device, magnetic tape is not designed to
enable the replacement of a single record in an existing file. An
attempt to perform this type of operation causes problems in maintaining
the integrity of records on the tape. Magnetic tape files, therefore,
should not be maintained (updated) on an individual record basis, but
should be updated during copy operations from one file to another. For
detailed information on updating files, refer to Accessing Files
Programmer's Guide (32650-90017).
Using Mapped Access to a File
The MPE/iX File System employs access to mapped files, accessible through
the use of pointers in the HPFOPEN intrinsic. A mapped file is a file
that can be accessed directly through machine loads and stores, bypassing
File System intrinsics normally used for disc files.
Mapped access is not available through the standard Input/Output
statements of most programming languages. Thus, the programmatic use of
HPFOPEN adds capability to programs. You can achieve mapped access to a
file by declaring a pointer in a program and passing it to the HPFOPEN
intrinsic. The pointer is initialized to point to the beginning of the
data area of the opened file.
After HPFOPEN returns the address of the file, simply reference the
pointer as an array or any type you want. The machine architecture
translates the address to a file page and ensures integrity and
protection of the file.
Standard disc files with fixed-length or undefined-length record formats
are allowed any type of access (Read, Write, Read/Write, and so on) when
opened for mapped access. The following file types are allowed Read Only
access when opened for mapped access:
* Standard disc files with variable-length record formats
* KSAM files (with COPY mode enabled)
The following file types cannot be opened for mapped access:
* Relative I/O (RIO) files
* Message (MSG) files
* Circular (CIR) files
* KSAM files (with COPY mode disabled)
* Device files
The File System provides protection by keeping a list of file rights.
When a page fault or protection fault occurs, it checks the list. If you
pass the security check, your protection ID is placed in a range of pages
allowing access to the file.
All File System and data transfer intrinsics applicable to the file can
be used with a mapped file. When mixing FREAD and FWRITE calls with
mapped access, you must consider the file's data type (ASCII or binary),
record format, and record size to ensure that data written to the file
using mapped access makes sense when read by FREAD.
When you open a file using mapped access and write data to it, you must
use the FPOINT and FCONTROL intrinsics to reset end-of-file (EOF) before
closing the file. Otherwise, all data written to the file is lost when
you close it. In the case of a newly created file, the EOF initially
points to record zero. Mapped accessing of a file bypasses File System
services that, otherwise, automatically set various File System pointers,
including EOF and the logical record pointer. You are responsible for
resetting EOF prior to closing the file.
For detailed information on the advantages of mapped access to files,
refer to Accessing Files Programmer's Guide (32650-90017).
Device File Buffers
A buffer is an area in memory used by the File System to hold one block
(one physical record) of a file. When a program reads a record from a
buffered file, a block is brought into the buffer. For detailed
information, refer to Accessing Files Programmer's Guide (32650-90017).
MPE/iX 5.0 Documentation