Question-1Explain various directory operations in brief.
System calls, which are allowed for managing directories exhibit more variation from system to system.
Following are common directory operations.
- A directory is created. It is empty except for dot and dot dot, which are put there automatically by the system.
- A directory is deleted. Only an empty directory can be deleted. A directory containing only dot and dotdot is considered as an empty directory.
- Directories can be read. For example, to list all the files in a directory, a listing program opens the directory to read out the names of all the files it contains. Before a directory can be read, it must be opened, analogous to opening and reading a file.
- When a directory has been read, it should be closed to free up internal table space.
- This call returns the next entry in an open directory. Formerly, it was possible to read directories using the usual read system call, but that approach has the disadvantage of
- forcing the programmer to know and deal with the internal structure of directories. In contrast, readdir always returns one entry in a standard format, no matter which of the possible directory structure is being used.
- In many respects, directories are just like files and can be renamed the same way files can be
- Linking is a technique that allows a file to appear in more than one directory. This system call specifies an existing file and a path name, and creates a link from the existing file to the name specified by the path. In this way, the same file may appear in multiple directories. A link of this kind, which increments the counter in the file’s inode (to keep track of the number of directory entries containing the file), is sometimes called a hard link.
- A directory entry is removed. If the file being unlinked is only present in one directory (the normal case), it is removed from the file system. If it is present in multiple
- directories, only the path name specified is removed. The others remain. In UNIX, the system call for deleting files (discussed earlier) is, in fact, unlink.