1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use std::{ffi::CString, os::fd::FromRawFd};
use crate::api::resource::Resource;
use crate::typed_op::TypedOp;
pub struct OpenAt {
dir_res: Resource,
pathname: CString,
flags: i32,
}
assert_op_max_size!(OpenAt);
impl OpenAt {
pub(crate) fn new(dir_res: Resource, pathname: CString, flags: i32) -> Self {
Self { dir_res, pathname, flags }
}
pub fn to_op(self) -> crate::op::Op {
crate::op::Op::OpenAt {
dir_fd: self.dir_res,
path: self.pathname.as_ptr(),
flags: self.flags,
}
}
}
impl TypedOp for OpenAt {
type Result = std::io::Result<Resource>;
fn into_op(&mut self) -> crate::op::Op {
crate::op::Op::OpenAt {
dir_fd: self.dir_res.clone(),
path: self.pathname.as_ptr(),
flags: self.flags,
}
}
fn extract_result(self, res: isize) -> Self::Result {
if res < 0 {
Err(std::io::Error::from_raw_os_error((-res) as i32))
} else {
// SAFETY: 'res' is valid fd.
Ok(unsafe { Resource::from_raw_fd(res as i32) })
}
}
// #[cfg(unix)]
// fn meta(&self) -> crate::operation::OpMeta {
// crate::operation::OpMeta::CAP_FD
// }
// #[cfg(unix)]
// fn cap(&self) -> i32 {
// self.dir_res.as_raw_fd()
// }
// #[cfg(linux)]
// fn create_entry(&self) -> lio_uring::submission::Entry {
// lio_uring::operation::OpenAt::new(
// self.dir_res.as_raw_fd(),
// self.pathname.as_ptr(),
// )
// .flags(self.flags)
// .build()
// }
// fn run_blocking(&self) -> isize {
// syscall!(raw openat(
// self.dir_res.as_raw_fd(),
// self.pathname.as_ptr(),
// self.flags
// ))
// }
}