SEEK_DATA / SEEK_HOLE
SEEK_DATA and SEEK_HOLE are seek modes that move a file cursor to the next reported data or hole location at or after a byte offset.
Classification: Reported data can contain zeros. A filesystem may report the entire file as data and its end as the only hole, so these queries do not measure physical allocation. [1]
EOF boundary: In the reviewed Linux v6.8 generic and iomap implementations, a starting offset at or beyond EOF fails with ENXIO for either mode. A hole query starting below EOF may return EOF; a data query fails with ENXIO if no reported data remains. Do not treat other errors as a completed scan. [2] [3]
Shared cursor: A successful seek changes the open file description's offset, including for descriptors created with dup(). pread() reads from an explicit position without moving that cursor, but does not freeze the file's contents. [4] [5]
Stable input: A multi-call walk needs a consistent source. Per-call locking does not provide a snapshot across a seek and a later read. Record filesystem behavior and account for short reads when consuming reported ranges. [6] [5]
Relations
- related
- Sparse file, File offset, End of file, Open file description, pread, FIEMAP, Unwritten extent
Advantages
- Supports sparse-aware copying without reading every reported hole.
Limitations
- Neither zero readback nor successful copying proves preservation of allocation or preallocation.
- Opening a separate descriptor avoids a shared cursor only when it creates a new open file description; it does not create a content snapshot.
Citations
- Linux man-pages: lseek(2), data/hole classification and return values
- Linux v6.8: generic_file_llseek_size, EOF equality and conservative classification
- Linux v6.8: iomap_seek_data and iomap_seek_hole endpoint handling
- Linux man-pages: dup(2), shared open file description and cursor
- Linux man-pages: pread(2), explicit offset and short reads
- Linux v6.8: ext4_llseek, per-call locking around data/hole queries
Further reading
- Hesela: source, tests and four-file EOF/cursor observation
- Hesela: sparse files, preallocation and thin-pool capacity
Sources & caveats
- Linux-scoped source review, including pinned v6.8 code; the current normative POSIX text was not inspected.
- The no-snapshot conclusion is an inference from per-operation locking, not a concurrent-writer experiment.
- The linked four-file observation records one host and filesystem; seek maps and allocated-block counts are not universal expected results.