4.2.34 · D5 · HinglishOperating Systems
Question bank — File allocation — contiguous, linked, indexed (inode)
4.2.34 · D5· Coding › Operating Systems › File allocation — contiguous, linked, indexed (inode)
Poore note mein use hone wale plain-word meanings ki reminders, taaki yahan kuch bhi bina explain kiye notation par depend na kare. Isse ek baar padho aur neeche har trap self-contained ho jaata hai:
Recall
- Ek block disk ka ek fixed-size chunk hota hai (e.g. bytes) — woh sabse chhoti unit jise OS allocate karta hai. Toh = bytes per block.
- Ek pointer ek disk address hota hai (ek number jo ek physical block ko name karta hai). Bytes mein iska size likha jaata hai (e.g. bytes). Toh = bytes jo ek block address store karne ke liye chahiye.
- = ek block ke andar kitne pointers fit hote hain. Yeh ratio kyun? Ek pointer-block sirf ek block ( bytes) hai jo addresses ( bytes each) se bhara hua hai, toh woh unke rakhta hai. ke saath: .
- Logical block = file ka -wa block (0, 1, 2, …). Physical block = disk par actual slot.
- Index array
Index[](indexed allocation): ek table jahan entryIndex[i]woh physical block store karta hai jo logical block ko hold karta hai. Yeh file ke index block mein rehta hai.Index[i]lookup karna ek single array read hai — koi chain walk nahi. - inode (Unix index node): ek chhota per-file structure jo file ki metadata plus uska pointer array hold karta hai — 12 direct pointers (seedha data blocks tak), phir 1 single, 1 double, 1 triple indirect pointer (har ek pichle se ek level gehri block-of-pointers ki taraf point karta hai). File open hone ke baad uska inode RAM mein rehta hai.
- matlab hai "constant work, file size se independent"; matlab hai "work blocks ki sankhya ke saath badhti hai".
- External fragmentation = free space exist karta hai lekin chhote holes mein split ho jaata hai jo use karne ke liye bahut chhote hain — dekho External vs Internal Fragmentation.
- Internal fragmentation / overhead = allocated block ke andar barta hua space.
Poora topic ek three-way tension hai — neeche har "why" ke liye yeh picture mind mein rakho:


