Operating Systems · File System Structure
Introduction to File Systems and Blocks
Overview
The file system is the most important part of the operating system: without it, accessing information stored in the computer is very difficult.
It hides the physical layout of the hard disk behind an abstract data structure called a file, so the user supplies a logical file and the operating system stores it physically on the disk.
Key concepts
- File: an abstract data structure provided by the operating system that hides the details of how the hard disk is actually structured. It has attributes, just like a data structure.
- Everything is a file: to the operating system, a video, an executable file, a text file, or even a collection of database records is a file.
- Directory: a collection of logically related files.
- File system: a collection of logically related directories. It can be viewed as the software that manages and creates directories, which contain files, which contain information.
- Block: the smallest information unit accessed on a hard disk or any storage device — a small unit or chunk of memory accessed all at once, either for reading or for writing.
- Logical-to-physical mapping: a file is divided into logical blocks, which are mapped onto physical blocks on the disk.
- Segmented paging (memory management unit): uses two tables, a segment table and a page table, to convert a logical address into a physical address.
How it works
- Information is saved to the hard disk because main memory is volatile: if the computer is switched off, the contents of main memory do not last. Information is therefore stored on the hard disk and fetched later when needed.
- The hard disk is organized very differently from the way a file is logically organized.
A video may be 4 MB, but the hard disk may not have a continuous 4 MB region available for it, so the information must be divided into parts called blocks, and the logical blocks must be mapped onto physical blocks. - A file may need many blocks — a video file may need 10 blocks — and it may not be possible to find all of them contiguously.
Even if contiguous blocks are found, fetching the file manually would be tedious without operating system support. - The operating system abstracts away the details of how the hard disk is structured and provides the abstract data structure called a file.
The user gives the operating system a logical file, and the operating system stores it physically on the hard disk. - The entire code required to create a file, store a file, fetch a file, and perform related actions is part of the file system in the operating system.
Everything saved on the computer is saved as a file; logically related information is collected into a file (for example, all employee records of a company can be collected into a file). - A computer contains a very large number of files. To manage so many files, logically related files are grouped into a directory, and logically related directories are grouped into a file system.
- The file system performs various operations and provides the executable code needed to perform those actions. The logical view of the file is considered first; the physical storage of the file on the hard disk is considered later.
Worked examples
- 4 MB video file: the hard disk may not have a contiguous 4 MB region. The video is divided into parts called blocks, and the logical blocks are mapped onto physical blocks on the disk.
- File needing 10 blocks: the file requires 10 blocks on the hard disk, and all 10 blocks may not be available contiguously.
The operating system tracks the mapping and retrieves the file, while the user still sees one logical file.
Revision summary
- Main memory is volatile; the hard disk is used for persistent storage.
- A block is the smallest unit accessed on a storage device for reading or writing.
- A file is divided into logical blocks that are mapped onto physical blocks.
- The operating system hides the physical layout of the hard disk and provides the file abstraction.
- To the operating system, everything is a file: video, executable, text, or database records.
- Logically related information is collected into a file; logically related files are grouped into a directory; logically related directories are grouped into a file system.
- The file system contains the code for creating, storing, fetching, and operating on files.
- A file is an abstract data structure with attributes.
Previous-year exam insights
- Space used by a file on disk = (number of blocks allocated) × (block size + per-block bookkeeping overhead), where number of blocks = ceil(file size / block size);
internal fragmentation is the unused space in the last block.
Asked inGATE 2005 - Larger block size increases disk throughput (fewer I/O operations, less seek/overhead per byte) but decreases disk space utilization (more internal fragmentation and more wasted space per file).
Asked inGATE 2003ISRO 2009 - A block is the unit of disk allocation and transfer; a file's logical blocks are mapped to physical disk blocks, and the last block of a file is usually only partially filled.
- Per-block bookkeeping/metadata (e.g., pointers, block headers) is charged for every allocated block, including the partially filled last block, so overhead grows with the number of blocks.
Asked inGATE 2005