file-truncation · shipping · also ftruncate, ftruncate(), truncate()

File truncation

File truncation changes a regular file to a specified byte length, discarding data beyond a shorter end or extending it when supported.

Length and position: Linux ftruncate operates through a writable descriptor without changing the file offset. An extended region reads as zero bytes; this does not imply physical allocation of every block. [1]

Mapped readers: POSIX.1-2017 specifies that shrinking a mapped file discards whole pages beyond the new end, and accessing those pages raises SIGBUS. This rule concerns whole pages, not the unused tail of a partial final page. [2]

Storage boundary: changing file size and synchronizing it are separate operations. File-size metadata is retrieval-critical for fdatasync. [3]

Relations

related
memory-mapped-file, fdatasync, open-file-description, sparse-file, msync

Advantages

Limitations

Citations

  1. Linux man-pages: truncate(2), regular-file length and offset (accessed 2026-10-17)
  2. POSIX.1-2017: ftruncate(), discarded mapped pages (accessed 2026-10-17)
  3. Linux man-pages: fsync(2), fdatasync and file-size metadata (accessed 2026-10-17)

Further reading

  1. Hesela: Memory-mapped files: visibility, size and synchronization (accessed 2026-10-17)
Sources & caveats

JSON: /data/terms/file-truncation.json