Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions compio-driver/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pub use crate::sys::op::{
pub use crate::sys::op::{ConnectNamedPipe, DeviceIoControl};
#[cfg(unix)]
pub use crate::sys::op::{
CreateDir, CreateSocket, FileStat, HardLink, Interest, OpenFile, PathStat, PollOnce,
ReadVectored, ReadVectoredAt, Rename, Stat, Symlink, TruncateFile, Unlink, WriteVectored,
WriteVectoredAt,
CreateDir, CreateSocket, CurrentDir, FileStat, HardLink, Interest, OpenFile, PathStat,
PollOnce, ReadVectored, ReadVectoredAt, Rename, Stat, Symlink, TruncateFile, Unlink,
WriteVectored, WriteVectoredAt,
};
#[cfg(io_uring)]
pub use crate::sys::op::{ReadManaged, ReadManagedAt, RecvManaged};
Expand Down
2 changes: 1 addition & 1 deletion compio-driver/src/sys/fusion/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ op!(<T: IoBuf, S: AsFd> SendTo(fd: S, buffer: T, addr: SockAddr, flags: i32));
op!(<T: IoVectoredBufMut, S: AsFd> RecvFromVectored(fd: S, buffer: T, flags: i32));
op!(<T: IoVectoredBuf, S: AsFd> SendToVectored(fd: S, buffer: T, addr: SockAddr, flags: i32));
op!(<S: AsFd> FileStat(fd: S));
op!(<> PathStat(path: CString, follow_symlink: bool));
op!(<S: AsFd> PathStat(dirfd: S, path: CString, follow_symlink: bool));

macro_rules! mop {
(<$($ty:ident: $trait:ident),* $(,)?> $name:ident( $($arg:ident: $arg_t:ty),* $(,)? ) with $pool:ident) => {
Expand Down
92 changes: 52 additions & 40 deletions compio-driver/src/sys/iour/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ unsafe impl<
}
}

unsafe impl OpCode for OpenFile {
unsafe impl<S: AsFd> OpCode for OpenFile<S> {
fn create_entry(self: Pin<&mut Self>) -> OpEntry {
opcode::OpenAt::new(Fd(libc::AT_FDCWD), self.path.as_ptr())
opcode::OpenAt::new(Fd(self.dirfd.as_fd().as_raw_fd()), self.path.as_ptr())
.flags(self.flags | libc::O_CLOEXEC)
.mode(self.mode)
.build()
Expand Down Expand Up @@ -164,34 +164,39 @@ impl<S> IntoInner for FileStat<S> {
}
}

/// Get metadata from path.
pub struct PathStat {
pub(crate) path: CString,
pub(crate) stat: Statx,
pub(crate) follow_symlink: bool,
pin_project! {
/// Get metadata from path.
pub struct PathStat<S: AsFd> {
pub(crate) dirfd: S,
pub(crate) path: CString,
pub(crate) stat: Statx,
pub(crate) follow_symlink: bool,
}
}

impl PathStat {
impl<S: AsFd> PathStat<S> {
/// Create [`PathStat`].
pub fn new(path: CString, follow_symlink: bool) -> Self {
pub fn new(dirfd: S, path: CString, follow_symlink: bool) -> Self {
Self {
dirfd,
path,
stat: unsafe { std::mem::zeroed() },
follow_symlink,
}
}
}

unsafe impl OpCode for PathStat {
fn create_entry(mut self: Pin<&mut Self>) -> OpEntry {
unsafe impl<S: AsFd> OpCode for PathStat<S> {
fn create_entry(self: Pin<&mut Self>) -> OpEntry {
let this = self.project();
let mut flags = libc::AT_EMPTY_PATH;
if !self.follow_symlink {
if !*this.follow_symlink {
flags |= libc::AT_SYMLINK_NOFOLLOW;
}
opcode::Statx::new(
Fd(libc::AT_FDCWD),
self.path.as_ptr(),
std::ptr::addr_of_mut!(self.stat).cast(),
Fd(this.dirfd.as_fd().as_raw_fd()),
this.path.as_ptr(),
this.stat as *mut _ as _,
)
.flags(flags)
.mask(statx_mask())
Expand All @@ -200,35 +205,42 @@ unsafe impl OpCode for PathStat {
}

#[cfg(gnulinux)]
fn call_blocking(mut self: Pin<&mut Self>) -> io::Result<usize> {
fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
let this = self.project();
let mut flags = libc::AT_EMPTY_PATH;
if !self.follow_symlink {
if !*this.follow_symlink {
flags |= libc::AT_SYMLINK_NOFOLLOW;
}
let res = syscall!(libc::statx(
libc::AT_FDCWD,
self.path.as_ptr(),
this.dirfd.as_fd().as_raw_fd(),
this.path.as_ptr(),
flags,
statx_mask(),
std::ptr::addr_of_mut!(self.stat).cast()
this.stat
))?;
Ok(res as _)
}

#[cfg(not(gnulinux))]
fn call_blocking(mut self: Pin<&mut Self>) -> io::Result<usize> {
fn call_blocking(self: Pin<&mut Self>) -> io::Result<usize> {
let this = self.project();
let mut flags = libc::AT_EMPTY_PATH;
if !*this.follow_symlink {
flags |= libc::AT_SYMLINK_NOFOLLOW;
}
let mut stat = unsafe { std::mem::zeroed() };
let res = if self.follow_symlink {
syscall!(libc::stat(self.path.as_ptr(), &mut stat))?
} else {
syscall!(libc::lstat(self.path.as_ptr(), &mut stat))?
};
self.stat = stat_to_statx(stat);
let res = syscall!(libc::fstatat(
this.dirfd.as_fd().as_raw_fd(),
this.path.as_ptr(),
&mut stat,
flags
))?;
*this.stat = stat_to_statx(stat);
Ok(res as _)
}
}

impl IntoInner for PathStat {
impl<S: AsFd> IntoInner for PathStat<S> {
type Inner = Stat;

fn into_inner(self) -> Self::Inner {
Expand Down Expand Up @@ -364,9 +376,9 @@ unsafe impl<S: AsFd> OpCode for Sync<S> {
}
}

unsafe impl OpCode for Unlink {
unsafe impl<S: AsFd> OpCode for Unlink<S> {
fn create_entry(self: Pin<&mut Self>) -> OpEntry {
opcode::UnlinkAt::new(Fd(libc::AT_FDCWD), self.path.as_ptr())
opcode::UnlinkAt::new(Fd(self.dirfd.as_fd().as_raw_fd()), self.path.as_ptr())
.flags(if self.dir { libc::AT_REMOVEDIR } else { 0 })
.build()
.into()
Expand All @@ -377,9 +389,9 @@ unsafe impl OpCode for Unlink {
}
}

unsafe impl OpCode for CreateDir {
unsafe impl<S: AsFd> OpCode for CreateDir<S> {
fn create_entry(self: Pin<&mut Self>) -> OpEntry {
opcode::MkDirAt::new(Fd(libc::AT_FDCWD), self.path.as_ptr())
opcode::MkDirAt::new(Fd(self.dirfd.as_fd().as_raw_fd()), self.path.as_ptr())
.mode(self.mode)
.build()
.into()
Expand All @@ -390,12 +402,12 @@ unsafe impl OpCode for CreateDir {
}
}

unsafe impl OpCode for Rename {
unsafe impl<S1: AsFd, S2: AsFd> OpCode for Rename<S1, S2> {
fn create_entry(self: Pin<&mut Self>) -> OpEntry {
opcode::RenameAt::new(
Fd(libc::AT_FDCWD),
Fd(self.old_dirfd.as_fd().as_raw_fd()),
self.old_path.as_ptr(),
Fd(libc::AT_FDCWD),
Fd(self.new_dirfd.as_fd().as_raw_fd()),
self.new_path.as_ptr(),
)
.build()
Expand All @@ -407,10 +419,10 @@ unsafe impl OpCode for Rename {
}
}

unsafe impl OpCode for Symlink {
unsafe impl<S: AsFd> OpCode for Symlink<S> {
fn create_entry(self: Pin<&mut Self>) -> OpEntry {
opcode::SymlinkAt::new(
Fd(libc::AT_FDCWD),
Fd(self.dirfd.as_fd().as_raw_fd()),
self.source.as_ptr(),
self.target.as_ptr(),
)
Expand All @@ -423,12 +435,12 @@ unsafe impl OpCode for Symlink {
}
}

unsafe impl OpCode for HardLink {
unsafe impl<S1: AsFd, S2: AsFd> OpCode for HardLink<S1, S2> {
fn create_entry(self: Pin<&mut Self>) -> OpEntry {
opcode::LinkAt::new(
Fd(libc::AT_FDCWD),
Fd(self.source_dirfd.as_fd().as_raw_fd()),
self.source.as_ptr(),
Fd(libc::AT_FDCWD),
Fd(self.target_dirfd.as_fd().as_raw_fd()),
self.target.as_ptr(),
)
.build()
Expand Down
74 changes: 39 additions & 35 deletions compio-driver/src/sys/poll/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ unsafe impl<
}
}

unsafe impl OpCode for OpenFile {
unsafe impl<S: AsFd> OpCode for OpenFile<S> {
fn pre_submit(self: Pin<&mut Self>) -> io::Result<Decision> {
Ok(Decision::Blocking)
}
Expand Down Expand Up @@ -150,60 +150,64 @@ impl<S> IntoInner for FileStat<S> {
}
}

/// Get metadata from path.
pub struct PathStat {
pub(crate) path: CString,
pub(crate) stat: Stat,
pub(crate) follow_symlink: bool,
pin_project! {
/// Get metadata from path.
pub struct PathStat<S: AsFd> {
pub(crate) dirfd: S,
pub(crate) path: CString,
pub(crate) stat: Stat,
pub(crate) follow_symlink: bool,
}
}

impl PathStat {
impl<S: AsFd> PathStat<S> {
/// Create [`PathStat`].
pub fn new(path: CString, follow_symlink: bool) -> Self {
pub fn new(dirfd: S, path: CString, follow_symlink: bool) -> Self {
Self {
dirfd,
path,
stat: unsafe { std::mem::zeroed() },
follow_symlink,
}
}
}

unsafe impl OpCode for PathStat {
unsafe impl<S: AsFd> OpCode for PathStat<S> {
fn pre_submit(self: Pin<&mut Self>) -> io::Result<Decision> {
Ok(Decision::Blocking)
}

fn operate(mut self: Pin<&mut Self>) -> Poll<io::Result<usize>> {
fn operate(self: Pin<&mut Self>) -> Poll<io::Result<usize>> {
let this = self.project();
let mut flags = libc::AT_EMPTY_PATH;
Comment thread
Berrysoft marked this conversation as resolved.
Outdated
if !*this.follow_symlink {
flags |= libc::AT_SYMLINK_NOFOLLOW;
}
#[cfg(gnulinux)]
{
let mut flags = libc::AT_EMPTY_PATH;
if !self.follow_symlink {
flags |= libc::AT_SYMLINK_NOFOLLOW;
}
let res = {
let mut s: libc::statx = unsafe { std::mem::zeroed() };
syscall!(libc::statx(
libc::AT_FDCWD,
self.path.as_ptr(),
let res = syscall!(libc::statx(
this.dirfd.as_fd().as_raw_fd(),
this.path.as_ptr(),
flags,
statx_mask(),
&mut s
))?;
self.stat = statx_to_stat(s);
Poll::Ready(Ok(0))
}
*this.stat = statx_to_stat(s);
res
};
#[cfg(not(gnulinux))]
{
let f = if self.follow_symlink {
libc::stat
} else {
libc::lstat
};
Poll::Ready(Ok(syscall!(f(self.path.as_ptr(), &mut self.stat))? as _))
}
let res = syscall!(libc::fstatat(
this.dirfd.as_fd().as_raw_fd(),
this.path.as_ptr(),
this.stat,
flags
))?;
Poll::Ready(Ok(res as _))
}
}

impl IntoInner for PathStat {
impl<S: AsFd> IntoInner for PathStat<S> {
type Inner = Stat;

fn into_inner(self) -> Self::Inner {
Expand Down Expand Up @@ -518,7 +522,7 @@ unsafe impl<S: AsFd> OpCode for Sync<S> {
}
}

unsafe impl OpCode for Unlink {
unsafe impl<S: AsFd> OpCode for Unlink<S> {
fn pre_submit(self: Pin<&mut Self>) -> io::Result<Decision> {
Ok(Decision::Blocking)
}
Expand All @@ -528,7 +532,7 @@ unsafe impl OpCode for Unlink {
}
}

unsafe impl OpCode for CreateDir {
unsafe impl<S: AsFd> OpCode for CreateDir<S> {
fn pre_submit(self: Pin<&mut Self>) -> io::Result<Decision> {
Ok(Decision::Blocking)
}
Expand All @@ -538,7 +542,7 @@ unsafe impl OpCode for CreateDir {
}
}

unsafe impl OpCode for Rename {
unsafe impl<S1: AsFd, S2: AsFd> OpCode for Rename<S1, S2> {
fn pre_submit(self: Pin<&mut Self>) -> io::Result<Decision> {
Ok(Decision::Blocking)
}
Expand All @@ -548,7 +552,7 @@ unsafe impl OpCode for Rename {
}
}

unsafe impl OpCode for Symlink {
unsafe impl<S: AsFd> OpCode for Symlink<S> {
fn pre_submit(self: Pin<&mut Self>) -> io::Result<Decision> {
Ok(Decision::Blocking)
}
Expand All @@ -558,7 +562,7 @@ unsafe impl OpCode for Symlink {
}
}

unsafe impl OpCode for HardLink {
unsafe impl<S1: AsFd, S2: AsFd> OpCode for HardLink<S1, S2> {
fn pre_submit(self: Pin<&mut Self>) -> io::Result<Decision> {
Ok(Decision::Blocking)
}
Expand Down
Loading
Loading