sendfile · shipping

sendfile

sendfile is a Linux system call that transfers bytes between file descriptors within the kernel.

Success reports bytes transferred and can be shorter than requested. On zero-copy socket or pipe paths, source regions must remain unchanged until the receiver consumes them. Since Linux 5.12, a pipe output uses splice semantics. [1]

Closing the input descriptor does not mean queued data has been consumed. A file-to-pipe experiment demonstrates source mutation after return; it is not a TCP or durability test. [2]

On successful transfer, a non-NULL input offset advances the caller's offset variable, leaving the input file position unchanged; NULL uses and advances that position. A seekable output still advances its own position: sendfile has no separate destination-offset argument. [1] A duplicated descriptor shares the same open file description and cursor, not a private position. [3]

A caller-provided offset must remain writable for its output update. In a controlled Linux 6.8.0-147-generic experiment, failed offset copyback returned EFAULT after destination bytes and its cursor had already changed; repairing permissions and blindly retrying duplicated data. Unreadable-offset and zero-count controls also returned EFAULT without moving bytes, so the error alone does not identify progress. [4] [5]

Relations

related
splice, File descriptor, Atomic rename, Checksum, File offset, Open file description, copy_file_range

Limitations

  • An output opened with O_APPEND is rejected with EINVAL; an explicit input offset does not enable append-mode output. [1]

Citations

  1. Linux man-pages: sendfile(2), offsets, return counts, append-mode restriction and source lifetime (accessed 2026-11-09)
  2. Hesela: Zero-copy transfers do not freeze source bytes (accessed 2026-10-18)
  3. Linux man-pages: dup(2), shared open file descriptions and file offsets (accessed 2026-11-09)
  4. Hesela: native offset-copyback failures, observed bytes and unsafe retries (accessed 2026-11-09)
  5. Linux v6.8: transfer and caller-offset copyback (accessed 2026-11-09)

JSON: /data/terms/sendfile.json

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

Cite this page
Hesela team. sendfile. Hesela. 2026-11-09. https://hesela.dev/terms/sendfile/