Friday, September 25, 2015

INODES in Linux

 In Linux Everything Is a File

  
                     In Linux  files inside a file system(be it ext2,ext3 or ext4) are not really accessed by their name. Names are helpful to humans but, the file system recognizes a file not by its name but by a number. That number through which the operating system reaches the location and other attributes of that file is called as an INODE number. 

                              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).

               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.

 
              Size of each inode entry is 128 bytes

 Inode number also called as index number , it consists following attributes

  • Inode number
  • Access Control List (ACL)
  • Extended attribute
  • Direct/indirect disk blocks
  • Number of blocks
  • File access, change and modification time
  • File deletion time
  • File generation number
  • File size
  • File type
  • Group
  • Number of links
  • Owner
  • Permissions
  • Status flags

 Structure of an inode


 




Now lets note down inode numbers of .(dot) and ..(dot dot).
.(dot) =655899
..(dot dot) =655892

Now lets do the directory listing of /sandbox/ directory and see the inodes there:


 
here you can see 
.(dot) = 655892 is same as the ..(dot dot) file of /sandbox/comp$

The . (dot) always means the current directory as its inode is same as the directory inode. Similarly, .. (dot dot) corresponds to parent directory inode as its inode is same as the previous (parent) directory.

How to check Inode utilization : 


As you can clearly see from the above output that the max number of inodes that can be created on /dev/sda1 is 1245184

Lets say, when I do ls -li inside a directory, I get this:

12353538 -rw-r--r-- 6 me me 1650 2013-01-10 16:33 fun.txt

As the output shows, the file fun.txt has 6 hard links; and the inode number is 12353538.



If you already have the inode number you can use find's -inum option:

find -inum 12353538
 










No comments:

Post a Comment