HPlogo New Features of MPE/iX: Using the Hierarchical File System: 300 MPE/iX Computer Systems > Chapter 4 What's New for Programmers?

New File Types

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Glossary

 » Index

Release 4.5 and 5.0 of MPE/iX provide some new file types. Here is a brief description of them. Since these interfaces are based on a commonly used standard, many textbooks are available that contain a detailed discussion of their use.

Symbolic Links

Symbolic links are permanent MPE/iX files that can be created, removed, renamed, and archived.

Creating symbolic links

Symbolic links can be created by one of the following two ways:

  1. POSIX C-library function symlink

  2. MPE/iX command NEWLINK. For example:

       :NEWLINK ./syml, /SYS/PUB/SYSSTART
    

    This creates the file syml in the current working directory as a symbolic link to the pathname /SYS/PUB/SYSSTART.

Removing symbolic links

Symbolic links can be removed in the following ways:

  1. POSIX C-library function unlink

  2. MPE/iX command PURGELINK

         :PURGELINK ./syml
    

    This purges the file syml.

Renaming symbolic links

Symbolic links can be renamed by calling the POSIX C-library function rename.

The MPE/iX command RENAME does not rename the symbolic link itself, it renames the file pointed to by the symbolic link.

Archiving symbolic links

Symbolic links can be stored and restored to your MPE/iX system by using the MPE/iX STORE and RESTORE commands like any other file on the system.

MPE/iX LISTFILE command

This command displays information about the symbolic link file and its contents. For example: If the file

   /SYS/PUB/syml

is a symbolic link to /SYS/PUB/NL, then

   LISTFILE /SYS/PUB/syml,5

displays information about the file syml and in addition, it displays:

   SYMLINK TARGET: /SYS/PUB/NL

Pipes

A pipe provides a method to take output from one process and use it as input to another process. The HPPIPE intrinsic creates a new file type object called pipe for this purpose. It provides a one-way flow of data. After creating a pipe file type object, the HPPIPE intrinsic returns both read-access and write-access file numbers. Related processes can access the pipe.

Data can be written to the write-end and read from the read-end of the pipe. The data is accessed in a first-in-first-out manner, or FIFO.

A pipe file does not have a name associated with it and is not inserted into any directories upon creation. After the final close of a pipe file, the file is deleted. Pipe files are treated as new files.

FIFOs

A FIFO is similar to a pipe. It is a one-way flow of data, with the first byte written to it being the first byte read from it. Unlike pipes, a FIFO has a name associated with it, allowing unrelated processes to access a single FIFO. FIFOs are also called "named pipes."

The program MKNOD.PUB.SYS has been modified to support the creation of a new file type object called fifo to be used for this purpose. It creates a FIFO file and inserts it into the directory.

The HPFOPEN intrinsic has been modified to support the opening of the FIFO file. After the final close of a FIFO file, the data remaining in the FIFO is deleted, but the FIFO container remains and can be reopened and used again. FOPEN can open FIFOs as well.

MPE/iX Byte-Stream Files

Beginning with MPE/iX Release 4.5, the byte-stream record format is available to allow an MPE/iX file to reproduce POSIX byte-stream behavior.

NOTE: In this manual, the term "byte-stream file" is used to refer to an MPE/iX standard ASCII disk file with a record format of byte-stream.

The standard file used in a POSIX environment is the byte-stream file. Conceptually, a POSIX byte-stream file has no system-defined record structure. A user can write any number of bytes from a user buffer to a byte-stream file starting at the current file offset. By default, byte-stream files created by HPOPEN have a file limit of 2 Gigabytes. Byte-stream files created by FOPEN have a default file limit of 1023 bytes. The size can be defined by the user.

Likewise a user can read any number of bytes from a byte-stream file to the user's buffer starting at the current file offset. In short, a byte-stream file is a file that stores data in the form of a stream of bytes. It is the responsibility of the programmer to provide meaning and structure to the data.

Creating a byte-stream file

You use either the HPFOPEN or FOPEN intrinsics to create a byte-stream file. (Byte-stream files can also be created using POSIX.1/iX library functions.) You can also use the BUILD command, for example:

   :BUILD X;REC=,,B;DISC=100000

where B; indicates byte-stream record format.

The following table defines the file and access attributes imposed on an MPE byte-stream file when it is created. These attributes cannot be changed during the life of the byte-stream file.

Table 4-3 Access Attributes of Byte-Stream Files

Attribute NameDefault
DomainMust explicitly specify "create as a permanent file" if the file is being created under a hierarchical directory.
Record formatByte-stream. Must be explicitly specified in order to create a byte-stream file.
Carriage controlNo carriage control (NOCCTL). All other specifications are ignored.
File typeStandard disk file (STD). All other specifications are ignored.
MultirecordMultirecord access (MULTI). All other specifications are ignored.
Copy modeThe file is always accessed as its own file type. All other specifications are ignored.
Record sizeOne byte. All other specifications are ignored.
Remote environmentRemote access to byte-stream files is not supported. Specifying this option results in an error.
File sizeTwo gigabytes. Care should be taken when resetting the file limit of a byte-stream file. POSIX does not support MPE/iX file limits. To minimize the impact of this unsupported behavior, the file limit of a byte-stream file is set to the maximum possible value.
Block factorOne byte per block. All other specifications are ignored.
Fill characterASCII null character. Unlike other record formats, the file system does not pad byte-stream files except when the FPOINT intrinsic is called to set the record pointer beyond existing data in the file. If data is later written at this point, the resulting gap is padded with ASCII null characters.
Inhibit bufferingInhibit buffering (NOBUF). All other specifications are ignored.
ASCII/binaryASCII. All other specifications are ignored.

 

