Unit-VI File Management
File
management is a critical aspect of an operating system that oversees the
creation, deletion, reading, writing, and protection of files on storage
devices. It provides both user programs and users an abstract view of storage,
regardless of the device specifics.
Key Concepts in File
Management:
- File: A named collection of related data
treated as a single entity. Files are used to store data, executable code,
configuration information, etc.
- Directory: A system-defined file in which
other files and directories can be kept. It provides a mapping between
file names and the actual files, often organizing them in a hierarchical
manner.
- Disk: A physical device that can store
collections of files and directories.
Functions of File
Management:
- File Creation and Deletion: Users and user
programs should be able to create and delete files.
- Directory Creation and Deletion: For
organizing files, users should be able to create and delete directories.
- Support of Primitives for Manipulation: Open,
close, read, write, reposition, or delete a file.
- Mapping Files onto Secondary Storage: Decide
where on the disk a file's data goes.
- Backup: Maintain backup copies of files or
directories in case of system failures.
- Protection: Provide access controls and
permissions for files and directories.
File Attributes and
Metadata:
Each file in a system is
associated with a set of attributes (metadata) that includes:
- Name: Symbolic file name.
- Identifier: Unique tag (number) which
identifies the file within the file system.
- Type: Information about the file type (e.g.,
.txt, .exe).
- Location: Pointer to file location on the
device.
- Size: The current size of the file.
- Protection: Key-controlled access to the file
(read, write, execute permissions).
- Time, Date, and User Identification: Used
for protection, security, and usage monitoring.
File Operations:
- Open: The system searches the directory to
find the file and loads its metadata into memory.
- Close: Releases the opened file, and the
system can remove the metadata from memory.
- Read & Write: Transfer data from the
file to memory and vice versa.
- Reposition within File (Seek): Change the
current file pointer position.
- Delete: Remove the file and reclaim its
storage space.
- Truncate: Allow all the space occupied by
the file to be released but keep its attributes.
File Types:
- Regular Files: Contains user information
(e.g., text files, binary files).
- Directory Files: Contains a list of file
names and the associated attributes.
- Special Files: Used to model I/O devices and
certain system processes.
Directory Structures:
- Single-Level Directory: All files are in the
same directory, which is easy but unorganized.
- Two-Level Directory: Separate directories
for each user.
- Tree-Structured Directory (Hierarchical):
Directories can contain subdirectories, allowing for efficient
organization.
- Acyclic-Graph Directories: Allows
directories to share subdirectories and files.
- General Graph Directory: Has loops which can
make deletion complex, so it's rarely used.
Access Methods:
- Sequential Access: Read/write data in order,
from the beginning to the end of the file.
- Direct (or Random) Access: Access any file
block directly, usually provided by disk storage.
- Indexed: Creates an index for each file; the
index contains pointers to the file blocks, aiding in direct access.
File Protection:
Operating systems protect files
through:
- Access Control Lists (ACLs): List all users
and their associated permissions for each file.
- Capability Lists: For each user, list all
files and associated permissions.
Conclusion:
File
management in an operating system provides the necessary mechanisms for
storage, organization, retrieval, naming, sharing, protection, and manipulation
of information. It plays a pivotal role in ensuring data persistence and
structure, making it easy for applications and users to work with the stored
data.