Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/driver/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ impl Op<Open> {
pub(crate) fn open(path: &Path, options: &OpenOptions) -> io::Result<Op<Open>> {
use io_uring::{opcode, types};
let path = driver::util::cstr(path)?;
let flags = libc::O_CLOEXEC | options.access_mode()? | options.creation_mode()?;
let flags = libc::O_CLOEXEC
| options.access_mode()?
| options.creation_mode()?
| (options.custom_flags & !libc::O_ACCMODE);

Op::submit_with(Open { path, flags }, |open| {
// Get a reference to the memory. The string will be held by the
Expand Down
15 changes: 15 additions & 0 deletions src/fs/open_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::driver::Op;
use crate::fs::File;

use std::io;
use std::os::unix::fs::OpenOptionsExt;
use std::path::Path;

/// Options and flags which can be used to configure how a file is opened.
Expand Down Expand Up @@ -62,6 +63,7 @@ pub struct OpenOptions {
create: bool,
create_new: bool,
pub(crate) mode: libc::mode_t,
pub(crate) custom_flags: libc::c_int,
}

impl OpenOptions {
Expand Down Expand Up @@ -94,6 +96,7 @@ impl OpenOptions {
create: false,
create_new: false,
mode: 0o666,
custom_flags: 0,
}
}

Expand Down Expand Up @@ -374,3 +377,15 @@ impl Default for OpenOptions {
Self::new()
}
}

impl OpenOptionsExt for OpenOptions {
fn mode(&mut self, mode: u32) -> &mut OpenOptions {
self.mode = mode;
self
}

fn custom_flags(&mut self, flags: i32) -> &mut OpenOptions {
self.custom_flags = flags;
self
}
}