Skip to content

Direct I/O file system flag not supported #4462

@nazar-pc

Description

@nazar-pc

I was testing my direct/unbuffered/unchached I/O abstractions with isolation disabled and it turned out that the file file opening flag for direct I/O is not supported:

error: unsupported operation: unsupported flags 0x4000
    --> /home/nazar-pc/.rustup/toolchains/nightly-2025-07-10-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/fs/unix.rs:1185:36
     |
1185 |         let fd = cvt_r(|| unsafe { open64(path.as_ptr(), flags, opts.mode as c_int) })?;
     |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsupported operation occurred here

The usage was:

#[cfg(target_os = "linux")]
{
    use std::os::unix::fs::OpenOptionsExt;

    options.custom_flags(libc::O_DIRECT);
}
#[cfg(windows)]
{
    use std::os::windows::fs::OpenOptionsExt;

    options.custom_flags(
        windows::Win32::Storage::FileSystem::FILE_FLAG_WRITE_THROUGH.0
            | windows::Win32::Storage::FileSystem::FILE_FLAG_NO_BUFFERING.0,
    );
}
let file = options.open(path)?;

#[cfg(target_os = "macos")]
{
    use std::os::unix::io::AsRawFd;

    if unsafe { libc::fcntl(file.as_raw_fd(), libc::F_NOCACHE, 1) } != 0 {
        return Err(io::Error::last_os_error());
    }
}

It'd be very nice for all of these to be supported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-filesArea: related to files, paths, sockets, file descriptors, or handlesC-enhancementCategory: a PR with an enhancement or an issue tracking an accepted enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions