Skip to content

Support positional vectored IO for unix files #71055

Open

Description

@vimpunk

Next to the existing write_vectored and read_vectored APIs, it would be great to have write_vectored_at and read_vectored_at methods for Files on UNIX systems, corresponding to the pwritev and preadv syscalls. This would be an easy way to add means for high performance file IO using the standard library File type.

As far as I understand, the equivalent does not exist on Windows, so this would probably have to live in the unix FileExt trait.

If this is deemed desirable, I'd be happy to send a PR for this.

Activity

  1. retep998 commented on Apr 12, 2020

    @retep998
    Contributor

    Windows actually does not support vectored reads and writes for anything other than sockets, so write_vectored and read_vectored for files just defaults to doing a single read/write of the first buffer. Windows does support reading and writing at a specific position, so I see no reason why read_vectored_at and write_vectored_at cannot be implemented in a similar fashion, where it does a simple read_at or write_at of the first buffer.

  2. vimpunk commented on Apr 15, 2020

    @vimpunk
    Author

    @retep998 Thanks for the clarification. In that case this could indeed be implemented for Windows as well.

    I suppose the next step would be an RFC?

  3. alecmocatta commented on Apr 16, 2020

    @alecmocatta
    Contributor

    Positional reading/writing on Windows has the unfortunate effect of modifying the file offset cursor. IIRC the positioned-io crate has either of two workarounds: storing the cursor explicitly, or using a temporary memory mapping to read data rather than FileExt::seek_read.

  4. superobertking commented on Apr 26, 2020

    @superobertking

    Citing from Linux man page, preadv and pwritev are "nonstandard, but present also on the modern BSDs". In fact, not all unix support preadv and pwritev - macOS does not yet.

    Further, "preadv and pwritev first appeared in Linux 2.6.30 and library support was added in glibc 2.10", while the Rust platform support requires the minimal Linux version of 2.6.18. This would break backward compatibility support.

    For non-POSIX standard API, it's better to reside in an external crate rather than in the std as suggested (in somewhere else I cannot find now). Libc already provides this syscall function, and nix provides a pretty wrapper function around it. I guess we could have a FileExt-like trait in some crate and implement it for the std File.

  5. artob commented on Oct 10, 2023

    @artob

    This was implemented in #89518, feature gated by #![feature(unix_file_vectored_at)] (#89517).

  6. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions