operating-systems file-management
Definition
File Directory
A directory (or folder) is a special system file that contains mapping information to translate user-defined file names into references to the physical data.
Structure
- Flat List: A single list of entries for the entire partition. Found in very early or simple operating systems.
- Hierarchical Tree: A nested structure where directories can contain files and other sub-directories. This is the standard for modern operating systems.
Pathnames
- Absolute Pathname: Specifies the location of a file starting from the root directory (e.g.,
/home/user/notes.txtin Unix orC:\Users\User\notes.txtin Windows). - Relative Pathname: Locates a file relative to the Current Working Directory (CWD).
.(Dot): Refers to the current directory...(Dot-dot): Refers to the parent directory.
Implementation Variations
Operating systems differ in how they store file attributes relative to the directory:
- Attributes in Directory: The directory entry contains the file name, all its attributes, and the physical address (e.g., in early Windows/MS-DOS systems).
- Long Filenames: In Windows 95/98, long filenames are stored using “extension” directory entries marked with a special attribute byte (0x0F).
- Attributes in i-nodes: The directory entry is kept minimal, containing only the file name and an i-node number. The attributes and block pointers are stored in the referenced i-node (standard in Unix/Linux).
Operations
Standard directory operations provided by the OS include:
create/delete: Creating or removing a directory.opendir/closedir: Opening or closing a directory stream.readdir: Reading the next entry in a directory.rename: Changing the name of a directory.link/unlink: Managing hard links to files.