Source: https://www.guru99.com/file-systems-operating-system.
html
What is File System?
A file is a collection of correlated information which is recorded on secondary or non-volatile
storage like magnetic disks, optical disks, and tapes. It is a method of data collection that is used
as a medium for giving input and receiving output from that program.
In general, a file is a sequence of bits, bytes, or records whose meaning is defined by the file
creator and user. Every File has a logical location where they are located for storage and
retrieval.
File structure
A File Structure needs to be predefined format in such a way that an operating system
understands. It has an exclusively defined structure, which is based on its type.
Three types of files structure in OS:
A text file: It is a series of characters that is organized in lines.
An object file: It is a series of bytes that is organized into blocks.
A source file: It is a series of functions and processes.
File Attributes
A file has a name and data. Moreover, it also stores meta information like file creation date and
time, current size, last modified date, etc. All this information is called the attributes of a file
system.
Here, are some important File attributes used in OS:
Name: It is the only information stored in a human-readable form.
Identifier: Every file is identified by a unique tag number within a file system known as
an identifier.
Location: Points to file location on device.
Type: This attribute is required for systems that support various types of files.
Size. Attribute used to display the current file size.
Protection. This attribute assigns and controls the access rights of reading, writing, and
executing the file.
Time, date and security: It is used for protection, security, and also used for monitoring
Directory Files
Directory contains files and other related information about those files. Its basically a
folder to hold and organize multiple files.
File Access Methods
File access is a process that determines the way that files are accessed and read into memory.
Generally, a single access method is always supported by operating systems. Though there are
some operating system which also supports multiple access methods.
Three file access methods are:
Sequential access
Direct random access
Index sequential access
Sequential Access
In this type of file access method, records are accessed in a certain pre-defined sequence. In the
sequential access method, information stored in the file is also processed one by one. Most
compilers access files using this access method.
Random Access
The random access method is also called direct random access. This method allow accessing the
record directly. Each record has its own address on which can be directly accessed for reading
and writing.
Sequential Access
This type of accessing method is based on simple sequential access. In this access method, an
index is built for every file, with a direct pointer to different memory blocks. In this method, the
Index is searched sequentially, and its pointer can access the file directly. Multiple levels of
indexing can be used to offer greater efficiency in access. It also reduces the time needed to
access a single record.
Space Allocation
In the Operating system, files are always allocated disk spaces.
Three types of space allocation methods are:
Linked Allocation
Indexed Allocation
Contiguous Allocation
Contiguous Allocation
In this method,
Every file users a contiguous address space on memory.
Here, the OS assigns disk address is in linear order.
In the contiguous allocation method, external fragmentation is the biggest issue.
Linked Allocation
In this method,
Every file includes a list of links.
The directory contains a link or pointer in the first block of a file.
With this method, there is no external fragmentation
This File allocation method is used for sequential access files.
This method is not ideal for a direct access file.
Indexed Allocation
In this method,
Directory comprises the addresses of index blocks of the specific files.
An index block is created, having all the pointers for specific files.
All files should have individual index blocks to store the addresses for disk space.
Source: https://www.javatpoint.com/
Single Level Directory
The simplest method is to have one big list of all the files on the disk. The entire system will
contain only one directory which is supposed to mention all the files present in the file system.
The directory contains one entry per each file present on the file system.
This type of directories can be used for a simple system.
Advantages
1. Implementation is very simple.
2. If the sizes of the files are very small then the searching becomes faster.
3. File creation, searching, deletion is very simple since we have only one directory.
Disadvantages
1. We cannot have two files with the same name.
2. The directory may be very big therefore searching for a file may take so much time.
3. Protection cannot be implemented for multiple users.
4. There are no ways to group same kind of files.
5. Choosing the unique name for every file is a bit complex and limits the number of files in
the system because most of the Operating System limits the number of characters used to
construct the file name.
Two Level Directory
In two level directory systems, we can create a separate directory for each user. There is one
master directory which contains separate directories dedicated to each user. For each user, there
is a different directory present at the second level, containing group of user's file. The system
doesn't let a user to enter in the other user's directory without permission.
Characteristics of two level directory system
1. Each files has a path name as /User-name/directory-name/
2. Different users can have the same file name.
3. Searching becomes more efficient as only one user's list needs to be traversed.
4. The same kind of files cannot be grouped into a single directory for a particular user.
Every Operating System maintains a variable as PWD which contains the present directory name
(present user name) so that the searching can be done appropriately.
Tree Structured Directory
In Tree structured directory system, any directory entry can either be a file or sub directory. Tree
structured directory system overcomes the drawbacks of two level directory system. The similar
kind of files can now be grouped in one directory.
Each user has its own directory and it cannot enter in the other user's directory. However, the
user has the permission to read the root's data but he cannot write or modify this. Only
administrator of the system has the complete access of root directory.
Searching is more efficient in this directory structure. The concept of current working
directory is used. A file can be accessed by two types of path, either relative or absolute.
Absolute path is the path of the file with respect to the root directory of the system while relative
path is the path with respect to the current working directory of the system. In tree structured
directory systems, the user is given the privilege to create the files as well as directories.
Acyclic-Graph Structured Directories
The tree structured directory system doesn't allow the same file to exist in multiple directories
therefore sharing is major concern in tree structured directory system. We can provide sharing by
making the directory an acyclic graph. In this system, two or more directory entry can point to
the same file or sub directory. That file or sub directory is shared between the two directory
entries.
These kinds of directory graphs can be made using links or aliases. We can have multiple paths
for a same file. Links can either be symbolic (logical) or hard link (physical).
If a file gets deleted in acyclic graph structured directory system, then
1. In the case of soft link, the file just gets deleted and we are left with a dangling pointer.
2. In the case of hard link, the actual file will be deleted only if all the references to it gets
deleted.
Source: Operating System Concepts Silberschatz, Galvin and Gagne 2002