Core · Module 5 · Lesson 4 of 12
File Offsets, Sparse Files, and lseek
Manipulate file offsets with lseek, understand sparse files and unallocated disk holes, and navigate non-seekable streams.
Pro — members onlyAbout 15 minutes
By the end you can
- Reposition read and write file offsets using SEEK_SET, SEEK_CUR, and SEEK_END
- Inspect current file positions and file sizes without transferring payload data
- Construct sparse files with filesystem holes and analyze logical versus physical disk usage
- Detect non-seekable descriptors like pipes and sockets via ESPIPE
Builds on Unbuffered I/O: read, write, and Partial Transfers.
01 · A question first
How can a C program create a 10-terabyte file in two milliseconds on a 500-gigabyte SSD without running out of disk space? The secret lies in how the kernel coordinates file offsets with sparse filesystem allocations.
Make a guess before you read on.
02 · The idea
Members only
Unlock the full lesson
This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.
What's inside
- Start with the problem
- How the idea works
- Why it is correct
- What it costs
- Pitfalls and variations
- Where it is used
03 · Practice
Asked in interviews
Something wrong with this lesson? Report a problem