Reading — step 1 of 5
Read
~1 min readInodes & Files
Inodes
An inode stores file metadata + pointers to data blocks. NOT the file name (that's in the directory).
ext4 inode (256 bytes):
struct inode {
uint16_t mode; // file/dir/symlink + perms (rwx for u/g/o)
uint16_t uid;
uint32_t size_lo;
uint32_t atime; // access time
uint32_t ctime; // status change time
uint32_t mtime; // modification time
uint32_t dtime; // deletion time (0 if alive)
uint16_t gid;
uint16_t link_count;
uint32_t blocks; // number of blocks used (in 512B units)
uint32_t flags;
uint32_t block[15]; // direct + indirect pointers
uint32_t version;
uint32_t file_acl;
uint32_t size_hi;
...
};
Inodes occupy a fixed-size table allocated at FS creation. Number of inodes is fixed unless you grow.
stat() returns mostly inode contents.
Direct vs indirect pointers (classic ext2/3):
- 12 direct: each points to a data block (12 × 4 KiB = 48 KiB).
- 1 indirect: points to a block of pointers → 1024 × 4 KiB = 4 MiB.
- 1 double-indirect: 1024 × 1024 × 4 KiB = 4 GiB.
- 1 triple-indirect: 4 TiB.
Total max: ~4 TiB per file (ext2/3). ext4 added extents.
Extent: (start_block, length, file_offset). One extent describes a contiguous run.
- ext4 inode has 4 extents inline; more in an extent tree.
- Better for large contiguous files.
Hardlinks:
link_count≥ 1.- Multiple directory entries pointing to same inode.
- Delete decrements; reaches 0 → free inode + blocks.
Symlinks:
- A separate inode with mode = SYMLINK.
- Data: target path string.
- Following requires re-resolving path.
ls -i shows inode numbers. Inodes are scarce: a FS with 10M inodes can hold only 10M files regardless of disk space.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…