Unit 2. Introduction to File System and File Management

INDEX
Overview
2.1. File Concept
2.2. Operations on File
2.3. File Access Methods (Sequential Access and Direct Access)
2.4. Directory Systems File Management Functions.
2.5. File System and Directory Structure organization.
2.6. File Protection
Introduction to File System in Operating System.
Introduction.
A file system is a crucial component of an operating system (OS) that manages the storage, organization, retrieval, and access of data on storage devices.
It provides a structured way to store and manage files and directories, ensuring efficient data handling and security.
Every operating system has its own file system that determines how data is stored and accessed.
Functions of a File System.
1. File Organization and Storage
The file system organizes data into files and directories, making it easier for users and applications to locate and manage information.
It ensures that files are stored efficiently on storage devices like hard drives, SSDs, and USB drives.
2. File Naming and Identification
Each file is given a unique name and extension (e.g.,
.txt
,.jpg
,.exe
) to identify its type and purpose.The file system maintains metadata, including file size, creation date, permissions, and last modified date.
3. File Access and Retrieval
It provides mechanisms to read, write, modify, and delete files.
Access control mechanisms ensure that only authorized users can open or modify files.
4. File Protection and Security
Implements permissions and encryption to protect sensitive data from unauthorized access.
Ensures secure multi-user access by defining user roles (e.g., read, write, execute permissions).
5. Space Management and Optimization
Manages available storage space by allocating and deallocating disk space as needed.
Prevents file fragmentation, ensuring efficient disk utilization.
Types of File Systems
1. Disk-Based File Systems
FAT (File Allocation Table): Used in USB drives and older Windows systems, simple but lacks advanced security features.
NTFS (New Technology File System): Default file system for modern Windows OS, supports encryption and large file storage.
ext (Extended File System): Used in Linux-based systems, with versions like ext2, ext3, and ext4 offering improved performance and reliability.
2. Network File Systems
NFS (Network File System): Allows file access over a network, commonly used in UNIX/Linux environments.
SMB (Server Message Block): Used in Windows for sharing files across a network.
3. Flash-Based File Systems
exFAT: Designed for flash storage devices, supporting large files and improved performance.
YAFFS (Yet Another Flash File System): Optimized for flash memory in embedded systems and mobile devices.
File System Operations
Create: Generates a new file with a specified name and location.
Read: Opens a file for viewing its contents.
Write: Modifies or adds new data to an existing file.
Delete: Removes a file permanently from storage.
Rename: Changes the name of a file.
Copy and Move: Transfers files within the system or to different storage locations.
Operations on Files in an Operating System
Introduction.
A file is a collection of data stored on a computer system.
The operating system (OS) manages files by providing various operations to create, modify, organize, and access them efficiently.
These file operations ensure that users and applications can interact with stored data effectively while maintaining security and integrity.
Types of File Operations.
1. File Creation
A file is created when a user or a program needs to store data permanently.
The OS assigns a name, file type, and location on the storage device.
Metadata such as file size, creation date, and access permissions are recorded.
2. File Opening
Before performing any operation, a file must be opened.
The OS checks permissions to ensure the user has the required access rights.
A file handle or descriptor is assigned to track the open file session.
3. File Reading
The OS allows users or applications to retrieve data from a file.
Data is read sequentially or randomly, depending on file structure and access methods.
The read operation does not modify file contents.
4. File Writing
Enables users or applications to modify or add new data to a file.
Data can be written sequentially (appending) or at a specific location (editing).
The OS ensures that file integrity is maintained during writing.
5. File Renaming
Allows users to change the file name while keeping its contents and attributes unchanged.
The OS updates the file system to reflect the new name without affecting stored data.
6. File Deletion
Removes a file permanently from the storage system.
The OS marks the space occupied by the file as free, making it available for new data.
Deleted files may sometimes be recovered if the space has not been overwritten.
7. File Copying and Moving
Copying: Creates a duplicate of the original file in a different location.
Moving: Transfers a file from one directory or storage device to another, updating the file path in the system.
8. File Appending
Adds new data to an existing file without altering previous contents.
Commonly used in log files and data recording applications.
9. File Closing
Once operations are completed, the OS closes the file to free system resources.
Closing a file ensures that data is saved properly and prevents accidental modifications.
10. File Security and Access Control
The OS enforces security mechanisms to restrict unauthorized file access.
Access permissions define which users can read, write, execute, or delete a file.
File Access Methods in Operating System.
Introduction.
File access methods define how data stored in a file can be read or modified.
The operating system (OS) provides different access methods to optimize data retrieval and storage efficiency.
The two primary file access methods are Sequential Access and Direct (Random) Access.
The choice of access method depends on the type of file and the application’s requirements.
1. Sequential Access
Definition
Sequential access is a method where data is read or written in a linear order, from the beginning to the end of the file. This method is commonly used in text files, log files, and tape storage.
Characteristics
Data is accessed sequentially, similar to reading a book page by page.
Slower compared to direct access, as each piece of data must be read in order.
Efficient for reading large amounts of data without frequent modifications.
Operations in Sequential Access
Read Next: Reads the next block of data from the file.
Write Next: Appends data to the end of the file.
Rewind: Moves the read/write pointer back to the beginning of the file.
Advantages of Sequential Access
✔ Simple to implement and efficient for batch processing.
✔ Suitable for applications that process data sequentially (e.g., logs, reports).
✔ Requires less memory and computational resources.
Disadvantages of Sequential Access
✖ Slow for random data retrieval, as the system must scan through unwanted data.
✖ Not ideal for databases or applications requiring frequent modifications.
2. Direct (Random) Access
Definition
Direct access allows data to be read or written at any position in the file without following a sequential order.
It is commonly used in databases, multimedia files, and modern storage systems like hard drives and SSDs.
Characteristics
Data can be accessed randomly, similar to jumping to a specific page in a book.
Uses file pointers to move directly to the required data location.
Faster than sequential access, as it does not require scanning through unnecessary data.
Operations in Direct Access
Read n: Reads data from a specific location (n) in the file.
Write n: Writes data at a specific location (n).
Seek n: Moves the file pointer to a specified location for reading or writing.
Advantages of Direct Access
✔ Faster data retrieval, making it ideal for databases and multimedia applications.
✔ Supports random searches and modifications without processing the entire file.
✔ Efficient for large files where quick access to specific data is needed.
Disadvantages of Direct Access
✖ More complex to implement compared to sequential access.
✖ Requires additional system resources and memory management.
Feature | Sequential Access | Direct Access |
---|---|---|
Data Retrieval | Linear (one by one) | Random (any location) |
Speed | Slower | Faster |
Implementation | Simple | Complex |
Use Case | Logs, reports, text files | Databases, multimedia, large data files |
Resource Usage | Low | High |
Modification | Difficult, requires rewriting | Easy, supports editing at any point |
Directory Systems and File Management Functions in Operating System.
Introduction.
A directory system is an essential part of an operating system (OS) that organizes, manages, and controls access to files stored on a computer.
It helps users and applications efficiently locate, retrieve, and manage files.
The OS provides various file management functions to ensure proper storage, security, and accessibility of data.
1. Directory Systems in File Management
A directory system is a structure that organizes files in a hierarchical manner, making it easier to store and retrieve data.
The main components of a directory system include:
a) Single-Level Directory
All files are stored in a single directory.
Simple but difficult to manage when multiple users store many files.
b) Two-Level Directory
Each user has their own directory for file storage.
Prevents file name conflicts between users.
c) Hierarchical (Tree) Directory
Organizes files in multiple levels (folders and subfolders).
Provides better organization and security for large storage systems.
d) Acyclic Graph Directory
Allows files to be shared among multiple directories.
Avoids duplication but requires additional management.
e) General Graph Directory
Allows complex file relationships but may lead to issues like circular references.
2. File Management Functions in an Operating System
1. File Creation and Naming
Allows users to create new files and assign unique names.
The OS maintains metadata such as creation date, file type, and permissions.
2. File Organization and Storage
The OS organizes files into directories and subdirectories for efficient access.
Uses indexing and allocation techniques to optimize storage.
3. File Access and Retrieval
Provides different file access methods like Sequential Access and Direct Access.
Supports file search operations to locate files quickly.
4. File Editing and Modification
Allows users to update and modify file contents.
Supports operations like copying, moving, renaming, and deleting files.
5. File Protection and Security
Implements access control mechanisms to restrict unauthorized file access.
Uses authentication, encryption, and permission settings (read, write, execute).
6. File Backup and Recovery
Provides backup mechanisms to prevent data loss due to system failure.
Supports file recovery tools to restore accidentally deleted or corrupted files.
7. Disk Space Management
Allocates and deallocates storage space efficiently.
Uses contiguous, linked, and indexed allocation methods to optimize disk usage.
8. File Sharing and Permissions
Allows multiple users to share files while maintaining security.
Supports file locking to prevent conflicts when multiple users access the same file.
File System and Directory Structure Organization in Operating System.
Introduction.
A file system is a fundamental component of an operating system (OS) that manages how data is stored, organized, retrieved, and accessed on storage devices.
It ensures data integrity, security, and efficient file management.
The directory structure organizes files and directories in a systematic way, making it easier for users and applications to locate and manage data.
1. File System Organization
A file system is responsible for structuring and maintaining data on storage devices such as hard drives, SSDs, USB drives, and memory cards.
It defines how files are stored and accessed by the OS and users.
Components of a File System
Files: The basic unit of data storage in an OS, consisting of user and system-generated data.
Directories: Containers that store and organize multiple files and subdirectories.
Metadata: Information about files, including size, permissions, creation date, and modification date.
Storage Allocation Methods: Defines how disk space is assigned to files (e.g., contiguous, linked, indexed).
File Access Methods: Determines how files are accessed (e.g., sequential or direct access).
Types of File Systems
FAT (File Allocation Table): Used in older Windows systems and USB drives.
NTFS (New Technology File System): Default for modern Windows OS, supports security and large files.
ext (Extended File System): Common in Linux systems (ext2, ext3, ext4).
HFS+ (Hierarchical File System): Used in macOS.
exFAT: Optimized for flash storage devices.
2. Directory Structure Organization
A directory structure organizes files and directories in a hierarchical manner, enabling efficient storage and retrieval of data.
It helps in managing large amounts of data by providing a structured path for files.
Types of Directory Structures
Single-Level Directory
All files are stored in a single directory.
Simple but difficult to manage when multiple users store many files.
Two-Level Directory
Each user has a separate directory for organizing files.
Prevents file name conflicts between different users.
Hierarchical (Tree) Directory
Files are organized into directories and subdirectories, forming a tree structure.
Provides better file organization and searchability.
Acyclic Graph Directory
Allows files to be shared among multiple directories.
Reduces duplication but requires careful management to avoid inconsistencies.
General Graph Directory
Similar to an acyclic graph but allows complex file relationships.
May lead to circular references, requiring additional management mechanisms.
Operations on Directories
Creating and Deleting Directories: Users can create and remove directories as needed.
Navigating Directory Paths: The OS allows movement between directories using relative or absolute paths.
Accessing and Managing Files: Directories provide a structured way to access, rename, move, or delete files.
File Sharing and Security: Implements permissions to control user access to files and directories.
File Protection in Operating System.
Introduction.
File protection is a crucial function of an operating system (OS) that ensures data security by preventing unauthorized access, modification, or deletion of files.
It safeguards files from accidental loss, malware, and unauthorized users, maintaining system integrity and confidentiality.
Effective file protection mechanisms help in enforcing access control and ensuring secure data sharing among multiple users.
1. Need for File Protection
File protection is essential for:
Preventing Unauthorized Access: Ensuring only authorized users can access specific files.
Maintaining Data Integrity: Protecting files from accidental or malicious modifications.
Ensuring Privacy: Restricting access to sensitive information.
Avoiding Data Loss: Preventing accidental deletion or corruption of files.
Supporting Multi-User Environments: Managing different access levels for multiple users.
2. File Protection Mechanisms
1. File Permissions and Access Control
Operating systems use permission-based access control to define which users can perform operations on a file.
Read (r): Allows users to view the file’s contents.
Write (w): Grants permission to modify or edit the file.
Execute (x): Enables users to run executable files or scripts.
No Access: Denies any interaction with the file.
Permissions can be set for different types of users:
Owner (User): The creator or owner of the file.
Group: A defined group of users with shared access rights.
Others (Public): All other users who are not the owner or part of the group.
Example (Linux File Permissions):
-rwxr--r-- owner group filename
rwx (Owner): Read, write, and execute.
r– (Group): Read-only access.
r– (Others): Read-only access.
2. Authentication and User Identification
Uses login credentials (username and password) to verify authorized users.
Advanced methods include biometric authentication and multi-factor authentication (MFA).
3. Access Control Lists (ACLs)
ACLs provide fine-grained control over file access by specifying individual user permissions.
They offer more flexibility than basic file permissions.
4. Encryption
Protects files by converting them into an unreadable format that requires a decryption key.
Common encryption methods include AES (Advanced Encryption Standard) and RSA (Rivest-Shamir-Adleman).
Ensures secure file storage and transmission.
5. File Backup and Recovery
Regular backups prevent data loss in case of accidental deletion or corruption.
Automated backup systems store copies of important files at scheduled intervals.
Recovery tools help restore lost or damaged files.
6. File Auditing and Monitoring
Tracks file access and modifications to detect unauthorized activities.
Logging systems record details such as who accessed the file, when, and what changes were made.
7. File Locking Mechanisms
Shared Lock: Multiple users can read a file simultaneously but cannot modify it.
Exclusive Lock: Only one user can access the file at a time to prevent conflicts.
Prevents issues like data inconsistency in multi-user environments.
3. Common Threats to File Security
Unauthorized Access: Hackers or unauthorized users accessing confidential files.
Malware and Viruses: Malicious programs corrupting or deleting files.
Accidental Deletion: Users mistakenly removing important files.
Data Corruption: System failures leading to unreadable or damaged files.
Insider Threats: Employees or internal users misusing file access privileges.
4. File Protection in Different Operating Systems
Windows OS
Uses NTFS (New Technology File System) for security and access control.
Supports user groups, permissions, and encryption (BitLocker).
Provides Windows Defender for malware protection.
Linux OS
Implements file permissions using the rwx (read, write, execute) system.
Uses Access Control Lists (ACLs) for detailed file security.
Supports SELinux (Security-Enhanced Linux) for advanced security.
MacOS
Uses HFS+ and APFS file systems with built-in encryption.
Provides FileVault encryption for securing user data.
Supports Unix-based permissions and ACLs for access control.
Â
Â