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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use crate::fd::{AsFd, BorrowedFd};
use crate::ffi::CStr;
use crate::fs::AtFlags;
use crate::{backend, io, path};
use core::sync::atomic::{AtomicU8, Ordering};
pub use backend::fs::types::{Statx, StatxFlags, StatxTimestamp};
#[inline]
pub fn statx<P: path::Arg, Fd: AsFd>(
dirfd: Fd,
path: P,
flags: AtFlags,
mask: StatxFlags,
) -> io::Result<Statx> {
path.into_with_c_str(|path| _statx(dirfd.as_fd(), path, flags, mask))
}
static STATX_STATE: AtomicU8 = AtomicU8::new(0);
#[inline]
fn _statx(
dirfd: BorrowedFd<'_>,
path: &CStr,
flags: AtFlags,
mask: StatxFlags,
) -> io::Result<Statx> {
match STATX_STATE.load(Ordering::Relaxed) {
0 => statx_init(dirfd, path, flags, mask),
1 => Err(io::Errno::NOSYS),
_ => backend::fs::syscalls::statx(dirfd, path, flags, mask),
}
}
fn statx_init(
dirfd: BorrowedFd<'_>,
path: &CStr,
flags: AtFlags,
mask: StatxFlags,
) -> io::Result<Statx> {
match backend::fs::syscalls::statx(dirfd, path, flags, mask) {
Err(io::Errno::NOSYS) => statx_error_nosys(),
Err(io::Errno::PERM) => statx_error_perm(),
result => {
STATX_STATE.store(2, Ordering::Relaxed);
result
}
}
}
#[cold]
fn statx_error_nosys() -> io::Result<Statx> {
STATX_STATE.store(1, Ordering::Relaxed);
Err(io::Errno::NOSYS)
}
#[cold]
fn statx_error_perm() -> io::Result<Statx> {
if backend::fs::syscalls::is_statx_available() {
STATX_STATE.store(2, Ordering::Relaxed);
Err(io::Errno::PERM)
} else {
statx_error_nosys()
}
}