OSOperating Systems · Lesson 5 of 7
Files, Descriptors & Filesystems
Unix's boldest simplification: everything is a file. Documents, your terminal, network sockets, even random numbers — all read and written through the same tiny interface.
A filesystem maps names to data: directories are lists of name-to-inode entries, and an inode holds a file's metadata (size, owner, permissions, timestamps) plus pointers to its data blocks on disk. The filename is not the file — several names can point to one inode (hard links), and a file deleted while open lives on until the last descriptor closes.
✦ Tip
Writes are buffered at multiple layers — your language's library, then the kernel's page cache. 'Saved' data may sit in RAM for seconds before reaching disk; that's what fsync() and safe-save patterns (write temp file, fsync, rename) are for. Databases obsess over this — now you know why.
Writes are buffered at multiple layers — your language's library, then the kernel's page cache. 'Saved' data may sit in RAM for seconds before reaching disk; that's what fsync() and safe-save patterns (write temp file, fsync, rename) are for. Databases obsess over this — now you know why.