uutils/coreutils · error · io::Error

failed to write whole buffer

Error message

failed to write whole buffer

What it means

write_all_at() loops over seek_write calls at a given offset; if a call returns Ok(0) (zero bytes written) the loop would spin forever, so it raises WriteZero 'failed to write whole buffer'. This mirrors std's write_all semantics. It means the underlying Windows file could not accept any bytes at that offset.

Source

Thrown at src/uu/cp/src/platform/windows.rs:98

            Ok(n) => total += n,
            Err(e) if e.kind() == std::io::ErrorKind::Interrupted => {}
            Err(e) => return Err(e),
        }
    }
    Ok(total)
}

/// Write the whole `buf` to `file` at `offset`, looping over partial writes.
///
/// The Windows-only `seek_write` has no `write_all`-style counterpart (unlike
/// the Unix `write_all_at`), so dropped tails on partial writes are handled
/// here. The `Interrupted` arm mirrors std's own write loops, although Windows
/// file I/O does not produce it.
fn write_all_at(file: &File, mut buf: &[u8], mut offset: u64) -> std::io::Result<()> {
    while !buf.is_empty() {
        match file.seek_write(buf, offset) {
            Ok(0) => {
                return Err(std::io::Error::new(
                    std::io::ErrorKind::WriteZero,
                    "failed to write whole buffer",
                ));
            }
            Ok(n) => {
                buf = &buf[n..];
                offset += n as u64;
            }
            Err(e) if e.kind() == std::io::ErrorKind::Interrupted => {}
            Err(e) => return Err(e),
        }
    }
    Ok(())
}

/// Error from [`sparse_copy`], separating "the destination filesystem cannot
/// do sparse files" — which callers handle by falling back to a plain copy —
/// from real I/O failures.

View on GitHub (pinned to 325183372a)

Solutions

  1. Free disk space on the destination volume and retry the copy
  2. Retry the cp operation without --sparse (fall back to normal copy) to rule out sparse-write issues
  3. Check the destination is not locked by another process (antivirus, indexer, backup) and that the volume is writable
  4. If persistent, report with the Windows error/last-os-error from the io::Error chain

Example fix

null
Defensive patterns

Strategy: try-catch

Validate before calling

// before copying on Windows
let free: u64 = get_free_bytes(dest_volume);
if free < expected_size { return Err("insufficient disk space"); }

Type guard

null

Try / catch

match result {
    Err(e) if e.kind() == std::io::ErrorKind::WriteZero => {
        eprintln!("write failed at offset: {e}; check disk space/locks");
        // retry without sparse mode or free space first
    }
    other => other?,
}

Prevention

When it happens

Trigger: file.seek_write(buf, offset) returns Ok(0) while writing sparse file data in sparse_copy/sparse_copy_without_hole_fd, e.g., after the file handle becomes invalid, the volume is full, or an offset beyond a hard limit is used.

Common situations: Copying very large/sparse files on Windows with insufficient disk space; copying to a file on a network share or removable volume that fails mid-write; antivirus or backup software locking the destination file.

Related errors


AI-assisted analysis of uutils/coreutils@325183372a (2026-08-31). Data as JSON: /api/errors/9899e14ecbc180bd. Report an issue: GitHub.