True or false — justify
True or false: Contiguous allocation random access deta hai, toh yeh overall best scheme hai.
"Best overall" par False. real hai (address bas
start + i hai, ek addition), lekin yeh external fragmentation aur advance mein file size jaanne ki zaroorat ke saath payment karta hai — yeh trade-off triangle ke ek corner (fast access) mein jeetta hai jabki baaki do kho deta hai.True or false: Linked allocation mein zero wasted space hai kyunki koi bhi free block kisi bhi file mein join ho sakta hai.
Sirf external half sach hai — koi free block kabhi unusable nahi hota. Lekin har block phir bhi next-pointer par bytes kharach karta hai, toh internal overhead hai; block per usable data hai, nahi.
True or false: FAT scheme data blocks ke andar pointer overhead ko eliminate kar deta hai.
Sach. FAT har "next" pointer ko data blocks se nikaal ke ek central table mein le aata hai, isliye har data block poore bytes hold karta hai; pointers ab table mein rehte hain.
True or false: Indexed (inode) allocation har tarah ki fragmentation se completely bachta hai.
False. Yeh external fragmentation se bachta hai (data blocks kahin bhi baith sakte hain), lekin index block khud metadata overhead hai, aur file ka aakhri data block abhi bhi partly empty hota hai (internal fragmentation).
True or false: Sirf 12 direct pointers use karne wali file ke kisi bhi block ko fetch karne ke liye zero extra pointer-block reads chahiye.
Sach. 12 direct pointers inode ke andar hote hain, jo file open hone ke baad already memory mein hota hai, toh blocks 0–11 mein se har ek exactly ek data read karta hai aur koi pointer-block read nahi.
True or false: Linked allocation mein, agar teesre block ka pointer corrupt ho jaaye, toh sirf woh ek block lost hota hai.
False. Ek broken pointer chain ke poore remainder ko orphan kar deta hai — corruption ke baad ka har block unreachable ho jaata hai, kyunki unke addresses sirf us pointer ko follow karke jaane ja sakte the.
True or false: Contiguous allocation ko file ko sequentially padhte waqt kabhi disk seek nahi chahiye.
Essentially sach. Kyunki blocks physically consecutive hain, ek sequential read adjacent locations ko bina koi head repositioning ke walk karta hai — theek yahi wajah hai ki yeh streaming reads mein excels karta hai.
True or false: Triple-indirect pointer Unix file ki maximum size ka main contributor hai.
Sach. Har indirection level reach ko (pointers per block) se multiply karta hai, toh triple level contribute karta hai — geometrically direct, single (), aur double () contributions ko combined dominate karta hai.
True or false: Ek contiguous file ko grow karna hamesha sasta hai kyunki tum bas blocks append karte ho.
False. Tum sirf tabhi append kar sakte ho jab next physical block free ho. Agar ek neighbour file wahan already baith gayi hai, toh poori file ko ek bade free run mein relocate karna padega — potentially bahut expensive.
Spot the error
Spot the error: "Indexed allocation mein logical block ke liye, physical address start + i hai."
Woh contiguous formula hai. Indexed allocation mein koi
start nahi hai; address Index[i] hai, index array mein direct lookup, precisely isliye kyunki data blocks consecutive hone ki zaroorat nahi hai.Spot the error: "Linked allocation access deta hai agar hum directory mein pehla aur aakhri dono blocks store kar lein."
Aakhri block store karna sirf appends mein help karta hai, random access mein nahi. Kisi middle block tak pahunchne ke liye tumhe abhi bhi front se pointers follow karne padte hain — koi cheez tumhe middle mein jump karne nahi deti.
Spot the error: " aur ke saath, ek single index block zyada se zyada blocks ki file ko address kar sakta hai."
Yeh pointers hold karta hai, toh yeh blocks (lagbhag 4 MB) address karta hai, nahi. Confusion bytes-per-block () ko pointers-per-block () se swap kar deta hai.
Spot the error: "FAT scheme mein, logical block padhne ke liye abhi bhi disk reads chahiye chain walk karne ke liye."
Chain ab ek in-memory table mein rehti hai, toh ise walk karna RAM lookups karta hai, disk reads nahi. Tum sirf ek disk read karte ho: woh final data block.
Spot the error: "Double-indirection ke saath logical block 100000 fetch karne mein 2 disk reads lagte hain: double-indirect block aur data block."
Tum middle level bhool gaye. Double indirection matlab hai inode → double-indirect block → single-indirect block → data block, toh yeh 3 disk reads hain (do pointer blocks phir data).
Spot the error: "Contiguous allocation har block mein ek next-pointer store karta hai jaise linked karta hai, bas consecutively."
Nahi. Contiguous koi bhi per-block pointers store nahi karta — "next" block arithmetic se implied hai (
b + i). Pointers ki woh absence hi exactly wajah hai ki iska metadata sirf (start, length) hai.Spot the error: "Inode mein 12 direct pointers ek aisi block ki taraf point karte hain jo 12 data addresses list karta hai."
Woh seedha 12 data blocks ki taraf point karte hain, kisi list ki taraf nahi. Sirf single/double/triple indirect pointers intermediate blocks-of-pointers ki taraf point karte hain.
Why questions
Teen allocation schemes kyun exist karte hain bajaye ek winner ke?
Kyunki teen goals — fast random access, koi wasted space nahi, aasaan growth — conflict karte hain (triangle figure dekho). Har scheme ek sacrifice karta hai doosre kharidne ke liye, isliye "sahi" choice workload par depend karti hai.
Linked allocation pointer size ko usable capacity se kyun subtract karta hai lekin contiguous nahi?
Linked next-block pointer ko har data block ke andar store karta hai, bytes chura leta hai; contiguous ko aisa pointer chahiye hi nahi kyunki agla block arithmetic se milta hai (
b + i), toh saare bytes data rehte hain.Unix multiple levels of indirection kyun use karta hai ek giant index block ke bajaye?
Bahut badi files ke liye kaafi bada ek flat index bahut zyada choti files ki overwhelming majority par space waste karta. Tiered inode chhoti files ko zero-overhead direct pointers deta hai jabki -fold fan-out ke through bahut badi files ko possible bhi banata hai — ek 80/20 optimisation.
Linked aur indexed allocation ke under external fragmentation impossible kyun hai?
Dono data blocks ko disk par kahin bhi rehne dete hain, toh koi bhi single free block kisi bhi file ke liye usable hai. External fragmentation tabhi aata hai jab tum ek badi contiguous run demand karte ho, jo sirf contiguous allocation karta hai.
Indexed allocation random access restore kar sakta hai jabki linked nahi kar sakta — kyun?
Index block saare block addresses side by side hold karta hai, toh
Index[i] ek direct array lookup hai. Linked addresses ko blocks ke andar hi scatter karta hai, har ek ko discover karne ke liye sequential walk force karta hai.Ek file ki maximum possible size jaanna aage se utne blocks allocate karne ki zaroorat kyun nahi?
Indirect pointer blocks lazily create hote hain — sirf jab file us range mein grow karti hai. Formula reachable ceiling deta hai; ek chhoti file sirf woh direct blocks allocate karti hai jo woh use karte hain.
Edge cases
Edge case: Jab ek contiguous file ki length ho toh phys(i) = b + i ka kya hota hai?
Sirf block 0 valid hai ( physical ); koi bhi out of range hai. Formula abhi bhi sahi hai — bound hi ise guard karta hai.
Edge case: Indexed allocation mein, ek brand-new empty file ka index block kya contain karta hai?
Abhi tak koi valid data pointers nahi (saare
Index[] entries unused/null). Index block exist kar sakta hai lekin zero logical blocks map karta hai jab tak data likha nahi jaata.Edge case: Ek Unix file mein exactly 12 blocks hain — kya yeh kabhi single-indirect pointer touch karta hai?
Nahi. Blocks 0–11 precisely 12 direct pointers fill karte hain, toh single-indirect pointer unused rehta hai aur kisi bhi block ko padhna sirf ek data read karta hai.
Edge case: Linked allocation mein logical block 0 ki access cost kya hai?
Yeh sabse sasta case hai: block 0 directory ka stored first block hai, toh ek single read lagta hai () — linked allocation sirf baad ke blocks ke liye hurt karta hai.
Edge case: Contiguous allocation mein, "pehle se file size jaanna zaroor hai" ka matlab ek aisi file ke liye kya hai jo shrink hoti hai?
Shrink karna aasaan hai — bas length reduce karo aur tail blocks free karo, ek hole chodke. Dard growth mein hai, kyunki freed hole kisi bade neighbour ke liye reusable nahi ho sakta, external fragmentation ko feed karta hai.
Edge case: Agar file ki size block size ka exact multiple hai, toh kya uske aakhri data block mein abhi bhi internal fragmentation hai?
Nahi — ek perfect multiple final block ko completely fill karta hai, zero internal waste chodke. Internal fragmentation sirf tabhi aata hai jab aakhri block partially used ho.