Guardian Programmer's Guide

Table Of Contents
Communicating With Disk Files
Guardian Programmer’s Guide 421922-014
5 - 32
Opening Entry-Sequenced Files
FILE^NAME ':=' "\SYS.$HR.RECORDS.ESFILE" -> @S^PTR;
LENGTH := @S^PTR '-' @FILE^NAME;
CALL FILE_CREATE_(FILE^NAME:ZSYS^VAL^LEN^FILENAME,
LENGTH,
!file^code!,
!primary^extent^size!,
!secondary^extent^size!,
!max^extents!,
FILE^TYPE,
!options!,
RECORD^LENGTH,
BLOCK^LENGTH);
A file type of 2 specifies an entry-sequenced file.
The maximum record length has been set to 4072 bytes, almost equal to the block
size. (Entry-sequenced files require a few bytes of overhead in each block.) There is
no need to make the record size any smaller, because space is not wasted when you
use records that are smaller than the maximum (unlike relative files, where disk space
equal to the maximum record size is allocated even if the record itself is only one byte
long). Records can be any length from one byte up to this maximum. Unlike relative
files, records follow each other immediately, regardless of their sizes.
In this example, the block size is 4096 bytes. The file system will pack as many
records into this block size as it can, then start another block.
Opening Entry-Sequenced Files
Once an entry-sequenced file is created, you can open it as you would any file, by
using the FILE_OPEN_ procedure. See Using Unstructured Files for an example of
opening a disk file.
Positioning, Reading, and Writing With Entry-Sequenced Files
Write operations to an entry-sequenced file are done by appending records to the file
using the WRITE[X] procedure. Before writing, you must position the current-record
and next-record pointers at the end of the file. You do this by positioning to
address -1D:
INT(32) RECORD^ADDR;
.
.
RECORD^ADDR := -1D;
CALL POSITION(FILE^NUM,
RECORD^ADDR);
CALL WRITEX(FILE^NUM,
BUFFER,
STRING^LENGTH);