The simplest access method is sequential access. Information in the file is processed in order, one record after the other. This mode of access is by far the beginning current position most common; for example, editors and compilers usually access files in this fashion. Reads and writes make up the bulk of the operations on a file. A read operation read next reads the next portion of the file and automatically advances a file pointer, which tracks the I/O location.
Similarly, the write operation write next appends to the end of the file and advances to the end of the newly written material (the new end of file).
To read a piece of data that is stored at the end of the file, one has to read all of the data that comes before it-you cannot jump directly to the desired data.
This is similar to the way cassette tape players work. If one wants to listen to the last song on a cassette tape, he has to either fast-forward over all of the songs that come before it or listen to them. There is no way to jump directly to a specific song.
Direct Access Method:
A file is made up of fixed-length logical records that allow programs to read and write records rapidly in no particular order. Thus, we may read block 14, then read block 53, and then write block 7. There are no restrictions on the order of reading or writing for a direct-access file. The direct-access method is based on a disk model of a file, since disks allow random access to any file block. Direct access files are of great use for immediate access to large amounts of information. Databases are often of this type. For the direct-access method, the file operations must be modified to include the block number as a
parameter.
The block number provided by the user to the OS is normally a relative block number. A relative block number is an index relative to the beginning of the file. Thus, the first relative block of the file is 0, the next is 1, and so on, even though the actual absolute disk address of the block may be 14703 for the first
block and 3192 for the second. The use of relative block numbers allows the OS to decide where the file should be placed (called the allocation problem) and helps to prevent the user from accessing portions of the file system that may not be part of her file.
When you work with a direct access file (which is also known as a random access file), you can jump directly to any piece of data in the file without reading the data that comes before it. This is similar to the way a CD player or an MP3 player works. You can jump directly to any song that you want to listen
to. Sequential access files are easy to work with, and you can use them to gain an understanding of basic file operations.
0 Comments