- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
File System Management
Files are used to provide a uniform view of data storage by the operating system. All the files are mapped onto physical devices that are usually non volatile so data is safe in the case of system failure.
The attributes of a file may vary a little on different operating systems. However, the common file attributes are −
This denotes the symbolic name of the file. The file name is the only attribute that is readable by humans easily.
This denotes the file name for the system. It is usually a number and uniquely identifies a file in the file system.
If there are different types of files in the system, then the type attribute denotes the type of file.
This points to the device that a particular file is stored on and also the location of the file on the device.
This attribute defines the size of the file in bytes,words or blocks. It may also specify the maximum allowed file size.
The protection attribute contains protection information for the file such as who can read or write on the file.
Operations on Files
The operations that can performed on a file are −
Creating a file
To create a file, there should be space in the file system. Then the entry for the new file must be made in the directory. This entry should contain information about the file such as its name, its location etc.
Reading a file
To read from a file, the system call should specify the name and location of the file. There should be a read pointer at the location where the read should take place. After the read process is done, the read pointer should be updated.
Writing a file
To write into a file, the system call should specify the name of the file and the contents that need to be written. There should be a write pointer at the location where the write should take place. After the write process is done, the write pointer should be updated.
Deleting a file
The file should be found in the directory to delete it. After that all the file space is deleted so it can be reused by other files.
Repositioning in a file
This is also known as file seek. To reposition a file, the current file value is set to the appropriate entry. This does not require any actual I/O operations.
Truncating a file
This deletes the data from the file without destroying all its attributes. Only the file length is reset to zero and the file contents are erased. The rest of the attributes remain the same.
File Access Methods
The information in a file can be accessed in various ways. The most common among them are using sequential access or direct access. More details about these are −
The information in a file is processed in order using sequential access. The files records are accessed on after another. Most of the file systems such as editors, compilers etc. use sequential access. It is based on the tape model of a file and so can be used with sequential access devices as well as random access devices.
A diagram to illustrate sequential access is as follows −
As seen in the image, the read and write operations in the file can only be done in a sequential manner. However, the file can be reset to the beginning or rewinded as required.
In direct access or relative access files can be accessed in random for read and write operations. The direct access model is based on the disk model of a file, since it allows random accesses. In this method, the file is divided into numbered blocks. Any of these arbitrary blocks can be read or written. For example, we may read block 8, then write into block 10 and then read block 15. Direct access system is quite useful and mostly databases are of this type.
A diagram to illustrate direct access is as follows −
As seen in the above image, the file pointer can be positioned randomly as required for read and write operations. This can be done without any particular order in positioning.