• Aucun résultat trouvé

\PRINT RTHANK YOU·

Dans le document RSTS/E Programming Manual (Page 27-31)

800 CLOSE 1%

\END

In certain applications, it is desirable to append records to a file on one channel and read the appended records on another channel. Because RSTS/E does not update the directory information on disk immediately after each append operation, a program must process the END OF FILE ON DEVICE error (ERR

=

11) on the reading channel in a special manner. Upon encountering error number 11 when attempting to read appended records, the program should close the reading channel and reopen it. This action ensures that the latest directory information kept in memory is written to the disk. The appended records are then available on the reading channel.

1.4.4 Special Mode for Extending Files - MODE 8%

To force RSTS/E to update a file's size data on the disk during extend operations, the MODE 8% option is used in the OPEN, OPEN FOR INPUT, or OPEN FOR OUTPUT statement. In normal processing, RSTS/E maintains a fIle's size data in memory. This size is not updated on disk until a new cluster is allocated to the me. By specifying MODE 8%, the program force's RSTS/E to update the on-disk file size for every block added to the me:

The following sample statement shows the MODE 8% option.

10

OPEN 'DATA' AS FILE 1%, MODE 8% + N%

The system creates the file if it does not exist. The value N% can be any other disk MODE option.

1-14

Extending a disk file using MODE 8% increases the processing overhead because the system must access the disk more times for every block added. The extra overhead is warranted for applications where a file's size must be correctly preserved in the event of a system crash or power failure.

1.4.5 Creating a Contiguous File - MODE 16%

MODE 16% can be specified with the FILESIZE option in the OPEN FOR OUTPUT statement to create a con-tiguous file on disk. Concon-tiguous means that the clusters allocated to the file are logically adjacent. The following sample statement shows the procedure to create a contiguous file.

10 OPEN 'DATA.l' FOR OUTPUT AS FILE 1%, FI LESIZE 12%, MOnE 1 6%

~

Other options can be used with MODE 16% to specify the buffer size (RECORDSIZE) and the file cluster size (CLUSTERSIZE). The FILESIZE option is necessary with MODE 16%. It pre-extends the file to its maximum length, thus telling the system how much contiguous space is reqUired. If sufficient contiguous space is not avail-able, the system generates the NO ROOM FOR USER ON DEVICE error (ERR=4). .

Processing a contiguous me reduces overhead greatly because directory accesses and movement of read/write heads is minimized. Files for run-time systems and swapping must be contiguous because the monitor accesses these files independently of the normal file processor. A contiguous file, however, cannot be extended. An attempt to extend a contiguous me generates the PROTECTION VIOLATION error (ERR=10).

1.4.6 Reading a File Normally Regardless - MODE 4096%

In certain applications it is advantageous to be able to read a data file regardless of what other processing is trans-piring. Under normal circumstances, the system prohibits opening a file normally while the me is currently open for update (MODE 1 % or MODE 4%+ 1 %). With MODE 4096%, a privileged program can open a file for read access regardless of whether the file is being updated.

The following sample statement shows the procedure.

10 OPEN 'DATA.2' FOR INPUT-AS FILE 1%, RECORDSIZE R%, MODE 4096%

