HPlogo Accessing Files Programmer's Guide: HP 3000 MPE/iX Computer Systems > Chapter 2 Creating A File

Specifying a Record Format

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

A file can contain records written in only one of three formats: fixed-length, variable-length, and undefined-length. You can specify the format that you want for your records, either with the HPFOPEN/FOPEN intrinsic or the MPE/iX BUILD or FILE commands. Files residing on disk or magnetic tape may contain records in any of the three formats. For files on other devices, the file system overrides any specifications that you supply, and treats the records as undefined-length records.

Fixed-length records

When you create a file and request fixed-length records, all the records in the file will be the same size. The file system knows how much space has been allocated for each record, and that all of the space is to be available for data.

Figure 2-2 “Fixed-Length Records” depicts a file with fixed-length records. A record size of n bytes has been specified. Note that each record is the same size and contains the same amount of information.

Figure 2-2 Fixed-Length Records

[Fixed-Length Records]

Variable-length records

There may be a time when you want a disk file in which the logical records need not be the same size. In this case, you can request that the format of the records be variable-length. The file system knows the size of each logical record because each record is preceded by a two-byte (16-bit) counter giving the length of the record in bytes; thus, the data for each record is accompanied by an indication of its length. When you build a file containing variable-length records, specify a record size at least large enough to accommodate your longest record.

Figure 2-3 “Variable-length Records” depicts a file with variable-length records. The byte count preceding the first byte of each record gives its record's length.

Figure 2-3 Variable-length Records

[Variable-length Records]

Undefined-length records

When your file contains undefined-length records, the file system does not know the amount of good data in any given logical record. The data length is "undefined." Undefined-length records are especially useful when you are reading tapes of unknown record length produced on other systems.

The file system knows the maximum room available in each record because the same amount of space is allocated for each record; however, the data in the records may vary in length, so MPE/iX pads the unused space with "filler" instead of good data. The file system supplies this filler during writes to the file when the length of the data being written is less than the maximum record length. The file system cannot distinguish between valid data and filler. When you read data from a file you must be able to distinguish between the valid data and the filler.

Figure 2-4 “Undefined-Length Records” depicts a file with undefined-length records. When data does not fill the space allocated, filler occupies the unused space.

Figure 2-4 Undefined-Length Records

[Undefined-Length Records]

The three record formats, fixed-length, variable-length, and undefined-length are summarized in Table 2-5 “Comparison of Logical Record Formats”.

Table 2-5 Comparison of Logical Record Formats

Fixed-LengthVariable-LengthUndefined-Length
Data length known to file system.Data length known to file system.Data length not known to file system.
Same length for all records.Record length varies.Same length for all records.
Record space contains data only.Record space contains data plus byte count.Record space contains data plus filler.
Request actual size for records.Request maximum size for records.Request maximum size for records.