4.2.34 · D3 · HinglishOperating Systems

Worked examplesFile allocation — contiguous, linked, indexed (inode)

4,206 words19 min read↑ Read in English

4.2.34 · D3 · Coding › Operating Systems › File allocation — contiguous, linked, indexed (inode)

Yeh page File allocation — contiguous, linked, indexed (inode) ke liye "sab kuch daal do" wali drill hai. Hum koi naya theory nahi seekhenge — hum teen schemes ko har tarah ke input pe exercise karenge: normal cases, do index levels ke beech ki boundary, ek zero-size file, ek file jo exactly ek block ki hai, ek growth request jo fail ho jaati hai, aur ek exam twist. Kisi bhi example se pehle, hum saare cases ka ek map banate hain.

Do numbers almost har example mein aate hain, toh hum unhe ek baar plain words mein pin kar dete hain:


The scenario matrix

Neeche har cell ek alag situation hai. Ex column batata hai ki kaun sa worked example use cover karta hai.

Case class Contiguous Linked Indexed (inode)
Normal byte-to-block lookup Ex 1 Ex 3 Ex 5
Boundary levels/blocks ke beech Ex 2 (block edge) Ex 6 (direct↔indirect edge), Ex 12 (single↔double↔triple)
Zero-size / degenerate input Ex 8 (empty & 1-block) Ex 8 Ex 8
Limiting value (max reach) Ex 11 (pointer-width limit) Ex 7 (max file size)
Growth request (kya grow kar sakta hai?) Ex 4 (fails) Ex 4 (succeeds) Ex 4 (succeeds)
Real-world word problem Ex 3 Ex 9 (photo library)
Exam-style twist Ex 11 (width vs count) Ex 10 (reads for 3 blocks)

Related boundaries External vs Internal Fragmentation (Ex 4), Free Space Management (bitmap, free list) (Ex 4 growth), aur File Systems (ext4, FAT, NTFS) (Ex 3 FAT note) mein hain.


Do tools jo hum reuse karte hain (pehli baar use se pehle define kiye gaye)

Neeche dii gayi picture (Figure s01) bytes ko ek lamba ruler dikhati hai aur blocks ko har bytes pe tick-marks; amber arrow byte 9000 ko block 2 mein offset 808 pe land karta hua dikhata hai.

Figure — File allocation — contiguous, linked, indexed (inode)

Ex 1 — Contiguous, normal lookup (matrix: Contiguous / normal)


Ex 2 — Contiguous, block-edge boundary (matrix: Contiguous / boundary)


Ex 3 — Linked, word problem + random access (matrix: Linked / normal + word)

Chain aur uske chaar reads Figure s02 mein draw kiye gaye hain: har cyan box ek data block hai, uske andar amber slot next-pointer hai, aur amber arrows wo links hain jinhe tumhe logical block 3 tak pahunchne ke liye ek-ek karke follow karna hai.

Figure — File allocation — contiguous, linked, indexed (inode)

Ex 4 — Growth request, teeno schemes (matrix: growth row)


Ex 5 — Indexed, normal lookup (matrix: Indexed / normal)


Ex 6 — Inode, direct↔indirect boundary (matrix: Indexed / boundary)

Figure s03 exactly yahi boundary draw karta hai: baayi taraf in-memory inode, data block 11 ki taraf cyan single-read arrow (direct), aur block 12 tak amber two-hop path (indirect block → data block).

Figure — File allocation — contiguous, linked, indexed (inode)

Ex 7 — Inode, limiting value: maximum file size (matrix: Indexed / limiting)


Ex 8 — Degenerate inputs: empty file & one-block file (matrix: zero/degenerate)


Ex 9 — Word problem: ek photo library (matrix: Indexed / word)


Ex 10 — Exam twist: ek range fetch karne ke liye reads (matrix: Indexed / exam twist)


Ex 11 — Linked, limiting value + width-vs-count twist (matrix: Linked / limiting + exam twist)


Ex 12 — Inode, single↔double↔triple boundaries (matrix: Indexed / deep boundary)

Figure s04 chaar regions ko nested pointer-block ladders ki tarah stack karta hai; har ek ke saath amber count reads ko 1 → 2 → 3 → 4 climb karte hue dikhata hai jaisa tum deeper indirection mein jaate ho.

Figure — File allocation — contiguous, linked, indexed (inode)

Recall Quick self-test

Byte 9000 ka contiguous phys, start block 50, B=4096? ::: block 52, offset 808. Linked: chain 7→3→90→12 ke logical block 3 tak pahunchne ke liye reads? ::: 4 reads. Inode with B=4096, p=4, k=1024 — max file size? ::: approximately 4 TB (49152 + 4 MB + 4 GB + 4 TB bytes). Inode mein logical block 12 fetch karne ke liye reads (inode RAM mein)? ::: 2 (single-indirect block + data block). Pehla triple-indirect block fetch karne ke liye reads (uncached)? ::: 4 (triple + double + single + data). B=4096 pe ek 3 MB photo ko kitne blocks chahiye? ::: 733 blocks. Kya ek 0-byte file ko koi data blocks chahiye? ::: Nahi — saare pointers null, lekin inode abhi bhi exist karta hai. Ek 4-byte linked pointer jo sabse badi disk name kar sakta hai? ::: 2^32 blocks × 4096 B = 16 TiB.