CSC 394 · Operating Systems
Our notes
2 min readFiles
A file is a named collection of related information on secondary storage. Attributes: name, type, size, location, owner, permissions, timestamps. Operations: create, open, read, write, seek, close, delete.
Access methods
- Sequential: read in order (tapes, logs).
- Direct (random): jump to any block (databases).
- Indexed: an index points to blocks.
Directory structures
Single-level (all files in one list) → two-level (one directory per user) → tree-structured (folders within folders, paths like /home/ada/notes.txt) → acyclic graph (shared files through links).
Allocation methods
| Method | How | Pros / cons |
|---|---|---|
| Contiguous | file occupies consecutive blocks | fast direct access; external fragmentation, hard to grow |
| Linked | each block points to the next | no fragmentation; slow direct access, pointer lost = data lost (FAT is a linked variant with the links in a table) |
| Indexed | an index block lists all the file's blocks | fast direct access; index overhead (UNIX inodes use direct, single, double and triple indirect pointers) |
Free-space management
Bit map (one bit per block: 1 free, 0 used), linked list of free blocks, grouping, counting.
I/O techniques
- Programmed I/O: CPU polls the device (busy waiting).
- Interrupt-driven I/O: device interrupts when ready.
- DMA (direct memory access): a DMA controller moves whole blocks between device and memory, interrupting once at the end; frees the CPU.
- Buffering, caching and spooling smooth out speed differences.
Disk access time
Seek time (moving the head to the track) + rotational latency (waiting for the sector to come round) + transfer time. Seek time is the largest, so disk scheduling tries to reduce head movement.
Disk scheduling (worked)
Requests (cylinders): 98, 183, 37, 122, 14, 124, 65, 67; head at 53; cylinders 0-199.
- FCFS: 53→98→183→37→122→14→124→65→67. Movement: 45 + 85 + 146 + 85 + 108 + 110 + 59 + 2 = 640 cylinders.
- SSTF (shortest seek time first): 53→65→67→37→14→98→122→124→183. Movement: 12 + 2 + 30 + 23 + 84 + 24 + 2 + 59 = 236. (May starve far requests.)
- SCAN (elevator), moving towards 0 first: 53→37→14→0, then up 65→67→98→122→124→183. Movement: 53 (down to 0) + 183 = 236.
- C-SCAN (one direction, then jump back), moving up: 53→65→67→98→122→124→183→199, jump to 0, →14→37. Movement: (199 − 53) + 199 + 37 = 146 + 199 + 37 = 382 (counting the return); gives more uniform waiting times.
- LOOK / C-LOOK: like SCAN / C-SCAN but turn at the last request instead of the disk edge. LOOK moving down first: 53→37→14, then 65→…→183: 39 + 169 = 208.
SSDs
Solid-state drives have no moving head, so seek-based scheduling matters little; the OS instead manages wear levelling and TRIM.
Exams usually ask: file attributes and operations; access methods; compare allocation methods; inodes; DMA; compute total head movement for FCFS, SSTF, SCAN, C-SCAN and LOOK.
Common mistake: in SCAN, stopping at the last request instead of going to the end of the disk (that is LOOK). Read the question for which one is meant.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
Read
-
Best pick OSTEP: Hard Disk Drives (and disk scheduling)
Free chapter PDF from the authors' site (151 KB).
(opens pages.cs.wisc.edu in a new tab)
-
OSTEP: Interlude: Files and Directories
Free chapter PDF from the authors' site (207 KB).
(opens pages.cs.wisc.edu in a new tab)
-
OSTEP: File System Implementation
Free chapter PDF from the authors' site (156 KB).
(opens pages.cs.wisc.edu in a new tab)
-
OSTEP: I/O Devices
Free chapter PDF from the authors' site (116 KB).
(opens pages.cs.wisc.edu in a new tab)
-
Introduction to Computer Science, 6.5 File Systems
(opens openstax.org in a new tab)
OpenStax, Introduction to Computer Science, 6.5 File Systems, CC BY-NC-SA 4.0 · licence
-
I/O scheduling
(opens en.wikipedia.org in a new tab)
Wikipedia, I/O scheduling, CC BY-SA 4.0 · licence
Watch
We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.