π File Management β Basic Concepts
πΉ What Is a File?
A file is a named collection of related data stored on a secondary storage device (like a hard disk or SSD). Files are the primary means by which data is organized and accessed in most operating systems.
Think of a file as a container for storing digital informationβtext, images, videos, program instructions, etc.
π What Is File Management?
File management is a function of the operating system that handles the creation, organization, storage, retrieval, naming, sharing, protection, and deletion of files.
π§± 1. Basic File Concepts
| Concept | Description |
|---|---|
| File Name | Human-readable name used to identify the file (e.g., report.docx) |
| File Extension | Indicates the file type (e.g., .txt, .exe, .jpg) |
| File Structure | Way data is organized in a file: byte stream, records, or tree |
| File Type | Indicates usageβtext, binary, executable, etc. |
| File Attributes | Metadata like creation date, size, owner, permissions |
π§Ύ 2. File Attributes (Metadata)
Files have attributes that describe their properties:
- Name β Unique identifier
- Type β Format of the data (e.g., text, image)
- Location β Where on disk the file resides
- Size β Number of bytes
- Protection β Access rights (read/write/execute)
- Time stamps β Created, modified, accessed
π 3. File Operations
The OS provides a set of operations for file handling:
| Operation | Description |
|---|---|
| Create | Makes a new file with a unique name |
| Open | Prepares a file for reading or writing |
| Read | Retrieves data from a file |
| Write | Stores data into a file |
| Close | Ends access to a file |
| Delete | Removes a file from storage |
| Rename | Changes a file’s name |
| Append | Adds data at the end of a file |
| Seek | Moves the file pointer to a specific location |
ποΈ 4. File Organization
Files can be organized in different structures:
- Byte Sequence (unstructured stream, like in Unix)
- Record-based (used in databases, fixed-length records)
- Tree Structure (hierarchical, used in XML or JSON)
- Indexed (for fast lookup)
ποΈ 5. Directory Structure
Files are stored in directories (folders) to keep things organized. Directory structures include:
| Structure | Description |
|---|---|
| Single-level | All files in one directory |
| Two-level | Separate user directories |
| Tree-structured | Hierarchical, supports subdirectories (most common) |
| Acyclic Graph | Allows shared subdirectories/files |
| General Graph | Allows cycles (complex, requires garbage collection) |
π 6. File Access Methods
a) Sequential Access
- Data is read/written in order
- Simple but slow for random access
- Example: reading a log file
b) Direct (Random) Access
- Access any part of file directly using seek
- Used in databases, multimedia files
c) Indexed Access
- File has an index table for fast searching
- Common in large databases
π§° 7. File Allocation Methods
How space is allocated on disk for storing files:
| Method | Description | Pros & Cons |
|---|---|---|
| Contiguous | Entire file stored in one block | Fast access, but causes fragmentation |
| Linked List | Each block points to the next | No fragmentation, but slow random access |
| Indexed | Uses an index block to point to all file blocks | Fast and flexible |
π₯ 8. File Protection and Access Control
OS ensures data security through:
- Access Control Lists (ACLs) β Define user rights (read, write, execute)
- File Permissions β Unix-style (owner, group, others: rwx)
- Encryption β Data is scrambled to protect from unauthorized access
- User Authentication β Ensures only legitimate users access files
π§ͺ Real-Life Example: Using a Text File
When you open a .txt file:
- OS checks access permissions
- If allowed, it opens the file and places it in memory
- You read/write data using an application
- On closing, OS updates the fileβs metadata (modified time, size)
π Summary
- File management is a core responsibility of any OS.
- It provides a systematic way to store, access, and secure data.
- OS manages files using structures, access methods, operations, and protection mechanisms.
- A robust file system ensures efficiency, security, and data integrity.
