šŸŽ“ BookMCQ
← Back to 12. File System Implementation

šŸ“ Linear list Implementation in Directory (11 MCQs)

Sequential Storage of Directory Entries

Linear-list directory implementation stores directory entries one after another in a sequential structure. Each entry associates a filename with a file identifier or metadata reference. The file-system manager searches the list to locate requested names and updates entries during file creation, deletion, and renaming. This approach provides a simple directory-management mechanism suitable for small collections of files.

Why Simple Directory Structures Are Easy to Maintain

Complex search structures require additional metadata, memory, and maintenance operations. A linear list avoids these costs by storing entries in a straightforward sequence. Its main limitation appears when directories contain large numbers of files because searching may require examining many entries before finding the requested name.

Sequential Searching and Directory Modification

When a file is requested, the directory manager begins at the first entry and compares stored filenames with the requested name. A match identifies the associated file object. Creation normally checks that the name is unused before inserting a new entry. Deletion may remove an entry, mark it free, or compact the directory depending on implementation.

Searching a Directory Containing Five Hundred Files

Suppose a directory contains 500 entries and uses an unsorted linear list. Searching for a file in the last position requires examining all 500 entries. An unsuccessful search also requires examining the complete list. An average successful search under uniformly distributed names examines approximately 250 entries, illustrating the effect of directory size on lookup cost.

Low Metadata Overhead and Increasing Search Costs

Linear lists are easy to implement, require minimal auxiliary structures, and support straightforward insertion. However, lookup time increases linearly with the number of entries, making large directories less efficient. Deletion and space reuse also need careful management. Sorting can improve certain searches, but maintaining sorted order increases insertion and update complexity.

Clarifying Linear and Constant-Time Searching

'A linear list finds every file in constant time' is incorrect because searches may inspect all entries. 'Deleting an entry always requires moving every later entry' is incorrect because implementations can mark entries free or reuse them. 'An unsorted list supports binary search' is incorrect because binary search requires an appropriate ordered structure.

Exam Focus: Directory Lookup Complexity

Trace sequential filename comparisons and calculate the maximum or average number of entries examined. Explain insertion, deletion, and free-entry reuse. Identify the O(n) search complexity of an unsorted linear list. Compare linear lists with hash-table directories, particularly their metadata overhead and suitability for small or large directories.

Key Terms of Linear-List Directories

  • Linear list - Sequential directory-entry structure.
  • Directory entry - Stores a filename reference.
  • Linear search - Examines entries sequentially.
  • Insertion - Adds a directory entry.
  • Deletion - Removes or marks an entry.
  • O(n) - Linear search complexity.
2
Easy
6
Medium
3
Hard

šŸ“ All Linear list Implementation in Directory MCQs

Q1. What term does a UNIX system use for the per‑process entry that references an open file?

A.file descriptor āœ…
B.file handle
C.inode
D.directory entry
šŸ’” Difficulty: easy | āœ… Correct: A

šŸ“– Explanation: The correct answer is \file descriptor\ because UNIX assigns a small integer called a file descriptor to each open file in a process's table. \File handle\ is the Windows terminology, while an inode stores metadata on disk and a directory entry contains name information. Understanding the naming convention helps students recognize platform‑specific APIs and why code using descriptors works across UNIX environments.

Q2. Which component typically stores inode information for open files in a system‑wide structure?

A.superblock
B.open‑file table āœ…
C.inode cache
D.block bitmap
šŸ’” Difficulty: easy | āœ… Correct: B

šŸ“– Explanation: The open‑file table holds the inodes and related data for files that are currently open. The superblock describes the overall file system, the inode cache may hold recently used inodes but is not the primary table, and the block bitmap tracks free blocks. Knowing the role of the open‑file table clarifies how the OS quickly accesses metadata without consulting disk each time.

Q3. Why does the operating system decrement the open‑count when a process closes a file?

A.To free the file’s disk blocks immediately
B.To track how many active references exist āœ…
C.To delete the file from the directory
D.To reset the file’s permission bits
šŸ’” Difficulty: medium | āœ… Correct: B

šŸ“– Explanation: Decrementing the open‑count records how many processes still have the file open. When the count reaches zero, the system knows it can release cached metadata and write back any pending changes. It does not delete the file or alter permissions; those actions occur only on explicit system calls. Recognizing this reference‑counting mechanism explains resource cleanup in multi‑process environments.

Q4. How does caching file metadata improve performance in BSD UNIX systems?

A.It eliminates the need for any disk I/O
B.It reduces the number of disk reads by reusing recently accessed information
C.It speeds up network connections only āœ…
D.It allows the OS to bypass permission checks
šŸ’” Difficulty: medium | āœ… Correct: C

