0% found this document useful (0 votes)
9 views4 pages

Ui 2

The document provides detailed explanations of various UNIX file system concepts, including algorithms for inode management (iput, ialloc, ifree), file structures, and the superblock's role. It outlines the maximum file size based on block size, types of files in UNIX, and the consequences of mismanagement of inodes. Each section is designed to clarify fundamental aspects of UNIX operating systems for educational purposes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Ui 2

The document provides detailed explanations of various UNIX file system concepts, including algorithms for inode management (iput, ialloc, ifree), file structures, and the superblock's role. It outlines the maximum file size based on block size, types of files in UNIX, and the consequences of mismanagement of inodes. Each section is designed to clarify fundamental aspects of UNIX operating systems for educational purposes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ui2.

md 2025-04-07

Alright, you’ve thrown me a whole batch of questions from what I’m guessing is your “Unit 2 Question Bank”
starting at 12. Since you asked for “the answer” after question 11, I’ll tackle all of these (12–24) with clear,
concise explanations, leaning on The Design of the UNIX Operating System by Maurice J. Bach for accuracy.
These are all UNIX file system classics, so let’s dive in like we’re debugging a kernel together!

12. Explain iput algorithm

The iput algorithm releases an inode back to the system when it’s no longer needed. It’s what the kernel calls
when a process closes a file or unlinks it. Here’s how it works:

Decrements the inode’s reference count (in memory).


If the count hits 0 (no processes are using it):
If the link count is 0 (file’s been unlinked), it frees the inode and its data blocks.
Updates the disk inode with any changes (e.g., last access time).
Releases the in-memory inode structure back to the free pool. Think of it as checking a book
back into the library—if no one’s waiting for it and it’s been tossed from the catalog, it’s
shredded.

13. Explain Structure of regular File

A regular file in UNIX is just data—no fancy formatting, just bytes. Its structure is defined by:

Inode: Stores metadata (size, owner, permissions, timestamps) and pointers to data blocks.
Data Blocks: Hold the actual file content. These are referenced in the inode via:
Direct blocks (e.g., 10 pointers to blocks).
Indirect blocks (pointer to a block of pointers).
Double/triple indirect blocks for huge files. It’s like a treasure map: the inode is the map, and the
blocks are the chests of gold (or cat memes).

14. Find the maximum size of file if the block size is 1K?

Let’s assume a typical UNIX inode with 13 pointers: 10 direct, 1 single indirect, 1 double indirect, 1 triple
indirect. Block size = 1K = 1024 bytes.

Direct blocks: 10 × 1024 = 10,240 bytes.


Single indirect: 1 block of pointers = 1024 ÷ 4 (4-byte pointers) = 256 blocks × 1024 = 262,144 bytes.
Double indirect: 256 blocks of pointers = 256 × 256 × 1024 = 67,108,864 bytes.
Triple indirect: 256 × 256 × 256 × 1024 = 17,179,869,184 bytes.
Total: 10,240 + 262,144 + 67,108,864 + 17,179,869,184 = 17,247,050,432 bytes ≈ 16 GB.

Max file size is roughly 16 GB with a 1K block size.

15. What is the superblock? List the fields in the superblock

The superblock is the file system’s control hub—stored on disk, it tells UNIX how the file system is organized.

1/4
ui2.md 2025-04-07

Fields (varies by implementation, but classics include):


File system size (total blocks).
Block size (e.g., 1K, 4K).
Free block count and list (or pointers to free blocks).
Free inode count and list.
Magic number (file system type ID).
Mount status (clean/dirty flag). It’s like the file system’s DNA—everything the kernel needs to
navigate the disk.

16. Explain ialloc algorithm

The ialloc algorithm grabs a free inode for a new file:

Checks the superblock’s free inode list.


Picks the first available inode (or uses a remembered position for efficiency).
Marks it as allocated in memory and on disk.
Initializes its fields (e.g., owner, permissions).
Updates the superblock’s free inode count. It’s like reserving a locker at the gym—find an empty one,
claim it, and set it up.

17. Explain the structure of free inode list in the superblock

The free inode list tracks unallocated inodes:

Superblock holds a small array (e.g., 50–100 inode numbers) of free inodes.
If the list runs low, the kernel scans the inode table for more free ones and refills it.
Inodes in the list are marked free on disk (link count = 0). It’s a quick-access stash—when it’s empty, the
system digs through the full inventory.

18. Explain the process of allocation of a free inode to the file

Kernel calls ialloc.


Picks an inode from the superblock’s free list.
Removes it from the list, decrements free inode count.
Loads it into memory, sets metadata (e.g., type = regular, owner).
Writes changes to disk (eventually).
Returns the inode to the caller (e.g., for a new file). It’s like assigning a parking spot—pick one, mark it
taken, and hand over the key.

19. Explain ifree algorithm

The ifree algorithm frees an inode:

Called when a file’s link count hits 0 (unlinked).


Adds the inode number to the superblock’s free inode list.
Increments the free inode count.

2/4
ui2.md 2025-04-07

Clears the inode’s disk entry (link count = 0, blocks freed).


If the list is full, it might “forget” older entries or adjust. It’s like returning a rented bike—put it back in
the rack for the next rider.

20. Explain the structure of free block list on the superblock

The free block list tracks unallocated disk blocks:

Superblock stores a small array (e.g., 50 block numbers).


One block acts as a “link” to more free blocks (stored as a chain).
When the list empties, the kernel claims the linked block and refills from it. It’s a clever stack—pull
blocks off the top, and when it’s low, grab a new pile.

21. Explain alloc algorithm

The alloc algorithm grabs a free disk block:

Takes a block number from the superblock’s free block list.


Decrements the free block count.
If the list is empty, reads the next linked block into the superblock.
Marks the block as allocated on disk (eventually).
Returns the block number. It’s like snagging a free table at a busy diner—take one, update the
“available” sign.

22. Explain types of files in UNIX

UNIX has seven file types, all defined by the inode:

Regular: Plain data (text, binaries).


Directory: Lists filenames and inode numbers.
Symbolic Link: Points to another file/path.
Block Device: Interfaces hardware (e.g., disks).
Character Device: Streams data (e.g., terminals).
Named Pipe (FIFO): Inter-process communication.
Socket: Network or local communication. Each type gets its own handling—directories organize,
devices talk to hardware.

23. What is the consequence of “A free inode not gets added to the superblock free inode
list”?

If a freed inode isn’t added back:

Free inode count stays wrong (too low).


The inode is effectively lost—unusable until a file system check (e.g., fsck) finds it.
Over time, you’d run out of inodes prematurely, even with free space. It’s like forgetting to mark a
returned book as available—library thinks it’s full when it’s not.

3/4
ui2.md 2025-04-07

24. How freeing an inode and freeing a block is different?

Freeing an Inode (ifree):


Marks the inode free (link count = 0).
Adds it to the superblock’s free inode list.
Metadata-focused; data blocks may still need freeing.
Freeing a Block:
Adds the block number to the free block list.
Updates free block count.
Pure storage—no metadata involved. Inode freeing is about file identity; block freeing is about
raw space. One’s a librarian, the other’s a janitor.

There you go—12 through 24, solved and explained! If you need more depth on any or I’ve misguessed your
question bank, just nudge me. What’s next on your study plate?

4/4

You might also like