Sunday, 17 April 2016

What is iNode number and iNode table ?


An inode is a data structure on a traditional Unix-style file system such as UFS. An inode stores basic information about a regular file, directory, or other file system object.

When a file system is created, data structures are created that contain information about files. Each file is associated with an inode that is identified by an inode number (often referred to as an"i-number" or "inode") in the file system where it resides.

Inodes basically store information of files and folders, such asuser and group ownership, access mode (read, write, execute permissions) and type of file.
On many types of file systems the number of inodes available is fixed at file system creation, limiting the maximum number of files the file system can hold.
A typical fraction of space allocated for inodes in a file system is 1% of total size.

The inode number indexes a table of inodes in a known location on the device; from the inode number, the kernel can access the contents of the inode, including the data pointers, and so the contents of the file.

A file's inode number can be found using the ls -i command, while the ls -l command will retrieve inode information (i.e. the file information)
  • Inodes do not contain file names, only file metadata.
  • Unix directories are lists of "link" structures, each of which contains one filename and one inode number.
  • The kernel must search a directory looking for a particular file name and then convert the file name to the correct corresponding inode number if the name is found. 
 
iNode Table in Unix
  • Each (unix) file system has its own inode table; on disk each cylinder group will hold a relevant part of that table.
  • Each inode is referenced by a "device + inode number" pair.
  • Each file is assigned an inode number which is unique within that file system; each directory structure will consist of a list of "filename + inode number" pairs; inodes won't hold filenames. 
  • Reserved inode numbers: 0, 1, 2 
         0: deleted files/directories
         1: (fs dependent) file system creation time/bad blocks count/.....
         2: refers to the root directory of the file system

Some common info that Unix INODE structure contains :
  • The "mode" field will always be the first field in the inode; the order of the other fields is file system dependent 
  • timestamps, access time, modification time
  • inode change time: updated after each modification of one of the fields in the inode (chmod, chown, chgrp, ln, ...)
  • triple indirect pointer: use is fs and max.file size dependent
  • status/flags like "compress file" or "do not update access time" or "do not extend file" are file system dependent
  • extra fields may hold: an inode generation number (for NFS) and/or ACL info (sometimes this field contains a "continuation
  • inode number: a pointer to a special inode that holds ACL info) and/or a file type identification
    (For device files: Major and minor number; For directories: inode number of parent directory);
    All extra/reserved fields are file system dependent !


Example
Using the df command, you can look at all mounted file systems or specific file systems. In this view, you can see the number of inodes used already in the respective file system as well as the percentage used overall in the file system

# df -k|head -6
Filesystem    1024-blocks      Free         %Used     Iused         %Iused    Mounted on
/dev/hd4        229376              138436    40%         4730          13%            /
/dev/hd2        8028160            962692    89%        110034      33%            /usr
/dev/hd9var  1835008            366400    81%        25829        24%            /var

Using istat command, you can find the inumber of the specific file as well as other inode items like permissions; file type; UID; GID; number of links (not symbolic links); file size; and time stamps for last updated, last modified, and last accessed.
# istat /usr/bin/ksh
Inode 18150 on device 10/8 File
Protection: r-xr-xr-x
Owner: 2(bin) Group: 2(bin)
Link count: 5 Length 237804 bytes
Last updated: Wed Oct 24 17:37:10 EDT 2007
Last modified: Wed Apr 18 23:58:06 EDT 2007
Last accessed: Mon Apr 28 11:25:35 EDT 2008

Using the ls -i command, you can view the inumber next to the file name.
# ls –i
38988 38991 -p 38984 fileC 38982 fileF 38977 fileI 38978 fileL
38989 - 38980 fileA 38986 fileD 38983 fileG 38987 fileJ

No comments:

Post a Comment

Note: only a member of this blog may post a comment.