Files Organization and Access Mechanism
Files Organization and Access Mechanism
Direct Access:
It is an alternative method for accessing a file, which is based on the disk model of a file, since disk
allows random access to any block or record of a file. For this method, a file is viewed as a numbered
sequence of blocks or records which are read/written in an arbitrary manner, i.e. there is no restriction
on the order of reading or writing. It is well suited for Database management System.
Index Access:
In this method an index is created which contains a key field and pointers to the various block. To find
an entry in the file for a key value , we first search the index and then use the pointer to directly access
a file and find the desired entry.
With large files , the index file itself may become too large to be keep in memory. One solution is to
create an index for the index file. The primary index file would contain pointers to secondary index
files, which would point to the actual data items.
Contiguous allocation:
It requires each file to occupy a set of contiguous addresses on a disk. It sore each file as a contiguous
run of disk blocks. Thus on a disk with 1-KB blocks, a 50-KB file would be allocated 50 consecutive
blocks. Both sequential and direct access is supported by the contiguous allocation method.
Contiguous disk space allocation has two significant advantages.
1. First, it is simple to implement because keeping track of where a file's blocks are is reduced to
remembering two numbers: the disk address of the first block and the number of blocks in the
file. Given the number of the first block, the number of any other block can be found by a
simple addition.
2. Second, the read performance is excellent because the entire file can be read from the disk in
a single operation. Only one seek is needed (to the first block). After that, no more seeks or
rotational delays are needed so data come in at the full bandwidth of the disk.
Thus contiguous allocation is simple to implement and has high performance.
Unfortunately, contiguous allocation also has a major drawback: in time, the disk becomes fragmented,
consisting of files and holes. It needs compaction to avoid this.
Unlike contiguous allocation, every disk block can be used in this method. No space is lost to disk
fragmentation. The major problem with linked allocation is that it can be used only for sequential
access files. To find the ith block of a file, we must start at the beginning of that file, and follow the
pointers until we get the ith block. It is inefficient to support direct access capability for linked
allocation of files.
Another problem of linked list allocation is reliability. Since the files are linked together with the
pointer scattered all over the disk. Consider what will happen if a pointer is lost or damaged.
To read the ith block, we use the pointer in the ith index block entry to find and read the desired block.
This scheme is similar to the paging scheme.
Source : http://dayaramb.files.wordpress.com/2012/02/operating-system-pu.pdf