Internal Structure of UNIX File system
In this article, we will learn about the UNIX file systems and its internal structure in detail.
What do you mean by the UNIX Operating system?
All the utilities and applications are stored as files. It is a logical method of organizing and storing large amounts of information.
In UNIX, the file system is a hierarchical structure of files and directories where users can store and retrieve information using the files.
Structure of the UNIX file system
All the files in the UNIX system are related to one another.
The Directory structure of the UNIX File system are given below:
Root ( / ): The top of the directory structure is called root. It is also called parent directory as it contains all the subdirectories of the UNIX file system. It is represented by using slash symbol in UNIX system.
/lib: This directory contains all the information of system libraries functions and some critical files such as kernel modules or device drivers. It also contains the system calls that the compiler can include in a program.
/bin: This directory contains the system's binary files and certain fundamental utilities. It is the directory for admin-level commands such as ls or cp. The path (var) always shows this directory in the list.
Following is the subdirectory of /bin directory:
- /sbin: If there is a command you cannot execute, the system administrator can execute this so that it could be in this directory. Only the system and administrator path show this directory.
/dev: It stands for "devices" and contains all the information about the device files used in the UNIX system. These files do not occupy any space on the disk. It contains al; information about hard disks, file representations of peripheral devices, floppy disks, device information, and pseudo-devices.
Following is the subdirectory of /dev directory:
- /dev /HD1: This device file contains the first hard disk drive information.
- /dev /HD2: This device file contains the second hard disk drive information.
- /dev /FD0: This device file contains the first floppy disk drive information.
- /dev /FD1: This device file contains the second floppy disk drive information.
/etc : This directory and its subdirectories contain many of the UNIX configuration files and system databases. These files have many text files that can be changed according to the system's functionality. It also contains the information of your login name and password.
Following is the subdirectory of /etc directory:
- /etc/passwd: This directory contains information about your system password.
- ./etc/shadow: This directory contains information on the original password.
/home: This directory contains all the information of home directories for the users. Whenever a user log in to the system, the UNIX system automatically places you in a home directory.
If you log in the UNIX system using the login name demo, you would be in a directory that could have pathname /home/demo
This directory is created by the system when your account is opened. You can change your home directory using the cd command whenever you require. To check the home directory in which you are currently working, you can use the pwd command.
/tmp: This directory contains the information of all the temporary files created by UNIX or by the user in the UNIX system.
/var: The variable directory of a UNIX file system contains all the information of print jobs and outgoing and incoming emails. The variable part of a file system may be placed for files as database storage.
Following is the subdirectory of /var directory:
- /var/log: This directory contains the information of system log files.
- /var/mail: This directory contains the information where all incoming emails are stored.
- /var/spool: This directory is also called spool directory. It contains information on print jobs, mail spools, and other queued tasks.
- /var/tmp: This directory contains the information of temporary files.
/usr: This directory contains all the information related to the users in a UNIX system. It means it contains all the user account such as user1, user2, and so on.
Following is the subdirectory of /usr directory:
- /usr/bin: This directory stores the information of all the user binary used in UNIX system.
- /usr/include: This directory stores the information of all the development headers used in the system. The # mostly uses header files include directives in the C/C++ programming language.
What do you mean by the internal structure of the UNIX file system?
A file system is a group of files that contains information about how files and inodes are stored on the disks.
The internal view of the UNIX file system shows in the following figure:
In the above figure, it defines several parameters such as:
- Boot block: It is the first block of the UNIX file system and contains a small bootstrap program, i.e., known as a bootstrap program. It is loaded into the main memory and executed when booted up. This bootstrap program is fetched from the boot block of one file system known as a root file system.
Superblock: It contains static parameters of the file system like total size, the total number of data blocks and file system status, number of inodes, the free and used inodes, and the block size for the file system. The superblock is kept in the memory and maintained by the kernel.
The file system organization divides disk partitions into one or more areas called cylinder groups. This group consists of one or more consecutive cylinders on a disk. Each cylinder consists of a duplicated copy of the superblock, space for inodes, and a piece of summary information describing the usage of data blocks within the cylinder group.
Inodes: It stands for index node. When a file is created, an inode is also created to keep the information about all attributes of the particular file. The number of inodes represents the maximum number of files in the UNIX system.
A file's inode is responsible for storing the entire file's relevant data, except its name, which is stored as an entry in its parent directory.
When a file is opened, the kernel copies its corresponding inode from disk to main memory. The inode includes the type of file, a file's access information, i.e., read, write or execute several links to the file, length of files in bytes, and representations of the user and group who owns the file.
In the above figure, a closer look at the inode structure reveals that the addressing is not always straightforward. In this, there is a concept of indirect, double, and even triple indirect disk block address as shown in the below figure:
In UNIX, when a file is created, it is assigned a unique number known as an inode number. In this way, every file in UNIX has an inode number. UNIX treats all directories as files, so they also have an inode number.
An inode number assigned to a file can be accessed using the "ls- i" command, while the "ls- l" command will retrieve the inode information.
- Data blocks: The data blocks start at the end of the inode list and contain the file data. An allocated data block can belong to one and only one file in the UNIX system. The disk head seeks to access the data block, and we allocate blocks from the same cylinder group. If a single file cannot take up all the blocks in a cylinder group and a file exceeding a certain size then a further block allocation redirected to a different cylinder group.