{
  "slug": "sendfile",
  "term": "sendfile",
  "aliases": [],
  "definition": "sendfile is a Linux system call that transfers bytes between file descriptors within the kernel.",
  "note": "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. [sendfile]\n\nClosing 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. [hesela-lifetime]\n\nOn 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. [sendfile] A duplicated descriptor shares the same open file description and cursor, not a private position. [dup-cursors]\n\nA 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. [hesela-copyback] [linux-copyback]",
  "status": "shipping",
  "advantages": [],
  "limitations": [
    {
      "text": "An output opened with O_APPEND is rejected with EINVAL; an explicit input offset does not enable append-mode output.",
      "citationIds": [
        "sendfile"
      ]
    }
  ],
  "related": [
    "splice",
    "file-descriptor",
    "atomic-rename",
    "checksum",
    "file-offset",
    "open-file-description",
    "copy-file-range"
  ],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "citations": [
    {
      "id": "sendfile",
      "title": "Linux man-pages: sendfile(2), offsets, return counts, append-mode restriction and source lifetime",
      "url": "https://man7.org/linux/man-pages/man2/sendfile.2.html",
      "accessed": "2026-11-09"
    },
    {
      "id": "hesela-lifetime",
      "title": "Hesela: Zero-copy transfers do not freeze source bytes",
      "url": "https://hesela.com/analyses/zero-copy-source-lifetime/",
      "accessed": "2026-10-18"
    },
    {
      "id": "dup-cursors",
      "title": "Linux man-pages: dup(2), shared open file descriptions and file offsets",
      "url": "https://man7.org/linux/man-pages/man2/dup.2.html",
      "accessed": "2026-11-09"
    },
    {
      "id": "hesela-copyback",
      "title": "Hesela: native offset-copyback failures, observed bytes and unsafe retries",
      "url": "https://hesela.com/analyses/zero-copy-source-lifetime/#offset-copyback-failure",
      "accessed": "2026-11-09"
    },
    {
      "id": "linux-copyback",
      "title": "Linux v6.8: transfer and caller-offset copyback",
      "url": "https://github.com/torvalds/linux/blob/e8f897f4afef0031fe618a8e94127a0934896aba/fs/read_write.c",
      "accessed": "2026-11-09"
    }
  ],
  "updated": "2026-11-09"
}
