...

Wednesday, February 23, 2011

CAOS 05

Information can be stored on hard disks, magnetic tapes, optical media and so on. So there is a need for a way to represent this information in a convenient, consistent, uniform and logical view. That is where the file system comes in.
The file system provides an abstraction layer to the physical properties of its storage devices to define a logical storage unit, known as a File. Each File has its associated attributes. The bare minimum are these:
Name
FID - The file's unique identifier
Type
Location
Size
Protection - In other words, permissions, such as who can RWX.
Time, date, and user identification - Timestamp, and owner/group information.

File operations are operations that work on files, such as:
Create - Find space for the file, then write the file and record it in the directory
Write - The OS provides the File Name and information to be written. Controlled by a write pointer.
Read - The OS provides the File Name, and the memory (RAM) location to read to. Controlled by a read pointer. (As a process only performs one of these at a given point, the same pointer may be used for read and write. This is now called the current-file-position pointer)
Seek - Reposition within a file
Delete - Delete the file's contents and attributes
Truncate - Deletes the file's contents only, leaving a zero-byte file with attributes intact.

These operations work on the files by viewing them as an abstract data type, such as bits/bytes/lines/records.

You can derive other operations as such:
Copy - Create (in new location), Read (from old file), Write (to new location)
Move - Create (in new location), Read (from old file), Write (to new location), Delete (the old file)
Move/Rename
Append
etc.

File Types allow the operation (or in some cases the user) to determine what operations can be performed on the file. For example, a binary file should not be printed, or else we would get garbage. Likewise, a text file should not be executed as a binary file.

The way the operation system identifies the Type of the File can be through various ways such as:
1) File name extensions - The type is appended to the file name, such as .exe, .com. Typically used in Windows.
2) Creator Attributes - The type is an attribute stored in the file to describe the program that created it. Typically used in Macintosh.
3) Magic Number - The type is a number stored in the beginning of a file. It is not compulsory. This is typically used in UNIX systems.

Now that we've established the basics of a file (there are much more, actually), we'll go into how the files are accessed. The simplest method is the Sequential Access method.

In Sequential Access, the information in a file is processed in order. That is to say, the file is accessed Record by Record. This is the most common and simplest file access method, and it is used by editors and compilers.

In Sequential Access, a read operation basically reads forward, with the Read Pointer automatically advancing to the end of the file. A write (or append) operation would write from a specified pointer to the end of the newly written material.

Some systems allow skipping forward or backward for n records, most commonly n=1. This is based on the tape model, and it works well on Sequential Access DEVICES (Tape) as well as Random Access DEVICES (Disk, Flash).

The sequential file access method looks like this:

(Image taken from the recommended text.)

Another method is the Direct Access (or Relative Access) method. Files are made up of fixed-length logical records. As its name suggests, it allows Direct Access to any record in no particular order. As its name also suggests, the way the Records are accessed is through a Seek function which is Relative to its current position (following the seminar notes. In the recommended text, it is relative to the beginning of the file so it's actually an absolute access).

For example, assuming we start from Record 0:
seek(5);
seek(10);
read();

This would result in a read of Record 15.

Finally we come to the non-native Access Methods. These methods, like the non-native File Operations, work on existing Access Methods. We will discuss a method known as the Indexed Access method.

In the Indexed Access method, the file is divided into different sections and pointers to the starting Block of the different sections are stored in an Index. The Index is then consulted whenever it requires a specific section, and the Direct access method is used to move directly to the required Block. The Index can be stored as a separate file or within the same file. (Seminar notes only specifies the Index within the same file).

The Index looks like this:

(Again, image taken from Recommended Text)

No comments :

Post a Comment

<