Tuesday, April 30, 2013

Inode

An inode is a data structure in Unix/Linux file systems that stores information (metadata) about a file system object, except file content and file name. The command stat allows us to retrieve most information stored in an inode. Here is an example of system file bash on a Linux box:

  File: `/usr/bin/bash'
  Size: 902036        Blocks: 1768       IO Block: 4096   regular file
Device: 808h/2056d    Inode: 279026      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:shell_exec_t:s0
Access: 2013-05-01 13:59:45.680608666 +0800
Modify: 2013-01-31 22:47:10.000000000 +0800
Change: 2013-03-21 10:29:27.135450340 +0800
 Birth: -


We can see that regular files have the following attributes:
  • Size in bytes
  • Device ID where the file is stored
  • Inode number
  • Link count
  • User ID of the file
  • Group ID of the file
  • Permissions (access rights) of the file
  • Timestamps on last access (atime), modify (mtime), and change (ctime)
To get the file content, we need to consult to the inode pointer structure that is also part of information stored in inode. The inode pointer structrure consists of four different pointers:
  • direct pointer,
  • singly indirect pointer,
  • doubly indirect pointer, and
  • triply indirect pointer
These pointers point directly or indirectly to block locations where pieces of file content are stored.


One question remains: where is the file name stored? The answer is that it is stored in the content of the directory that contains the file. Unix/Linux directories are lists of association structures, each of which consists of one file name and one inode number for that file. That is why we need to specify (implicitly or explicitly) the path whenever we want to access a file in the file systems.

No comments:

Post a Comment