in Operating System retagged by
8,313 views
19 votes
19 votes

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?

  1. Creation of a new file in $\textsf{foo}$
  2. Deletion of an existing file from $\textsf{foo}$
  3. Renaming of an existing file in $\textsf{foo}$
  4. Opening of an existing file in $\textsf{foo}$
in Operating System retagged by
by
8.3k views

1 Answer

31 votes
31 votes
Best answer

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,

  1. Creation of a New File: For creating new file, we’ve to check whether the new name is same as the existing files. Hence, the linked list must be scanned in its entirety.
     
  2. Deletion of an Existing File: Deletion of a file doesn’t give rise to name conflicts, hence if the node representing the files is found earlier, it can be deleted without a through scan.
     
  3. Renaming a File: Can give rise to name conflicts, same reason can be given as option A.
     
  4. Opening of existing file: same reason as option B.
selected by

4 Comments

@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. 

 

1
1

@sauravgahlawat Probably the best answer for all the doubts

0
0

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 

0
0
Answer:

Related questions