Recall What we have learnt till now
At its core, a file system is a structured method for storing, organizing, and accessing data on a storage medium such as a hard drive or solid-state drive. It provides a logical framework that enables users and software applications to interact with stored data efficiently. Think of it as the librarian of the digital world, meticulously cataloging and managing our files for easy retrieval.
[1] File
In simply, a file is a container for storing data in a structured format. It serves as a unit of organization, allowing us to store, retrieve, and manipulate information in a meaningful way. Whether it's a simple text document or a complex multimedia presentation.
Attribute of File
Files possess various attributes that provide information about their characteristics, status, and permissions. Understanding these attributes is essential for managing and interacting with files effectively:
1 File Name:
- The name given to the file, providing a unique identifier within its directory.
- Example: "document.txt", "image.jpg", "program.exe".
2. File Extension:
- The suffix appended to the file name, indicating its format or type.
- Example: ".txt" for text files, ".jpg" for image files, ".exe" for executable files.
3. File Size:
- The amount of storage space occupied by the file on the disk, usually measured in bytes, kilobytes, megabytes, or gigabytes.
4. File Type:
- The category or classification of the file based on its content and format.
- Example: Text file, image file, audio file, video file, executable file, etc.
5. File Location:
- The directory path or location within the file system where the file is stored.
- Example: "/home/user/documents/", "C:\Users\User\Documents", etc.
6. Creation Date:
- The date and time when the file was created or initialized.
7. Modification Date:
- The date and time when the file was last modified or updated.
8. Access Date:
- The date and time when the file was last accessed or opened.
9. File Owner:
- The user account or entity that owns the file and has certain privileges or permissions over it.
10. File Permissions:
- The access rights granted to users or groups regarding the file, typically categorized into read, write, and execute permissions.
- Example: Read permission allows viewing the file's content, write permission allows modifying the file, and execute permission allows running the file as a program.
11. File Attributes (On Windows):
- Additional properties associated with the file, such as read-only, hidden, archive, system, etc., which affect its behavior and visibility within the operating system.
12. File Checksum:
- A unique value calculated from the file's contents using a checksum algorithm, used for data integrity verification and error detection.
13. File Version (For Some Types of Files):
- The version or revision number of the file, indicating its iteration or update history.
[3] Types of Files
Files come in various types and formats, each tailored to specific purposes and applications:
- Text Files:
- Store data in human-readable text format, often used for documents, configuration files, and source code.
- Binary Files:
- Store data in a binary format, consisting of sequences of 0s and 1s. They can represent any type of information, from images and audio to executable programs.
- Compressed Files:
- Reduce file size by compressing data using algorithms like ZIP, RAR, or gzip, making them easier to store and transfer.
- Specialized Formats:
- Designed for specific applications or purposes, such as database files (e.g., SQLite, MySQL), multimedia files (e.g., MP3, JPEG), and document formats (e.g., PDF, DOCX).
[4] File Operations and Interactions
- Creating Files:
- Involves generating a new file and assigning it a name and extension.
- Reading Files:
- Accessing the content of a file to retrieve information or perform operations based on its data.
- Writing to Files:
- Modifying the content of a file by adding, updating, or deleting data within it.
- Deleting Files:
- Removing a file from the file system, freeing up storage space and resources.
File System Architecture
The architecture of a file system refers to its internal structure and organization, including the data structures, algorithms, and mechanisms used for storing, accessing, and managing files and directories on a storage medium. A well-designed file system architecture is essential for achieving efficient performance, reliability, and scalability.
The architecture of a file system refers to its internal structure: the way it organises, reads, writes, and manages stored data. The architecture includes elements like files, directories, indices, and other.
- The goal is to store data in a way that maintains both data integrity and ease of accessibility.
Layered File System:
A layered file system architecture is a design approach that organizes the components and functionalities of a file system into distinct layers, each responsible for specific tasks. This modular structure enhances modifiability, scalability, and maintainability by decoupling different aspects of file system functionality. Let's explore the layers typically found in a layered file system architecture:
1 Application Layer:
- The top most layer, at this layer, user-level applications interact with the file system through system calls, and library functions provided by the operating system.
- Responsible for providing high-level system interfaces and APIs for file manipulation operations such as open, read, write, close, etc.
- Handles files access requests from applications and translates them into lower-level operations.
- Example applications like: Text editors, media players, file managers, etc.
2 File System Interface Layer:
- Sits between the application layer and the file system implementation.
- Provides a standardized interface for interacting with various file system, abstracting away the differences between them.
- This layer provides a standardized interface for file system operations, abstracting away the differences between various file systems.
- Example interface: POSIX (Portable Operating System Interface) API, which defines a set of standard system calls for file manipulation (e.g., open, read, write, close).
3. Logical File System Layer:
- In this layer, the logical structure and organization of files and directories are defined, irrespective of the underlying storage medium.
- Example components:
- Virtual File System (VFS): Provides a common interface for interacting with different file system types. In Linux, the VFS layer defines generic operations that can be implemented by specific file system drivers.
- File System Metadata: Manages file attributes (permissions, timestamps), directory structures, and file allocation information.
4. File System Driver Layer:
- This layer interacts directly with the physical storage devices to perform disk I/O operations.
- Example components:
- Ext4 Driver: Implements the Ext4 file system driver, responsible for translating logical file system operations into disk read/write operations specific to the Ext4 file system format.
- Block I/O Layer: Manages data transfer between the file system driver and the underlying block devices (e.g., hard disk drives, solid-state drives).
5. Device Driver Layer:
- At the lowest layer, device drivers communicate directly with hardware devices, including storage controllers and disk drives.
- Example components:
- SATA Driver: Manages communication with Serial ATA (SATA) controllers, enabling data transfer between the operating system and SATA-connected storage devices.
- SCSI Driver: Handles communication with SCSI (Small Computer System Interface) devices, including SCSI disks and storage arrays.
2 Components of File System Architecture
2.1 Boot Block
- The Boot Block is the first sector of a storage device and contains the bootstrap code responsible for initiating the boot process of an operating system.
- It typically includes a bootloader program that loads the operating system kernel into memory and begins its execution.
+-----------------------+
| Bootloader |
| (Bootstrap Code) |
+-----------------------+
2.2. Superblock
- The Superblock is a critical data structure located at the beginning of a file system and contains metadata about the file system itself.
- It includes information such as the size of the file system, the block size, the total number of inodes and data blocks, and the location of important data structures like the inode table and block allocation tables.
+-----------------------+
| Superblock |
| (Metadata about |
| file system) |
+-----------------------+
2.3. Inode(Index node) Table
- The Inode Table is a data structure that stores metadata about individual files and directories in the file system.
- Each inode contains information such as the file size, permissions, ownership, timestamps, and pointers to the data blocks that store the file's actual data.
- The inode table maintains a list of all inodes in the file system.
+-----------------------+
| Inode 1 |
| Inode 2 |
| ... |
| Inode N |
+-----------------------+
2.4. Data Blocks
- Data Blocks are the smallest unit of storage in a file system and are used to store the actual data of files.
- Files are divided into one or more data blocks, with each block typically containing a fixed-size portion of the file's data.
- Data blocks are allocated dynamically as files grew in size, and their pointers are managed by the inode table.
+-----------------------+
| Data Block 1 |
| Data Block 2 |
| ... |
| Data Block N |
+-----------------------+
2.5. Directory Structure
- The Directory Structure organizes files and directories in a hierarchical manner, allowing users to navigate the file system and access files by their names.
- Directories contain entries that map filenames to inodes, enabling efficient lookup and traversal of the file system.
+-----------------------+
| Directory |
| / |
| +--- File 1 |
| +--- Directory 1 |
| +--- File 2 |
| ... |
+-----------------------+