File Management – Directory and Directory Operations

By | November 21, 2021

A Directory is a symbol table of files that stores all the related information about the file it holds with the contents. Thus, a directory is a list of files. Each entry of a directory defines a file. A typical directory entry may contain the information like file name, type, its version number, size, owner of file, access rights, date of creation, date of last backup and date of last reference. Millions of files present in the system need to be managed. Directories provide means to organize files in a structure.

Basic Information

File name Name as chosen by creator. It must be unique within a specific directory.
File type For example, text, binary, load module etc.
 File organization For system that supports different organization.

Address Information

Volume Indicate device on which file is stored.
Starting address Starting physical address on secondary storage (eg, cylinder, track and block number on disk).
Size used Current size of the file in bytes, words or blocks.
Size allocated The maximum size of the file.

Access Control Information

Owner User who is assigned the control of this file.
Access information It includes user’s name and password for each authorized user.
Permitted action Controls reading, writing, executing, transmitting over a network.

Usage Information

Data created When file was first placed on directory. U
Identity of creator Usually but not necessarily the current owner.
Date last read access Date of the last time a record was accessed.
Identity of last reader User who did the reading.
Date last modified Date of the last update, insertion or deletion.
Identity of last modifier User who did the modification.
Date of last backup Date of the last time the file was backed up on another storage medium.
Current usage Information about current activity on the file, such as process or processes that have the file open, whether it is locked by a process, and whether the file has been updated in main memory but not yet on disk.

Directory Operations

Just as with files, several systems calls are allowed for managing directories. They vary from system to system.

File Management - Directory Structure and Operations

Some of the common system calls used to manipulate directories are: 

  1. CREATE: A directory is created. It is empty except for dot (.) and dotdot (-.), which are put there automatically by the system.
  2. DELETE: A directory is deleted. Only an empty directory can be deleted. A directory containing only dot () and dotdot (.) is considered empty, as these usually cannof be deleted. In order to delete a directory containing subdirectories, first the subdirectories should be deleted. 
  3. OPENDIR: Directories can be opened for reading it. 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.
  4. CLOSEDIR: When a directory has been read, it should be closed to free up internal table space.
  5. READDIR: This call returns the next entry in an open directory. Formerly, it w possible to read directories using the usual READ system call, but that approach b the disadvantage of forcing the programmer to know and deal with internal structure of directories. In contrast, READDIR always returns one entry in standard format, no matter which of the possible directory structure is being used renamed i.e.., it is possible to
  6. RENAME: Just like files, the directories can also change the name of existing directory.
  7. LINK: 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 path. In this way, the same file may appear in multiple directories.
  8. UNLINK: With this call, a directory entry is removed. If the file being unlinked is only present in one directory it is removed from the file system. If it is present in multiple directories, only the path name specified is removed and the other one remains as such.