šŸ“– Explanation: Caching metadata means the OS can answer queries about a file (size, timestamps, location) from memory instead of reading the inode from disk each time. This reduction in disk I/O accounts for the high cache‑hit rate (ā‰ˆ85 %). The cache does not eliminate all I/O nor affect network speed directly, and permission checks still occur. The benefit is faster file‑system operations for applications.

Q5. A program opens a file, reads data, then crashes without explicitly closing the file. What happens to the system‑wide open‑file entry?

A.It remains forever, causing a leak
B.The OS automatically decrements the open count when the process terminates āœ…
C.The entry is immediately removed at the crash point
D.The file becomes read‑only until manually closed
šŸ’” Difficulty: medium | āœ… Correct: B

šŸ“– Explanation: When a process ends abruptly, the operating system reclaims its resources, including any open file descriptors. It decrements the open count and, if that count becomes zero, flushes metadata and removes the entry. The entry does not persist indefinitely, and the file’s mode does not change because of the crash. This automatic cleanup prevents resource leaks in a multitasking environment.

Q6. Two processes open the same file. Process 1 writes and closes it, while Process 2 remains open. When is the file’s metadata flushed to disk?

A.Immediately after Process 1 writes
B.Only after Process 2 also closes the file
C.When the system‑wide open count reaches zero āœ…
D.Never, because caching prevents flushing
šŸ’” Difficulty: medium | āœ… Correct: C

šŸ“– Explanation: Metadata is written back only when the last reference to the file is closed, i.e., when the system‑wide open count becomes zero. Process 1’s close reduces the count but does not trigger a flush because Process 2 still holds the file open. This ensures that any further changes by remaining processes are not lost. Immediate flushing after a write would be inefficient, and caching does not block flushing entirely.

Q7. A network socket is opened using the same open‑file table as regular files. After the socket is closed, which effect occurs on the table?

A.The socket entry remains but is marked inactive
B.The entry is removed and the open count is decremented
C.The socket is converted into a regular file entry
D.The table size doubles to accommodate network entries āœ…
šŸ’” Difficulty: hard | āœ… Correct: D

šŸ“– Explanation: The unified open‑file table treats sockets like files; closing the socket causes the OS to decrement the open count and, when zero, remove the entry entirely. The entry is not retained as inactive, nor is it transformed into a file record. The table does not grow because of a single socket; it simply reclaims the slot. Understanding this uniform handling clarifies how the OS abstracts diverse resources.

Q8. Why is the file name not required in the per‑process open‑file table after locating the FCB on disk?

A.Because the name is stored in the inode
B.Because the FCB uniquely identifies the file for all operations
C.Because the name is irrelevant to the OS āœ…
D.Because the name is cached elsewhere permanently
šŸ’” Difficulty: hard | āœ… Correct: C

šŸ“– Explanation: Once the file control block (FCB) is located, it contains all necessary identifiers (inode number, device, etc.) to perform reads, writes, and seeks. The name is only needed for name resolution during the open call; after that, operations use the FCB reference. Storing the name would be redundant and waste memory. This design streamlines per‑process tables and speeds subsequent file operations.

Q9. A system reports an 85 % cache‑hit rate. If 1,000 file accesses occur, how many disk reads are expected?

A.150 āœ…
B.850
C.1000
D.0
šŸ’” Difficulty: hard | āœ… Correct: A

šŸ“– Explanation: With an 85 % hit rate, 15 % of accesses miss the cache. Expected disk reads = 1,000 × 0.15 = 150. Option A reflects this calculation. Options B and C ignore the miss proportion, and option D assumes perfect caching. Translating hit‑rate percentages into concrete I/O counts helps students assess performance impact in real workloads.

Q10. What is the primary advantage of using a single mechanism (open‑file table) for files, directories, devices, and network connections?

A.It reduces code size only
B.It provides a uniform interface for resource management āœ…
C.It eliminates the need for permissions
D.It speeds up CPU clock cycles
šŸ’” Difficulty: medium | āœ… Correct: B

šŸ“– Explanation: A unified table lets the OS manage diverse resources with the same data structures and reference‑counting logic, simplifying implementation and reducing bugs. While code size may shrink and permissions still apply, the key benefit is the consistent interface that allows processes to treat sockets, files, and devices similarly. This uniformity is fundamental to modern operating‑system design.

Q11. A developer notices frequent open/close cycles for the same file and wants to reduce overhead. Which caching strategy is most effective?

A.Cache the file descriptor āœ…
B.Cache the file’s data blocks
C.Cache the directory entry
D.Cache the process table
šŸ’” Difficulty: medium | āœ… Correct: A

šŸ“– Explanation: Caching the file descriptor (i.e., reusing the same open‑file entry) avoids repeated look‑ups and reference‑count updates, cutting the cost of opening the file repeatedly. Caching data blocks helps read performance but does not eliminate the open/close overhead. Directory entries and process tables are unrelated to this specific inefficiency. Selecting the descriptor cache directly addresses the observed overhead.

šŸ”— Related Topics (MCQs)