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 $\textsf{foo}$.
Which of the following operations will necessarily require a full scan of $\textsf{foo}$ for successful completion?
Correct Options: A, C
(Note: In the question it’s given “which of the following options require a full scan of foo for successful completion” . Meaning the best algorithm scans the list entirely for each type of input to verify the correctness of the procedure and ,can’t partially scan and complete for any particular instance...)
Each File in Directory is uniquely referenced by its name. So different files must have different names!
So,
Consistency should be maintained by the file management system, each file must posses a unique name to identify it, creation requires you to verify all file names before creating it. If we create without checking all file’s name then it would become inconsistent.
@rsonx file names have to be unique in a directory. The directory identifies a file using file name(the directory translates file names into directory entries). Two files can have same name only if they are in different directories or sub-directories because now they will have unique paths.
So why would we need unique paths you might ask, the answer lies in how file system uses a file. To use a file (read() or write()) we first need to open it, which is done via open() system call which requires path of the file as one of the argument.
https://man7.org/linux/man-pages/man2/open.2.html
The above question is only concerned with a single directory named foo. So all the file names in this directory has to be unique.
@sauravgahlawat Probably the best answer for all the doubts
Those who are saying deletion will also cost the whole scanning then please read the option again. Why to check whether a file is there or not??.
Deletion of an existing file from foo
64.3k questions
77.9k answers
244k comments
80.0k users