omron — Advanced Disk Operations

Advanced Disk Operations may contain either variable-length or fixed-length records. Random-Access Files In some applications, disk files need to be read or written in a nonsequential or random order. eV+ supports random access only for files with fixed-length records. Records are numbered starting with 1. The position of the first byte in a random-access record can be computed by: byte_position = 1 + (record_number -1) * record_length Random access is selected by setting the random-access bit in the mode parameter of the FOPEN_ instruction. A nonzero record length must also be specified. A specific record is accessed by specifying the record number in a READ or WRITE instruction.

If the record number is omitted, or is zero, the record following the one last accessed is used. (See the FOPEN documentation.) Buffering and I/O Overlapping All physical disk I/O occurs as 512-byte sector reads and writes. Records are unpacked from the sector buffer on input, and additional sectors are read as needed to complete a record. To speed up read operations, eV+ automatically issues a read request for the next sector while it is processing the current sector. This request is called a preread. Preread is selected by default for both sequential-access and random-access modes. It can be disabled by setting a bit in the mode parameter of the FOPEN_ instruction.

If prereads are enabled, opening a file for read access immediately issues a read for the first sector in the file. Preread operations may actually degrade system performance if records are accessed in truly random order, since sectors would be read that would never be used. In this case, prereads should be disabled and the FSEEK instruction should be used to initiate a preread of the next record to be used. The function IOSTAT(lun, 1) returns the completion status for a pending preread or FSEEK operation. On output, records are packed into sector buffers and written after the buffers are filled.

If no-wait mode is selected for a write operation by using the /N format control, the WRITE instruction does not wait for a sector to be written before allowing program execution to continue. In random-access mode, a sector buffer is not normally written to disk until a record not contained in that buffer is accessed. The FEMPTY instruction empties the current sector buffer by immediately writing it to the disk. A file may be opened in nonbuffered mode, which is much slower than normal buffered mode, but it guarantees that information that is written will not be lost due to a system crash or power failure.

This mode was intended primarily for use with log files that are left eV+Language User's Guide, v2.x, 18318-000 Rev A Page 149