NOTE: If you are using the FOPEN intrinsic to create a byte- stream file, the number of bits available in the record format field (bits 8:2) of foptions parameter is inadequate to specify byte-stream record format.

To create a file with a byte-stream record format, you must set foptions bits 8:2 to "01" (variable) and foptions bit 1:1 to "1" (record format extension).

User-defined labels can be attached to a byte-stream file. For these files, the behaviors of both the FREADLABEL and FWRITELABEL intrinsics remain unchanged.

Opening a byte-stream file

MPE/iX provides two mechanisms to open and access a byte-stream file. The behavior of the byte-stream file differs depending on how you open it. The two mechanisms are:

  • The open byte-stream file behaves as a byte-stream file only if you explicitly specify "byte-stream" in the HPFOPEN record format option (item 77). The behavior of byte-stream files is described in the following sections.

  • The open byte-stream file behaves as a variable-length record format file if you do not explicitly specify "byte- stream" in the record format option. (The default MPE system behavior.)

Opening a byte-stream file as a buffered variable-length record format file allows existing applications to access a byte-stream text file in a known and expected manner without having to perform any code revisions.

For example, many text editors supported today can access either fixed-length record format files or variable-length record format files. By allowing a byte-stream file to be opened as a variable-length record format file, these text editors can read from and write to byte-stream files without concern for compatibility problems that occur when trying to access a file with an unknown record structure.

Record selection and data transfer

Both the blocking factor and the record size of a byte- stream file are equal to one. The record pointer is defined by its offset from the beginning of a file of one-byte records. The offset of the first record, or byte, is zero. When a byte-stream file is first created, the record pointer points to byte zero.

Conceptually, there should be no limit to the number of bytes a user can transfer to and from a byte-stream file. In fact, processes performing data transfer using POSIX.1/iX library functions can transfer up to two gigabytes of data in one operation. However, the length parameter used by MPE/iX data transfer intrinsics (FREAD, FREADDIR, FWRITE, FWRITEDIR) to specify the number of bytes to transfer limits the value to 32,768 (this value must be passed as a negative-signed integer value to indicate byte transfer).

Sequential access

Byte-stream files are always opened for multirecord access. Because data transfer to and from byte-stream files usually occurs in blocks of bytes, data transfer to and from byte- stream files usually occurs using sequential access. Sequential access is the typical form of byte-stream data transfer.

The behavior of both the FWRITE and FREAD intrinsics are straightforward with respect to byte-stream files. Data transfer to and from byte-stream files is usually accomplished by transferring a number of bytes to or from the file.

After a successful data transfer, the record/byte pointer is set to the next unread/unwritten byte. Carriage controls are ignored when accessing byte-stream files.

Care should be taken when accessing a file using sequential access methods. Because there is no system-imposed record structure in a byte-stream file, applications that require some form of record structure in order to sequentially access user-defined records in the file must define and manage their own record blocking and deblocking.

Random access

The behavior of both the FWRITEDIR and FREADDIR intrinsics are straightforward with respect to byte-stream files. When performing random access on a byte-stream file, remember that the logical record number passed in the lrecnum parameter corresponds to the desired byte offset from the beginning of the file (byte offset 0).

Successful data transfers set the record/byte pointer to the next unread/unwritten byte. Carriage controls are ignored when randomly accessing byte-stream files.

Care should be taken when accessing a file using random access methods. Because there is no system-imposed record structure in a byte-stream file, applications that require some form of record structure in order to randomly access user-defined records in the file must define and manage their own record blocking and deblocking.

Append access and append mode

A byte-stream file opened for append access using the HPFOPEN/FOPEN "access type" option performs in a straightforward manner. When the file is opened, the record/byte pointer is set to the end of the file. Subsequent writes to the file using FWRITE appends data to the end of the file, ensuring that existing data cannot be overwritten.

Beginning with MPE/iX Release 4.5, item number 51 of the FCONTROL intrinsic can be used to enable a new type of append access called "append mode". Append mode is available only for byte-stream files.

Append mode differs from append access in the following ways:

  • Append mode can be dynamically enabled and disabled while a byte-stream file is open. Append access is established when opening a file and cannot be changed dynamically for a file number.

  • Append mode affects all processes sharing a logical record pointer. Append access is a process-local attribute affecting only the access of the process opening the byte-stream file. (The HPFOPEN/FOPEN MULTI and GMULTI options permit logical record pointers to be shared.)

  • A byte-stream file's logical record pointer can be manipulated using FPOINT or FREADDIR when append mode is enabled. Append access prohibits logical record pointer operations. For example, calls to FPOINT and FSPACE result in an error for files opened for append access.

Update access

Update access is not allowed on byte-stream files. If you attempt to set the access type option of HPFOPEN/FOPEN to "update" when opening a byte-stream file, an error occurs. Likewise, a call to the FUPDATE intrinsic on a byte-stream file results in an error.

Moving the file pointer

Use the FPOINT intrinsic to move the record pointer from its current offset to any offset in a byte-stream file. FPOINT also allows you to set the record pointer beyond existing data in the file. If data is later written at this point, the resulting gap is padded with the fill character, which is defaulted to the ASCII null character, but may be set to any character at creation time. This case is the only circumstance where the file system pads a byte-stream file.

Use the FCONTROL intrinsic with a control code of 5 to "rewind" the record pointer of a byte-stream file to the first record/byte, a file offset of zero.

Use of the FSPACE intrinsic on a byte-stream file is not allowed. An attempt to do so results in an error. Instead, use the FPOINT intrinsic.

NOTE: The affect of moving the record pointer of a shared byte-stream file may be different than expected if append mode is enabled for that file. For more information, refer to the discussion of the new append mode feature in the section called "Append access and append mode" earlier in this chapter.
Feedback to webmaster