Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 17
Opening Relative Files
The record length is set to 128 bytes, which sets the limit on the size of a logical
record. (Recall that the maximum size of a logical record for a relative file is the record
length.) A block size of 4096 limits the maximum size of a record that could be
specified.
The block size is the number of bytes that are transferred between the disk and the
disk process. The block size can be 512, 1024, 2048, or 4096 bytes. Records cannot
span blocks; therefore the block size must be at least large enough to contain one
record and the overhead associated with the block. In other words, the maximum
record size is smaller than the block size. A block usually contains multiple records.
As for any disk file, the file system allocates a primary extent to the file and as many
secondary extents as necessary (up to the maximum allowed). The above example
assumes the default extent sizes and default maximum number of extents. Extent
allocation is described in Section 2, Using the File System.
Opening Relative Files
A relative file is opened in the same way as any other file, by using the FILE_OPEN_
procedure. See Using Unstructured Files, earlier in this section, for details.
Positioning, Reading, and Writing With Relative Files
Before performing a read or write operation on a relative file, you must be sure that the
current-record and next-record pointers point to the appropriate places. When you
open the file, the pointers are set up to access record 0. If you want to randomly
access other records in the file, you must move the pointers using the POSITION
procedure to do this. For example:
INT(32) RECORD^NUM;
.
.
RECORD^NUM := 24D;
CALL POSITION(FILE^NUM,RECORD^NUM);
IF <> THEN ...
The above example places the current-record and next-record pointers at the start of
record number 24 in the file. Your program can now do sequential read and write
operations using the READ[X] or WRITE[X] procedures starting at record number 24.
READUPDATE[X] and WRITEUPDATE[X] can be used if you do not wish to move the
file pointers, for example, when updating a record.
You can position the file pointers to the next empty physical record by setting the
record number to -2D. You can address the end of the file (for appending a record) by
setting the record number to -1D.