Skip to content

Support for renameat2? #406

Description

@korrat

On Linux, cap-std implements Dir::rename via rustix::fs::renameat, which is the renameat function.

Since Linux 3.15, there is another version of this call, renameat2, which supports an additional flags argument. rustix already supports this function as rustix::fs::renameat_with.

Could cap-std add support for this function as well?

Additional Context

The external cap-std-ext crate implements atomic writes by writing a temporary file and renaming it in place. However, it is not possible to atomically create a file in this way.

renameat2 supports the RENAME_NOREPLACE flag, which ensures that no existing file is overwritten by the rename. As such, an atomic_create could be implemented based on this change.

Activity

  1. joshuamegnauth54 commented on Jun 21, 2026

    @joshuamegnauth54

    Coincidentally, FreeBSD recently implemented renameat2 too. I implemented RENAME_NO_REPLACE for Redox a while ago and libc exports its renameat2 as well.

    I think rustix needs to relax its feature gates for FreeBSD and Redox, but this could be a useful addition for Linux, FreeBSD, and Redox to help avoid TOCTOU.

  2. added 3 commits that reference this issue on Jul 4, 2026
    611c65f
    8f5cd6f
    4ffd9ff
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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions