In Linux ext4, directories map string file names to integer Inode numbers. The ext4 journal log prevents file corruption during unexpected power outages by recording metadata changes in a circular journal buffer before committing writes to primary disk blocks.
// Inspecting File Inode metadata using stat() in C
#include <stdio.h>
#include <sys/stat.h>
int main() {
struct stat file_stat;
if (stat("/etc/passwd", &file_stat) == 0) {
printf("Inode Number: %lu\n", file_stat.st_ino);
printf("File Size: %ld bytes\n", file_stat.st_size);
printf("Hard Link Count: %lu\n", file_stat.st_nlink);
printf("Permissions (mode): %o\n", file_stat.st_mode & 0777);
}
return 0;
}Visual representation of control loops, memory layout, and execution flow for File Systems, Inodes & Directory Architecture.
The OS opens root Inode 2, searches directory entries (dentry) matching the path components, and retrieves the target file Inode number.
The kernel reads the Inode from the Inode Table and checks process UID/GID against file permission bits (rwxrwxrwx).
Small files use 12 Direct Block Pointers. Larger files dynamically traverse Single, Double, or Triple Indirect Pointer blocks to read file data.
When `rm` is called, the directory entry is removed and the Inode link count (`st_nlink`) decrements. Data blocks are freed ONLY when link count == 0 AND all open file descriptors close.
| Feature / Dimension | Hard Link (ln file link) | Soft / Symbolic Link (ln -s file link) |
|---|---|---|
| Inode Association | Points directly to the EXACT SAME Inode number as the target file. | Has its own unique Inode containing a text path string pointing to target filename. |
| Target Deletion Behavior | Deleting original file does NOT delete data; file remains accessible via hard link. | Deleting original file breaks the symlink, resulting in a dangling pointer error. |
| Cross-Filesystem Capability | CANNOT span across different partitions or file systems (Inodes are per-filesystem). | CAN freely link across different disk partitions, network drives, and directories. |
| Directory Linking | Prohibited for regular users to prevent infinite recursive directory cycles. | Permitted and widely used to link folders and directories. |
Detailed answers, interviewer pro tips, key takeaway summaries, and code examples formulated for technical rounds.
✅ Correction: The Inode stores file metadata (size, owner, permissions, timestamps) and block pointers. The file name is stored inside the directory file entry, and file content is stored in physical data blocks.
File Systems organize non-volatile storage using Inode metadata tables and hierarchical directory structures.