• Keine Ergebnisse gefunden

HOW AMOS ALLOCATES FILES ON THE DISK

Im Dokument INTRODUCTION TO AMOS (Seite 41-44)

WHAT IS A FILE?

5.4 HOW AMOS ALLOCATES FILES ON THE DISK

We'll talk in much more detail about the structure of the disk in Chapter 16, "How AMOS Handles Devices."

However, there is one concept that we ought to discuss here before you actually begin to use files.

Throughout the Alpha Micro documentation, you frequently see the terms sequential files and random files.

(You may also see these mentioned as linked files and contiguous files.) Because the kinds of actions you can perform on files depend on whether those files are sequential or random, you'll want to understand the difference between the two.

What is a File? 5-5

AMOS transfers files to and from the disk in units of 512 bytes. This 512 - byte chunk is called a disk block. Even the smallest file consists of at least one disk block (though the block might be partially empty). The upper limit on the size of a file depends on the size of your storage devices. (That is, a file may not overlap onto two different disks, but must fit all on one unit.) Each disk block has a unique number by which AMOS can reference it.

AMOS has two different ways of writing files to the disk. The way that a file is allocated on the disk determines whether it is a sequential or a random file.

5.4.1 Sequential Files

Most files on the AMOS system are sequential files. We call these files sequential files because AMOS accesses the data in the file sequentially. That is, as AMOS reads each disk block of the file, that block tells it the disk address of the next disk block. AMOS proceeds through the file one block at a time. To find out where block

#3 of the file is, AMOS looks at block #1, which points to block #2. Then AMOS looks at block #2, which points to block #3. The important thing to remember about a sequential file is that to acess one block of data in it, you have to access all preceding blocks.

When AMOS writes a sequential file to the disk, it looks for the first free disk block. It writes a copy of the first file block into that disk location. Next, it looks for another free disk block. This next disk block mayor may not be anywhere near the first disk block used. This process goes on until the entire file is transferred to the disk. The disk blocks that make up the file may be scattered across the disk. How does AMOS keep track of the file?

Each disk block in the file contains a portion of the file; it also contains the address of the next disk block used by the file.

Address of Next

Disk Block in File DATA IN FILE BLOCK Figure 5-1

Sequential File Disk Block

Sequential files are also called linked files because the disk blocks are linked together by the information III

each block that points to the address of the next disk block. (The last block in the file is designated as such by a link of zero.) For example:

I I r.

Address of

DATA

~

Address of

DATA ~ End of File

Next Disk Block Next Disk Block ~ (Zero Link) DATA

File Block #1 File Block #2 File Block #3

Figure 5-2

Disk Blocks in a Sequential File

The major advantage of a sequential file is that you can expand it. For example, suppose you are editing a text file that is four disk blocks long. AMOS is easily able to make the file larger by simply allocating a new disk block for the new material you want to add. It is for this reason that processes which expand files (such as text editing) can only be performed on a sequential file. If you try to use VUE on a random file, you see the error message:

? File type mismatch

Almost any time you create a file by using a command from AMOS command level (for example, using the MAKE or VUE commands), that file is a sequential file.

5.4.2 Random Files

Some files are called random files because AMOS can access the data in them "randomly." AMOS knows how long the files are, and also knows exactly where the files begin on the disk. AMOS can therefore access any block in a file by computing an offset value from the front of the file, and then reading the proper disk location. We say that the data access is random rather than sequential, because AMOS can access the disk blocks in any order, and does not have to step through the file to find the disk location of a specific block.

AMOS can therefore find data in such a file quickly and efficiently.

When AMOS writes a random file to the disk, it looks for the first free group of contiguous disk blocks that is large enough to hold the entire file. That is, if your random file is 20 blocks long, AMOS looks for 20 disk blocks that physically adjoin on the disk. When it finds such a group of blocks, AMOS writes the file to the disk.

If it cannot find a group of blocks large enough, you see a Disk full error message. This illustrates a major disadvantage of a random file. Even if you have 100 free disk blocks, you will not have room for a 20-block random file if 20 of those blocks are not in a contiguous group on the disk.

Because this kind of file is written into contiguous disk blocks, we also call it a contiguous file.

File Block #1 File Block #2 File Block #3 File Block #4

Figure 5-3

Disk Blocks In a Random File

Once a random file is allocated on the disk, it is not possible to expand it. Therefore, random files are used for applications where the file length remains constant (e.g., BASIC data files).

CHAPTER 6

Im Dokument INTRODUCTION TO AMOS (Seite 41-44)