File and Inode
File metadata
Redirection in case of large files
Maximum file size possible
Hard links and soft links
Soft links
Difference with example
π Hard Links vs. Soft Links
A Hard Link is a direct reference to the physical data on the disk (the inode). A Soft Link (or Symbolic Link) is a special file that points to another fileβs path (like a shortcut).
| Feature | Hard Link | Soft Link (Symlink) | Explanation |
|---|---|---|---|
| Inode Number | π Same | π Different | Hard links share the exact same inode as the original; soft links get a new unique inode. |
| Cross Filesystem | β No | β Yes | Hard links must stay on the same partition; soft links can point anywhere (even network drives). |
| Link to Directory | β No | β Yes | Hard linking directories is restricted (to prevent loops); soft links can point to directories easily. |
| Delete Original | π‘οΈ File Stays | π Link Breaks | If the original is deleted, hard links still work (data remains until last link is gone). Soft links become βdangling.β |
| File Size | πΎ Original Size | π€ Path Length | Hard links show the size of the actual data; soft links are tiny (size = length of the path string). |
| Speed | β‘ Fastest | π’ Slightly Slower | Hard links access data directly; soft links require an extra step to resolve the path. |
| Command | ln target link |
ln -s target link |
The -s flag is the key switch to create a soft link. |
π What Data is Stored in an Inode?
An inode (index node) is a data structure in a Unix-style file system that describes a file-system object like a file or a directory. Below is a breakdown of what attributes are actually stored within the inode itself versus what is stored elsewhere.
| Data Attribute | Stored? | Explanation / Notes |
|---|---|---|
| Filename | β No | Filenames are stored in directories, mapping names to inode numbers. |
| Containing Directory | β No | A file can be in multiple directories (via hard links), so the inode does not track a specific parent. |
| File Size | β Yes | Stores the size of the file in bytes. |
| File Type | β Yes | Identifies if it is a regular file, directory, character device, etc. |
| # of Soft Links | β No | Soft links are distinct files; the target inode does not track how many soft links point to it. |
| Location of Soft Links | β No | The inode is unaware of where soft links pointing to it are located. |
| # of Hard Links | β Yes | Used to track reference counts. The file is only deleted when this count reaches 0. |
| Location of Hard Links | β No | The inode knows how many exist, but not where they are in the directory tree. |
| Access Rights | β Yes | Stores permissions (e.g., Read, Write, Execute for User/Group/Others). |
| Timestamps | β Yes | Tracks creation (ctime), modification (mtime), and access (atime) times. |
| File Contents | β οΈ Sometimes | Generally No (data is in blocks), but some file systems store very small files directly in the inode (inline data). |
| Ordered List of Data Blocks | β Yes | Contains pointers to the disk blocks where the actual file content resides. |
Checking the details on ubuntu system
stat . shows the inode number of the directory
β file_lab stat .
File: .
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 801h/2049d Inode: 2704410 Links: 2
Access: (0775/drwxrwxr-x) Uid: ( 1000/ ubuntu) Gid: ( 1000/ ubuntu)
Access: 2026-01-18 00:30:20.990237727 -0800
Modify: 2026-01-18 00:30:16.994211085 -0800
Change: 2026-01-18 00:30:16.994211085 -0800
Birth: -
β file_lab ls -lai
total 8
2704410 drwxrwxr-x 2 ubuntu ubuntu 4096 Jan 18 00:30 .
2623640 drwxr-xr-x 42 ubuntu ubuntu 4096 Jan 18 00:30 ..
hard link with same inode number
touch original.txt
ln original.txt alias.txt
ls -li *.txt
2630901 -rw-rw-r-- 2 ubuntu ubuntu 0 Jan 18 00:31 alias.txt
2630901 -rw-rw-r-- 2 ubuntu ubuntu 0 Jan 18 00:31 original.txt
Directory and entry
Everything is a file, even directory
- Directory: A type of file that acts as a container for other files.
- Dentry (Directory Entry): A kernel data structure representing a specific component of a path.
Removing a file with journaling
Similar to Write-ahead log
File Path look up
The filesystem root directory is inode 2.
Directory Entries
Now find the next inode to traverse to
If directories are huge, this requires navigating singly, doubly, or even triple indirect blocks.
How is File system organised
We have the bit maps now, what else do we need?
- We donβt have any information about the file system itself. Some questions we need
answers to.
- How large are the blocks, how many inodes in the inode table, how many free blocks in total, how many blocks are allocated to data, how many blocks are hidden from the user (just for the os usage), what type of file system is this, what is the size of each inode, which is the first nonspecial inode, is the file system in a valid state, and much much more
- The Super Block - Is a block in the filesystem that contains metadata about the file system itself.
- Used by the operating system to maintain the file system
- Because it is so important, many copies of the super block are maintained within the file system.
- Just incase the super block the kernel has becomes corrupted
- Required overhead, as the superblock is written back to disk frequently
Ref: L09: Inodes, Super Block, and Boot Block, University of Pennsylvania