Write operations are not permitted. If a write operation is attempted, the system generates the PROTECTION VIOLATION error (ERR=10). If the file is simultaneously open fo{update, the normal DISK BLOCK IS INTER-LOCKED error is not generated when the program reads a block being updated.

MODE 4096% requires privileges because of the danger involved in reading data which is perhaps changing.

1.4.7 Read Only Access to a File - MODE 8192%

Certain applications require simple read access to a data file and do not want to preclude write access for other applications. Under normal circumstances, an OPEN FOR INPUT statement for a disk file possibly gains write access on the I/O channel involved. To bypass the mechanism which grants write access, the MODE 8192% option is specified in the OPEN FOR INPUT statement.

The following statement shows the procedure

After execution of the above statement, the program has only read access to the file DATA.3. If the fIle is currently open for update, however, the system generates the normal PROTECTION VIOLATION error (ERR=10).

1.4.8 Writing the UFD or MFD - MODE 16384%

A.privileged user can write into a UFD or MFD by specifying MODE 16384% in the OPEN statement. For example, the following statement allows a privileged user to read and write into the UFD of account [5,10] :

199 OPEN ·DK1:[S,10]· AS FILE 2%, MODE 16384%

To write the MFD, the user specifies [1,1] in the fIle name. An OPEN FOR OUTPUT statement is invalid for a UFD or MFD. Without MODE 16384%, only read access is allowed.

1.4.9 Simultaneous Disk Access

RSTS/E permits several users to read from the same fIle simultaneously, but only one at a time to write into a single file. Without this limitation, two users could try simultaneously to write the same record of the file, resulting in a loss of data. To avoid this conflict, the system permits only one user at a time to have write access to any file (unless the file is open in update mode). If a second user attempts to write into the file, a PROTECTION VIOLATION error results. Thus, a user may fail to obtain write privileges to a file that is not write-protected against him. If this failure occurs, the second user must close the fIle and reopen it after the first user has closed it.

The system does not permit a fIle to be open simultaneously in update mode and in normal mode'! Attempting to do so results in a PROTECTION VIOLATION (ERR=10). A fIle may be open in update mode by multiple users.

By checking bits 9 and 10 of the STATUS variable immediately after the OPEN statement, a program can ascertain whether the current job has read and write access to a fIle.

The STATUS variable is described in Section 12.3.5 of the BASIC-PLUS Language Manual. The example given in Section 1.4.3 performs such a check.

1.4.10 Disk Optimization

Whenever a user opens a file on the public structure, the system searches the directories of all public disks. This search determines whether the fIle exists. The user avoids the overhead of searching multiple directories by putting the fIle on a private disk.

Dedicating a private disk to a large production fIle minimizes overhead to access data and ensures an efficient directory organization. If the user fmds this impractical and must store more than one such fIle on one private

disk, he should dedicate an entire account to each fIle. This arrangement reduces directory search overhead.

However, lfthe user must save more than one file under an account, he should create the more frequently accessed ones first to ensure better directory organization. If he cannot do this, the system manager can optimally reorder the fIle directory with the REORDR system utility, which is described in the RSTS/E System Manager's Guide, Section 7.6. Thus, files on an account can be ordered in either forward or reverse direction, by either date and time of creation or date of last access.

When creating a large fIle, the user should specify a large file cluster size to increase efficiency. This reduces the number of UFD blocks required to describe the file. Throughput improves because the system can read or write multiple blocks in a single transfer operation. In addition, the user can pre-extend a disk fIle to its maximum length when he creates it and can specify that contiguous space be used. Pre-extension reduces directory fragmentation.

Contiguous space reduces window turning.

lA file may, however, be open simultaneously in update mode and read normally regardless mode as described in Section 1.4.6.

1-16

If a program requires simultaneous access to more than one data me, the optimal organization places each me on a different private disk. Overhead increases if the mes reside on the same disk because the disk head must move when-ever the program accesses a different me. Thus, a large percentage of execution time is spent in moving the disk head back and forth.

Different accounts should be used to store meso Certain accounts can be dedicated to mes that are created once and remain fairly static. Other accounts can be reserved for transient meso Thus, the number of poorly ordered accounts is minimized. To further optimize the structure, minimize the number of mes in one account. For example, it is better to have 30 files each in 10 accounts than to have 300 mes in one account.

1.4.11 Partial Block Operations on Disk

The RECORDSIZE option in the OPEN statement on a disk me can specify a value which is not a multiple of 512 bytes. Care, however, must be exercised in using the GET statement. For example, the following statement.

creates a 520 byte buffer on channell.

10 OPEN 'MASTER.DAT' AS FILE 1%, RECORDSIZE 520X

A subsequent GET operation. on channell % fills the buffer to the requested number of bytes. The disk software then skips the rest of the last disk block read and positions itself to access the next block. To fill the 520-byte buffer, the software reads the current block (for 512 bytes), reads 8 bytes of the next block, and positions itself to access the following block.

For GET operations, any value for RECORD may be used. For example, with a buffer of 520 bytes, RECORD 1 retrieves the first block and 8 bytes of the second block. RECORD 2 in the GET statement will retrieve the entire contents of the second block plus 8 bytes of the third block. The inter-block positioning is not maintained.

F or PUT operations, only blocks with a size which is a multiple of 512 bytes are written.

1.5 FLOPPY DISKS

The RXII/RX01 Floppy Disk can be used only as a non-file structured device.l The device name for the floppy disk is DX. Unit numbers for the floppy disk drive start at O. The current floppy disk implementation allows only a single .BAS file to be stored on floppy disk unit 1, for example, with the SAVE command:

SAVE [lX1:

It can be read from the disk or run by the following respective commands:

OLII

[lX1:

and

RUN DX1:

A floppy disk is divided into 77 tracks (numbered 0 through 76), each of which consists of 26 sectors (numbered 1

Table 1-5 MODE Specifi~tions for Floppy Disk

MODE Meaning

0% Read and write in block mode (default) 16384% Read and write in sector mode

The following sections describe the MODE specifications.

1.5.1 Sector Mode - MODE 16384%

In sector mode the buffer size is 128 bytes. Open the floppy disk on unit 3 in sector mode with the following statement:

Dans le document RSTS/E Programming Manual (Page 27-31)