Thursday 12 July 2018

inode

You store your information in a file, and the operating system stores the information about a file in an inode(sometimes called as an inode number).



Information about files(data) are sometimes called metadata.
Whenever a user or a program needs access to a file, the operating system first searches for the exact and unique inode (inode number), in a table called as an inode table.


the directory /var/log on my system.


[root@slashroot1 log]# ls -ia
3633723 .                3633786 faillog     3634889 rpmpkgs.3
3633697 ..               3634727 gdm         3634893 rpmpkgs.4
3634833 acpid            3633883 httpd       3633813 samba
Now lets note down inode numbers of .(dot) and ..(dot dot).
command "cd ." will change the directory to the current directory itself.
the command "cd .." will take you to the previous directory.






the directory listing of /var/ directory and see the inodes there.


[root@slashroot1 var]# ls -ia
3633697 .        3634275 cvs    3633698 lib    3633733 nis       3633737 spool
      2 ..       3633724 db     3633729 local  3633734 opt       3633700 tmp
3633844 account  3633725 empty  3633730 lock   3633735 preserve  3634278 tux
3633701 cache    3633726 games  3633723 log    3633838 racoon    3633884 www
3634135 crash    3634624 gdm    3633732 mail   3633736 run       3633740


Inode Structure of a File




Mode:

 

This keeps information about two things, one is the permission information, the other is the type of inode, for example an inode can be of a file, directory or a block device etc.

 

Owner Info: Access details like owner of the file, group of the file etc.

 

Size: This location store the size of the file in terms of bytes.

 

Time Stamps: it stores the inode creation time, modification time, etc.

 

Now comes the important thing to understand about how a file is saved in a partition with the help of an inode.

 

Block Size: Whenever a partition is formatted with a file system.It normally gets formatted with a default block size. Now block size is the size of chunks in which data

will be spread. So if the block size is 4K, then for a file of 15K it will take 4 blocks(because 4K*4 16), and technically speaking you waste 1 K.


Direct Block Pointers:

In an ext2 file system an inode consists of only 15 block pointers. The first 12 block pointers are called as Direct Block pointers. Which means that these pointers point to the address of the blocks containing the data of the file. 12 Block pointers can point to 12 data blocks. So in total the Direct Block pointers can address only 48K(12 * 4K) of data

Indirect Block Pointers:

whenever the size of the data goes above 48k(by considering the block size as 4k), the 13th pointer in the inode will point to the very next block after the data

Now as we have took our block size as 4K, the indirect block pointer, can point to 1024 blocks containing data. which means an indirect block pointer can address, upto 4MB of data


Double indirect Block Pointers:

Now if the size of the file is above 4MB + 48K then the inode will start using Double Indirect Block Pointers, to address data blocks
so Double indirect block pointer can address 1024 Indirect Block pointers(which means 1024 * 4M =4G).So with the help of a double indirect Block Pointer the size of the data can go upto 4G.


Triple Indirect Block Pointers

Now this triple Indirect Block Pointers can address upto 4G * 1024 = 4TB, of file size.








No comments:

Post a Comment