Module 6: File I/O & System Calls

Your code talking to the OS

Lessons

IDTitleDuration
6-1File Descriptors and the Unix I/O Model25 min
6-2Buffered I/O — stdio.h30 min
6-3errno and Error Handling20 min
6-4Parsing Binary Formats35 min
6-5stat, directories, and file metadata20 min

Project

| 6-proj | Project: xxd — Hex Dumper | 60 min |

Key Concepts

file-descriptors

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.