Consider a linear list based directory implementation in a file system. Each directory is a list of nodes, where each node contains the file name along with the file metadata, such as the list of pointers to the data blocks. Consider a given directory .
Which of the following operations will necessarily require a full scan of for successful completion?
View worked solution
Answer: A;C
In a linear list-based directory implementation, directory entries (nodes containing file names and metadata) are stored sequentially. To search for a file name, we must traverse the list linearly from the beginning.
Let's analyze each operation for successful completion:
- Creation of a new file in
Before creating a new file, the operating system must ensure that no other file with the same name already exists in the directory . To guarantee uniqueness, the entire linear list must be scanned. If the file is indeed new (successful creation), the search will reach the end of the list without finding a match. Thus, a full scan is necessarily required. - Deletion of an existing file from
To delete an existing file, we search for its name in the list. For successful completion, the search stops as soon as the target file is found. Since the file exists, it may be found before reaching the end of the list. Thus, a full scan is not necessarily required. - Renaming of an existing file in
Renaming a file from an old name to a new name requires two steps:- Finding the file with the old name (which can be a partial scan).
- Ensuring that the new name does not already exist in the directory to prevent name collision. This uniqueness check requires searching the entire list. Since the new name must not exist for a successful rename, this check will always result in a full scan.
- Opening of an existing file in
To open an existing file, we search for its name to locate its metadata. The search terminates successfully as soon as the file is found, which does not require scanning the remainder of the list. Thus, a full scan is not necessarily required.
Therefore, only operations A and C necessarily require a full scan of the directory.
Free practice · Your answers on this page are not saved.
