Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use linux-raw-sys for statx type definitions and fix compatibility with musl #322

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ keywords = ["async", "fs", "io-uring"]
tokio = { version = "1.2", features = ["net", "rt", "sync"] }
slab = "0.4.2"
libc = "0.2.80"
linux-raw-sys = "0.6"
io-uring = "0.6.0"
socket2 = { version = "0.4.4", features = ["all"] }
bytes = { version = "1.0", optional = true }
Expand Down
6 changes: 5 additions & 1 deletion src/fs/create_dir_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ mod fs_imp {
// Uses one asynchronous uring call to determine this.
async fn is_dir<P: AsRef<Path>>(path: P) -> bool {
let mut builder = crate::fs::StatxBuilder::new();
if builder.mask(libc::STATX_TYPE).pathname(path).is_err() {
if builder
.mask(linux_raw_sys::general::STATX_TYPE)
.pathname(path)
.is_err()
{
return false;
}

Expand Down
18 changes: 11 additions & 7 deletions src/fs/statx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ impl File {
/// f.close().await.unwrap();
/// })
/// ```
pub async fn statx(&self) -> io::Result<libc::statx> {
pub async fn statx(&self) -> io::Result<linux_raw_sys::general::statx> {
let flags = libc::AT_EMPTY_PATH;
let mask = libc::STATX_ALL;
let mask = linux_raw_sys::general::STATX_ALL;
Op::statx(Some(self.fd.clone()), None, flags, mask)?.await
}

Expand Down Expand Up @@ -73,7 +73,7 @@ impl File {
file: Some(self.fd.clone()),
path: None,
flags: libc::AT_EMPTY_PATH,
mask: libc::STATX_ALL,
mask: linux_raw_sys::general::STATX_ALL,
}
}
}
Expand Down Expand Up @@ -102,7 +102,7 @@ impl File {
/// let statx = tokio_uring::fs::statx("foo.txt").await.unwrap();
/// })
/// ```
pub async fn statx<P: AsRef<Path>>(path: P) -> io::Result<libc::statx> {
pub async fn statx<P: AsRef<Path>>(path: P) -> io::Result<linux_raw_sys::general::statx> {
StatxBuilder::new().pathname(path).unwrap().statx().await
}

Expand Down Expand Up @@ -162,7 +162,7 @@ impl StatxBuilder {
file: None,
path: None,
flags: libc::AT_EMPTY_PATH,
mask: libc::STATX_ALL,
mask: linux_raw_sys::general::STATX_ALL,
}
}

Expand Down Expand Up @@ -288,7 +288,7 @@ impl StatxBuilder {
/// dir.close().await.unwrap();
/// })
/// ```
pub async fn statx(&mut self) -> io::Result<libc::statx> {
pub async fn statx(&mut self) -> io::Result<linux_raw_sys::general::statx> {
// TODO should the statx() terminator be renamed to something like submit()?
let fd = self.file.take();
let path = self.path.take();
Expand All @@ -303,7 +303,11 @@ impl StatxBuilder {
#[allow(dead_code)]
pub async fn is_dir_regfile<P: AsRef<Path>>(path: P) -> (bool, bool) {
let mut builder = crate::fs::StatxBuilder::new();
if builder.mask(libc::STATX_TYPE).pathname(path).is_err() {
if builder
.mask(linux_raw_sys::general::STATX_TYPE)
.pathname(path)
.is_err()
{
return (false, false);
}

Expand Down
4 changes: 2 additions & 2 deletions src/io/sendmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ impl<T: BoundedBuf, U: BoundedBuf> Op<SendMsg<T, U>> {
match msg_control {
Some(ref _msg_control) => {
msghdr.msg_control = _msg_control.stable_ptr() as *mut _;
msghdr.msg_controllen = _msg_control.bytes_init();
msghdr.msg_controllen = _msg_control.bytes_init() as _;
}
None => {
msghdr.msg_control = std::ptr::null_mut();
msghdr.msg_controllen = 0_usize;
msghdr.msg_controllen = 0;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/io/sendmsg_zc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ impl<T: BoundedBuf, U: BoundedBuf> Op<SendMsgZc<T, U>, MultiCQEFuture> {
match msg_control {
Some(ref _msg_control) => {
msghdr.msg_control = _msg_control.stable_ptr() as *mut _;
msghdr.msg_controllen = _msg_control.bytes_init();
msghdr.msg_controllen = _msg_control.bytes_init() as _;
}
None => {
msghdr.msg_control = std::ptr::null_mut();
msghdr.msg_controllen = 0_usize;
msghdr.msg_controllen = 0;
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/io/statx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) struct Statx {

// TODO consider returning this type when the operation is complete so the caller has the boxed value.
// The builder could even recycle an old boxed value and pass it in here.
statx: Box<libc::statx>,
statx: Box<linux_raw_sys::general::statx>,
}

impl Op<Statx> {
Expand Down Expand Up @@ -53,7 +53,8 @@ impl Op<Statx> {
opcode::Statx::new(
types::Fd(raw),
statx.path.as_ptr(),
&mut *statx.statx as *mut libc::statx as *mut types::statx,
&mut *statx.statx as *mut linux_raw_sys::general::statx
as *mut types::statx,
)
.flags(flags)
.mask(mask)
Expand All @@ -65,7 +66,7 @@ impl Op<Statx> {
}

impl Completable for Statx {
type Output = io::Result<libc::statx>;
type Output = io::Result<linux_raw_sys::general::statx>;

fn complete(self, cqe: CqeResult) -> Self::Output {
cqe.result?;
Expand Down