Disk Structure - aryanjoshi0823/5143-Operating-System GitHub Wiki
Disk Structure in Operating Systems
The disk structure in an operating system refers to how data is physically and logically organized and managed on a storage device, such as a hard disk drive (HDD) or solid-state drive (SSD). The disk structure ensures efficient storage, retrieval, and management of data.
Figure - Moving-head disk mechanism.
1. Physical Structure of a Disk
A hard disk or similar storage device has a specific physical layout:
Components
- Platters: Circular disks made of metal or glass, coated with a magnetic material to store data.
- Tracks: Concentric circular paths on the platter's surface where data is recorded.
- Sectors: Small subdivisions of tracks. A sector is the smallest physical storage unit, typically 512 bytes or 4 KB.
- Cylinders: A vertical stack of tracks across all platters at the same radius.
- Read/Write Head: A mechanical arm that reads or writes data on the platter surface.
- Spindle: A motorized axis that spins the platters.
Data Addressing
Data on the disk is addressed using a CHS (Cylinder-Head-Sector) format or the more modern LBA (Logical Block Addressing).
2. Logical Structure of a Disk
The logical structure of a disk abstracts the physical layout into a usable format for the operating system. It includes:
Partitions
- A disk can be divided into partitions, each appearing as a separate logical drive.
- Common types:
- Primary Partition: Bootable and contains an OS or file system.
- Extended Partition: Can hold multiple logical drives.
- Logical Partition: A section within an extended partition.
File Systems
- The file system organizes and manages data within partitions. Examples include:
- NTFS (Windows), ext4 (Linux), HFS+ (Mac).
- Responsibilities:
- Managing files and directories.
- Tracking free and occupied disk space.
- Handling permissions and metadata.
Blocks
- Data is stored in fixed-sized blocks, typically 4 KB. Blocks are the smallest logical unit of storage.
3. Disk Management and Structures
The operating system relies on specific structures for managing the disk:
Master Boot Record (MBR):
- Located in the first sector of the disk.
- Contains:
- Partition table.
- Boot loader to start the operating system.
GUID Partition Table (GPT):
- A modern replacement for MBR, supporting larger disks and more partitions.
Disk Scheduling:
- Algorithms used by the OS to manage read/write requests efficiently:
- FCFS (First Come, First Served)
- SSTF (Shortest Seek Time First)
- SCAN (Elevator Algorithm)
- C-SCAN (Circular SCAN)
Inodes:
- Used in file systems like ext4 to store file metadata (e.g., size, location, permissions).
4. Disk Access Time
Disk performance is characterized by:
- Seek Time: Time taken by the read/write head to move to the desired track.
- Rotational Latency: Time for the platter to rotate to the desired sector.
- Transfer Time: Time to transfer data from the disk to memory.
5. RAID (Redundant Array of Independent Disks)
RAID combines multiple disks for performance and reliability:
- RAID 0: Striping (Performance)
- RAID 1: Mirroring (Reliability)
- RAID 5: Striping with Parity (Balanced)
6. Disk Caching
- A portion of memory is used to temporarily store frequently accessed data, reducing access times.