Superblock-inode tables-inodes

The superblock contains information regarding the filesystem type, the size and status of a partition, metadata information, number of inodes and data blocks, how much data a datablock holds in kilobytes.

An inode table consists of a number of inodes which in turn contains information for a file or a directory in a filesystem. Each inode has a unique number that corresponds to each file/directory the inode is associated with.

SuperBlock

The superblock contains information regarding the filesystem type, the size and status of a partition, metadata information, number of inodes and data blocks, how much data a datablock holds in kilobytes.


Inode Table and inodes

An inode table consists of a number of inodes which in turn contains information for a file or a directory in a filesystem. Each inode has a unique number that corresponds to each file/directory the inode is associated with. There is a fixed amount of inodes available in a filesystem which indicates the maximum number of files that a filesystem can hold.

The information contained in an inode for a file/directory are: – Time stamp. – Permissions/ownership. – File size and data block location.

Through the inode the kernel can find the information mentioned above along with the location of the data block that is associated with it. In addition, the kernel is responsible for creating/modifying directories. Processes however can read the directories.

One important thing to note, is that inodes do not contain filename information. Instead the filename is associated with a particular inode. More than one filename can be associated with the same inode. The kernel may search for a file using as reference a filename but when the filename is found, it converts the file name to the corresponding inode number.
Here is some inode information that we can get from directories and files by running the ls command with the i option which will give us inode numbers.

drwxr-xr-x   2   sfentona sfentona   6547214    4096 2008-01-11 17:55 Documents
drwxr-xr-x   2   sfentona sfentona   6547211    4096 2008-01-11 17:55 Download
-rw-rw-r--   1   sfentona sfentona   6547248      45 2008-01-22 21:19 log.txt
             |                          |
             v                          v
         Link Count                inode number

As you can see since these files are not linked, their inode number is unique. You can also notice that the Documents file is a directory drwxr-xr-x. The Link Count, which refers to how many inodes a file has, is two even though the directory it self is not hard linked. So what is the reason for this Willis you might ask and to find the answer to this you will have to keep on reading.


Directories, inodes and data

A directory is a list of dentries for a all the files that it contains. A dentry associates a filename with an inode. As mentioned before, inodes do not contain filename information. Thus there needs to be a middle man that will be able to associate the actual filename with the inode of that file.
A directory has a Link Count of two or more because it is being referenced by it self and from the parent directory.


Data Block

Is a series of bytes which make the content of a file/directory. In the case of a directory, the data block for that directory has a list of the files included within that directory. It too will have an inode.


Linked files

Linked files are files that are associated with one another. There are two types of Linked files. Hard links and Soft links.


Hard Linked files

Are files that share the same inode number which that makes them exact copies of one another. A change on one file will be mirrored to the other (linked) file as well. Two files can share the same inode number only if they reside on the same file system. When you delete one of the files the other file will still be preserved along with the inode. The link count will be minus that file. When two or more files are hard linked, they share the same inode and this can be displayed by running the ls -l command which lists the contents of a directory.
Here is an example of a listing.

In order to create a hard link you will need to use the ln command. Following there is an example on how to create a hard link to a file called TestFile.

Format of the ln command:
ln file1 name-of-file-that-will-be-linked-to-file1

Example

ln Testfile  TestFile1

Here is what the ls command will produce with the options of listing and inode display (-li)

ls -li
49284415 -rw-r--r--  1 root  root       17 Oct 31 21:44 status
49283523 -rw-r--r--  2 root  root        6 Nov 23 12:05 TestFile
49283523 -rw-r--r--  2 root  root        6 Nov 23 12:05 TestFile1
52330504 drwxrwxr-x 12 beast beast    4096 Nov 22 00:36 vmware
-----------------------------------------------------------------------------------

As you can see:
-The inode number for TestFile and Testfile1 is the same 49283523
-The number 2 shows that two files share the same inode.


Soft Linked files

Soft link also known as a Symbolic link does not share the same inode with the original file. The purpose of a symbolic link is to point to the original file (data block).
You can create a symbolic link by using again the ln command by passing the -s option.
Example

ln -s TestFile TestFile3

49284415 -rw-r--r--  1 root  root       17 Oct 31 21:44 status
49283523 -rw-r--r--  2 root  root        6 Nov 23 12:05 TestFile
49283523 -rw-r--r--  2 root  root        6 Nov 23 12:05 TestFile1
49283628 lrwxrwxrwx  1 root  root        8 Nov 23 12:32 TestFile3 -> TestFile
52330504 drwxrwxr-x 12 beast beast    4096 Nov 22 00:36 vmware
-----------------------------------------------------------------------------------
As you can see:
-The inode number between file TestFile 49283523 and TestFile3 49283628 are different.
 Which in turns it means that the inode share number indicator for TestFile3 will be 1
-TestFile3 is pointing to Testfile: TestFile3 -> TestFile

Ever Wondered what happens when:

  • A file is deleted
-File is located in whatever directory it resides.
-System checks to see if process has Write permissions with this specific directory.
-If it has Write permissions then it reads the inode for the file that will be delete.
-File is deleted.
-The data block of the file that was deleted along with the now available inode

number is added to the available list so it can be used later on again when a new file is created.

Share Button

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload the CAPTCHA.