File and Inode

image

File metadata

image

image

Redirection in case of large files image

Maximum file size possible

image

image

image

Soft links image

Difference with example

image

image

image

image

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 image

image

image

Removing a file with journaling

Similar to Write-ahead log image

File Path look up

image

The filesystem root directory is inode 2.

image

image

image

Directory Entries image

Now find the next inode to traverse to image

If directories are huge, this requires navigating singly, doubly, or even triple indirect blocks.

image

How is File system organised

image

We have the bit maps now, what else do we need?

image

image

Ref: L09: Inodes, Super Block, and Boot Block, University of Pennsylvania

Unix V6 Inodes

image