Skip to content

Commit 22e4644

Browse files
committed
Use linux-raw-sys for statx type definitions
These definitions are not provided on musl by the libc crate, and since they are defined in kernel headers, we can just use linux-raw-sys on all targets. Signed-off-by: Jens Reidel <[email protected]>
1 parent 7761222 commit 22e4644

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ keywords = ["async", "fs", "io-uring"]
2020
tokio = { version = "1.2", features = ["net", "rt", "sync"] }
2121
slab = "0.4.2"
2222
libc = "0.2.80"
23+
linux-raw-sys = "0.6"
2324
io-uring = "0.6.0"
2425
socket2 = { version = "0.4.4", features = ["all"] }
2526
bytes = { version = "1.0", optional = true }

src/fs/create_dir_all.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ mod fs_imp {
193193
// Uses one asynchronous uring call to determine this.
194194
async fn is_dir<P: AsRef<Path>>(path: P) -> bool {
195195
let mut builder = crate::fs::StatxBuilder::new();
196-
if builder.mask(libc::STATX_TYPE).pathname(path).is_err() {
196+
if builder
197+
.mask(linux_raw_sys::general::STATX_TYPE)
198+
.pathname(path)
199+
.is_err()
200+
{
197201
return false;
198202
}
199203

src/fs/statx.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ impl File {
2828
/// f.close().await.unwrap();
2929
/// })
3030
/// ```
31-
pub async fn statx(&self) -> io::Result<libc::statx> {
31+
pub async fn statx(&self) -> io::Result<linux_raw_sys::general::statx> {
3232
let flags = libc::AT_EMPTY_PATH;
33-
let mask = libc::STATX_ALL;
33+
let mask = linux_raw_sys::general::STATX_ALL;
3434
Op::statx(Some(self.fd.clone()), None, flags, mask)?.await
3535
}
3636

@@ -73,7 +73,7 @@ impl File {
7373
file: Some(self.fd.clone()),
7474
path: None,
7575
flags: libc::AT_EMPTY_PATH,
76-
mask: libc::STATX_ALL,
76+
mask: linux_raw_sys::general::STATX_ALL,
7777
}
7878
}
7979
}
@@ -102,7 +102,7 @@ impl File {
102102
/// let statx = tokio_uring::fs::statx("foo.txt").await.unwrap();
103103
/// })
104104
/// ```
105-
pub async fn statx<P: AsRef<Path>>(path: P) -> io::Result<libc::statx> {
105+
pub async fn statx<P: AsRef<Path>>(path: P) -> io::Result<linux_raw_sys::general::statx> {
106106
StatxBuilder::new().pathname(path).unwrap().statx().await
107107
}
108108

@@ -162,7 +162,7 @@ impl StatxBuilder {
162162
file: None,
163163
path: None,
164164
flags: libc::AT_EMPTY_PATH,
165-
mask: libc::STATX_ALL,
165+
mask: linux_raw_sys::general::STATX_ALL,
166166
}
167167
}
168168

@@ -288,7 +288,7 @@ impl StatxBuilder {
288288
/// dir.close().await.unwrap();
289289
/// })
290290
/// ```
291-
pub async fn statx(&mut self) -> io::Result<libc::statx> {
291+
pub async fn statx(&mut self) -> io::Result<linux_raw_sys::general::statx> {
292292
// TODO should the statx() terminator be renamed to something like submit()?
293293
let fd = self.file.take();
294294
let path = self.path.take();
@@ -303,7 +303,11 @@ impl StatxBuilder {
303303
#[allow(dead_code)]
304304
pub async fn is_dir_regfile<P: AsRef<Path>>(path: P) -> (bool, bool) {
305305
let mut builder = crate::fs::StatxBuilder::new();
306-
if builder.mask(libc::STATX_TYPE).pathname(path).is_err() {
306+
if builder
307+
.mask(linux_raw_sys::general::STATX_TYPE)
308+
.pathname(path)
309+
.is_err()
310+
{
307311
return (false, false);
308312
}
309313

src/io/statx.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(crate) struct Statx {
1818

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

2424
impl Op<Statx> {
@@ -53,7 +53,8 @@ impl Op<Statx> {
5353
opcode::Statx::new(
5454
types::Fd(raw),
5555
statx.path.as_ptr(),
56-
&mut *statx.statx as *mut libc::statx as *mut types::statx,
56+
&mut *statx.statx as *mut linux_raw_sys::general::statx
57+
as *mut types::statx,
5758
)
5859
.flags(flags)
5960
.mask(mask)
@@ -65,7 +66,7 @@ impl Op<Statx> {
6566
}
6667

6768
impl Completable for Statx {
68-
type Output = io::Result<libc::statx>;
69+
type Output = io::Result<linux_raw_sys::general::statx>;
6970

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

0 commit comments

Comments
 (0)