File System Access Methods-
File access methods refer to the manner in which the records of a file may be accessed. There are several ways to access files −
- Sequential access
- Direct/Random access
- Indexed sequential access
Sequential Access –
Sequential access is that in which the records are accessed in some sequence, i.e., the information in the file is processed in order, one record after the other. This access method is the most primitive one. Example: Compilers usually access files in this fashion.
It is the simplest access method. Information in the file is processed in order, one record after the other. This mode of access is by far the most common; for example, the editor and compiler usually access the file in this fashion.
Read and write make up the bulk of the operation on a file. A read operation -read next- read the next position of the file and automatically advance a file pointer, which keeps track of I/O location. Similarly, for the write next append to the end of the file and advance to the newly written material.
key point –
- Data is accessed one record right after another record in order.
- When we use the read command, it moves ahead pointer by one
- When we use the write command, it will allocate memory and move the pointer to the end of the file
- Such a method is reasonable for tape.
Another method is direct access method also known as relative access method. A filed-length logical record that allows the program to read and write record rapidly. in no particular order. The direct access is based on the disk model of a file since disk allows random access to any file block. For direct access, the file is viewed as a numbered sequence of block or record. Thus, we may read block 14 then block 59 and then we can write block 17. There is no restriction on the order of reading and writing for a direct access file.
A block number provided by the user to the operating system is normally a relative block number, the first relative block of the file is 0 and then 1 and so on.
key point –
- Random access file organization provides, accessing the records directly.
- Each record has its own address on the file with by the help of which it can be directly accessed for reading or writing.
- The records need not be in any sequence within the file and they need not be in adjacent locations on the storage medium.
Index sequential method –
It is the other method of accessing a file that is built on top of the sequential access method. These methods construct an index for the file. The index, like an index in the back of a book, contains the pointer to the various blocks. To find a record in the file, we first search the index, and then with the help of a pointer, we access the file directly.
- This mechanism is built upon the base of sequential access.
- An index is created for each file which contains pointers to various blocks.
- The index is searched sequentially and its pointer is used to access the file directly
Files are allocated disk spaces by the operating system. Operating systems deploy the following three main ways to allocate disk space to files.
- Contiguous Allocation
- Linked Allocation
- Indexed Allocation
- Each file occupies a contiguous address space on the disk.
- The assigned disk address is in linear order.
- Easy to implement.
- External fragmentation is a major issue with this type of allocation technique.
- Each file carries a list of links to disk blocks.
- The directory contains a link/pointer to the first block of a file.
- No external fragmentation
- Effectively used in sequential access files.
- Inefficient in case of direct access file.
- Provides solutions to problems of contiguous and linked allocation.
- An index block is created having all pointers to files.
- Each file has its own index block which stores the addresses of disk space occupied by the file.
- The directory contains the addresses of index blocks of files.
- Explain File Allocation Methods
- What is Directory Structure in
- What is Cache Memory Organization What is Program Design Explain File Allocation Methods USFULL PRODUCT