Understanding inodes is crucial to understanding Unix filesystems. Files contain data and metadata. Metadata is information about the file. Metadata is stored in an inode. The contents of an inode are:
- Inode Number
- Uid
- Gid
- Size
- Atime
- Mtime
- Ctime
- Blocksize
- Mode
- Number of links
- ACLs
Inodes are usually 256 bytes in size. Filenames are not stored in inodes, instead they are stored in the data portion of a directory. Usually filenames are stored in a linear manner, that is why searching for a filename can take a long time. Ext4 and XFS use more efficient Btrees to store filenames in directories, this allows for constant lookup times instead of linear lookup times.
Dentry is short for directory entry and is used to keep track of inode and filename information in a directory.
An inode can contain direct or indirect points to blocks of data for a given file. Direct block means that the inode contains the block number of a block that contains the actual file data. Indirect block means that the inode contains the block number of a block that then contains further block numbers to read data from.
Ext filesystem creates a fixed number of inodes when the filesystem is formatted. If you run out of inodes you have to format the filesystem. XFS does not contain a fixed number of inodes, they are created on demand.
When you delete a file the unlink() system call removes the directory entry for the inode and marks it available. The data blocks themselves are not deleted.
The number of links to a file is maintained in an inode. Each time a hard link is created the number of links increases. Soft links do not increase the number of links to a file or directory.
Superblock contains metadata about a filesystem. A filesystem typically stores many copies of a superblock in case one of them gets damaged. Some of the information in a superblock is:
– Filesystem size
– Block size
– Empty and filled blocks
– Size and location of inode table
– Disk block map
You can read superblock information using the command ‘dumpe2fs /dev/mount | grep -i superblock’.
Like this:
Like Loading...