4.2.31 · HinglishOperating Systems

File system concepts — file, directory, path, inode

2,180 words10 min readRead in English

4.2.31 · Coding › Operating Systems


WHAT each thing is


WHY separate name (directory) from metadata (inode)?

directory "docs"                inode 5012                  data blocks
+-----------+--------+          +------------------+        +---------+
|  name     | inode# |          | size, owner,     |  --->  | block 9 |
+-----------+--------+          | perms, times,    |  --->  | block 40|
| a.txt     | 5012   |--------> | link_count = 2,  |  --->  | block 88|
| copy.txt  | 5012   |--------> | block ptrs       |        +---------+
+-----------+--------+          +------------------+

Do names, ek inode, data ka ek copy → a.txt aur copy.txt same file hain.

Figure — File system concepts — file, directory, path, inode

HOW path resolution actually works (derive it step by step)

/home/ana/a.txt open karne ke liye, kernel iterative directory lookup karta hai:

  1. Root inode se shuru karo (uska inode number fixed/known hai, jaise ext-style FS par inode 2).
  2. Root ki directory data padho → entry "home" dhundho → uska inode# lo.
  3. Woh inode load karo, uski directory data padho → "ana" dhundho → inode# lo.
  4. Woh inode load karo, uski directory data padho → "a.txt" dhundho → inode# lo.
  5. Woh inode load karo → ab humein metadata + block pointers mil gaye → permissions check karo → file handle return karo.

HOW the inode addresses data blocks (the block-pointer scheme)


Worked examples


Common mistakes (steel-manned)


Recall Feynman: explain to a 12-year-old

Ek school library imagine karo. Book aapki file hai (actual pages = data). Catalog card inode hai: usme kahani nahi hai, lekin woh batata hai kitni badi book hai, kaun borrow kar sakta hai, aur pages kis shelf par hain. Titles ki folder/list directory hai: woh sirf "title → card number" map karti hai. Path directions hain: "floor 2 jao, room Science, shelf 5". Aap wahi card number do alag titles ke neeche rakh sakte ho — ab ek book ke do naam hain! Jab us card ki taraf point karne wala last title erase ho jaaye aur koi us waqt pad na raha ho, tab librarian pages phenk deta hai.


Active recall

Inode kya hai?
Ek on-disk structure jo ek file ki saari metadata store karta hai naam chodkar (size, owner, perms, timestamps, link count, data-block pointers).
File ka naam kahan store hota hai?
Uski parent directory mein, ek (name → inode number) entry ke roop mein — inode mein nahi.
Directory structurally kya hai?
Ek special file jiska content ek table hai jo names ko inode numbers se map karta hai.
Absolute vs relative path?
Absolute root / se shuru hota hai; relative current working directory se shuru hota hai.
Inode mein link_count kya hai?
Us inode ki taraf point karne wale directory entries (hard links) ki sankhya.
File ke data blocks kab free hote hain?
Jab link_count = 0 HO AUR koi process use open na rakhe (open_count = 0).
Ek badi file ko rename karna (same FS) instant kyun hai?
Sirf ek (name, inode#) directory entry change hoti hai; inode aur data blocks move nahi karte.
Hard link vs symbolic link?
Hard link = SAME inode# ka extra directory entry; symlink = ek file jo ek target PATH string store karti hai, dangle ho sakti hai aur filesystems cross kar sakti hai.
Hard link vs copy?
Hard link ek inode aur data ka ek copy share karta hai; copy ek nayi inode aur naye data blocks banata hai.
Direct + 3 levels of indirect ke saath max file size formula?
(D + k + k² + k³)·B, jahan k = block/pointer-size, B = block size, D = direct pointers.
/a/b/c.txt resolve karne ke liye kitne directory lookups chahiye?
3 (a, b, c.txt); root inode pehle se known hai.
stat kya padhta hai vs naam kahan se milta hai?
stat inode padhta hai (size/perms/times); naam parent directory se aata hai.

Connections

  • Hard links vs Symbolic links
  • ext2-ext4 inode structure
  • Virtual File System (VFS) layer
  • Block allocation and fragmentation
  • File permissions and UID-GID
  • open() read() write() system calls
  • Mount points and multiple filesystems

Concept Map

separates

separates

maps name to

identifies

stores

points to

is bytes plus

located by

each component is

resolves via

many entries share one inode

link count tracks

data freed when count hits 0

File System

Name in Directory

Metadata in Inode

Directory

Inode Number

Inode

Size owner perms times

Data Blocks

File

Path

Directory Lookup

Hard Link