What is an inode, and what information does it store?
MediumConceptFile Systems & Disk Scheduling
Answer
An inode (index node) is the structure that Unix and Linux file systems, such as ext4, use to describe a file. It stores the file's metadata and the locations of its data blocks, but not the file's name. Each inode is identified by a number, and the name lives in a directory, which maps names to inode numbers.
- Metadata: file type, permissions, owner and group, size, timestamps (access, modify, change) and the link count (how many names point to it).
- Block pointers: classic ext2/ext3 inodes have 12 direct pointers plus single, double and triple indirect pointers. With 4 KB blocks, the direct pointers cover 48 KB, and one indirect block adds 1,024 pointers, another 4 MB. ext4 uses extents (runs of consecutive blocks) instead.
- Because names are stored separately, one file can have several names (hard links), and renaming a file within one file system only changes a directory entry.
- ext4 creates its inodes when the file system is formatted, so millions of tiny files can exhaust the inodes while disk space is still free.
Example: ls -i notes.txt prints 1048602 notes.txt. To open /home/user/notes.txt, the kernel reads the directory /home/user, finds the entry notes.txt → 1048602, reads inode 1048602 to check permissions and get the block pointers, and only then reads the data blocks.
More in File Systems & Disk Scheduling
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | What is an inode, and what information does it store? | Concept | Medium | Read the answer to What is an inode, and what information does it store? | |||
| 2 | How do directories map file names to inodes, and what is the difference between a hard link and a soft link? | Concept | Medium | Read the answer to How do directories map file names to inodes, and what is the difference between a hard link and a soft link? | |||
| 3 | What are the contiguous, linked and indexed file allocation methods? | Concept | Medium | Read the answer to What are the contiguous, linked and indexed file allocation methods? | |||
| 4 | Compare FCFS, SSTF, SCAN and C-SCAN disk scheduling. | Concept | Hard | Read the answer to Compare FCFS, SSTF, SCAN and C-SCAN disk scheduling. |