Module 6: File I/O & System Calls
Your code talking to the OS
Lessons
| ID | Title | Duration |
|---|---|---|
| 6-1 | File Descriptors and the Unix I/O Model | 25 min |
| 6-2 | Buffered I/O — stdio.h | 30 min |
| 6-3 | errno and Error Handling | 20 min |
| 6-4 | Parsing Binary Formats | 35 min |
| 6-5 | stat, directories, and file metadata | 20 min |
Project
| 6-proj | Project: xxd — Hex Dumper | 60 min |
Key Concepts
PDF Status
- PDF ch07 (File I/O and System Calls) — Complete (written 2026-04-08).
- Key Concepts: FILE* vs fd table, stdio functions, POSIX open/read/write/close, errno, O_ flags table, dup/dup2.
- Going Deeper: three I/O layers (stdio buffer → page cache → hardware) with fflush/fsync/O_DIRECT/O_SYNC table; syscall mechanics (syscall instruction, register ABI, context switch cost, vDSO); three-table file descriptor model (fd table → open file table → inode table) with fork/dup/O_CLOEXEC consequences; error handling discipline (EINTR retry loop, EAGAIN, partial write loop).
- Real-World Connection: SQLite src/os_unix.c — seekAndWrite EINTR retry with pwrite, unixWrite partial-write loop, SQLITE_FULL vs SQLITE_IOERR_WRITE distinction, why pwrite is used over lseek+write.
- Exercises 7.1–7.4 + fully annotated solutions + test files.
Notes
Initial ingest from raw/course/src/data/modules/m6.js. Expand with deeper analysis of lesson content, pedagogical notes, and cross-module connections.