Functions of File Management in Operating System

A file management system (FMS) is a collection of system software that provides services to users.
Example: The user wants to create a file, or delete files, it must be done through the FMS.

Objectives of File Management:

1. It provides I/O support for multi-users.
2. It provides a standardized set of I/O interface routines.
3. Storage of data.
4. To optimize performance.
5. It also provides I/O support for a variety of storage device types.
6. To guarantee that the data in the file are valid.

Functions of File Management:

There are three types of functions of file management.

File Accessing Methods:

File stores information, this information must be accessed and read into computer memory. There are so many ways that the information in the file can be accessed.
There are three types of File Accessing Methods.

Sequential File access:

This method is the simplest of all file access methods. Information in the file is processed in order, one record after the other. Magnetic tapes are supporting this type of file access. Sequential File access are typically used in batch applications and payroll applications.

Direct access:

Direct access is also called relative access. In this method, records can be read/written randomly without any order. The Direct access method is based on a disk model of a file because disks allow random access to any file block. A direct access file allows arbitrary blocks to be read or written.

File Directory Structure:

The directory contains information about the files, including attributes, locations and ownership. Sometimes the directories consist of subdirectories also. The directory is itself a file owned by the operating system and accessible by various file management routines.
There are 3 types of functions of File Directory Structure.

Single-level directory system:

It is the simplest of all directory structures. This directory system has only one directory. It consists of all files. Sometimes it is said to be ‘Root Directory‘.

Two-level directory system:

In this directory system, each user needs a private directory. In this way, names chosen by one user don’t interface with names chosen by a different user and there is no problem caused by the same occurring in two or more directories.

Hierarchical directory system:

The two-level directory eliminates name conflicts among users but it is not satisfactorily for users with a large number of files. To avoid this create the subdirectory and load the same type of files into the subdirectory. So in this method, each can have as many directories are needed. the directory structure looks like a tree, that’s why it is also said to be ‘Tree-level directory structure‘.

General-graph directory structure:

When we add links to an existing tree-structured directory, the tree is destroyed, and then results in a General-graph directory structure. The advantage of this directory structure is traversing is very easy and file-sharing also possible.

File Allocation Methods:

Files are normally stored on disks, so the main problem is how to allocate space to these files so that disk space is utilized efficiently and files can be accessed quickly. Three major methods of allocating disk space:

Contiguous Allocation:

In this allocation method, each file occupies a set of contiguous blocks on the disk. This method is best suitable for sequential files. The main problem with this method is that it is difficult to find the contiguous free blocks in the disk.

Linked Allocation:

We can avoid the external fragmentation in this scheme. It is easy to locate the files because allocation is on an individual block basis. Each block contains a pointer to the next free block in the chain. Here is also the file allocation table consisting of a single entry for each file. Using this method any free block can be added to a chain very easily. There is a link between one block to another block, that’s why it is said to be ‘linked allocation‘.

Grouped Allocation or Indexed Allocation:

We can overcome the problem using this method which was faced in the Linked Allocation method. In this method, the file allocation table contains a single entry for each file. The entry consists of one index block, the index block having the pointers to the other blocks which were occupied by the particular file.