Skip to content

Commit b95ca36

Browse files
Enable ioctl and makedev on Redox
Submitted as #1555. Modified to avoid adding the `as Dev` on non-Redox targets. Co-authored-by: Jeremy Soller <jackpot51@gmail.com>
1 parent 76aff5e commit b95ca36

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

src/backend/libc/fs/makedev.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::fs::Dev;
1414
target_os = "aix",
1515
target_os = "android",
1616
target_os = "emscripten",
17+
target_os = "redox",
1718
)))]
1819
#[inline]
1920
pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
@@ -44,6 +45,17 @@ pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
4445
| (u64::from(min) & 0x0000_00ff_u64)
4546
}
4647

48+
#[cfg(target_os = "redox")]
49+
#[inline]
50+
pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
51+
// Redox's makedev is reportedly similar to 32-bit Android's but the return
52+
// type is signed.
53+
((i64::from(maj) & 0xffff_f000_i64) << 32)
54+
| ((i64::from(maj) & 0x0000_0fff_i64) << 8)
55+
| ((i64::from(min) & 0xffff_ff00_i64) << 12)
56+
| (i64::from(min) & 0x0000_00ff_i64)
57+
}
58+
4759
#[cfg(target_os = "emscripten")]
4860
#[inline]
4961
pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
@@ -70,7 +82,8 @@ pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
7082
freebsdlike,
7183
target_os = "android",
7284
target_os = "emscripten",
73-
target_os = "netbsd"
85+
target_os = "netbsd",
86+
target_os = "redox"
7487
)))]
7588
#[inline]
7689
pub(crate) fn major(dev: Dev) -> u32 {
@@ -89,7 +102,10 @@ pub(crate) fn major(dev: Dev) -> u32 {
89102
(unsafe { c::major(dev) }) as u32
90103
}
91104

92-
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
105+
#[cfg(any(
106+
all(target_os = "android", target_pointer_width = "32"),
107+
target_os = "redox"
108+
))]
93109
#[inline]
94110
pub(crate) fn major(dev: Dev) -> u32 {
95111
// 32-bit Android's `dev_t` is 32-bit, but its `st_dev` is 64-bit, so we do
@@ -109,7 +125,8 @@ pub(crate) fn major(dev: Dev) -> u32 {
109125
freebsdlike,
110126
target_os = "android",
111127
target_os = "emscripten",
112-
target_os = "netbsd"
128+
target_os = "netbsd",
129+
target_os = "redox",
113130
)))]
114131
#[inline]
115132
pub(crate) fn minor(dev: Dev) -> u32 {
@@ -128,7 +145,10 @@ pub(crate) fn minor(dev: Dev) -> u32 {
128145
(unsafe { c::minor(dev) }) as u32
129146
}
130147

131-
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
148+
#[cfg(any(
149+
all(target_os = "android", target_pointer_width = "32"),
150+
target_os = "redox"
151+
))]
132152
#[inline]
133153
pub(crate) fn minor(dev: Dev) -> u32 {
134154
// 32-bit Android's `dev_t` is 32-bit, but its `st_dev` is 64-bit, so we do

src/backend/libc/fs/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub mod inotify;
66
target_os = "espidf",
77
target_os = "haiku",
88
target_os = "horizon",
9-
target_os = "redox",
109
target_os = "vita",
1110
target_os = "wasi"
1211
)))]

src/fs/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ mod ioctl;
3838
target_os = "espidf",
3939
target_os = "haiku",
4040
target_os = "horizon",
41-
target_os = "redox",
4241
target_os = "vita",
4342
target_os = "wasi"
4443
)))]
@@ -103,7 +102,6 @@ pub use ioctl::*;
103102
target_os = "espidf",
104103
target_os = "haiku",
105104
target_os = "horizon",
106-
target_os = "redox",
107105
target_os = "vita",
108106
target_os = "wasi"
109107
)))]

src/ioctl/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ use crate::fd::{AsFd, BorrowedFd};
1818
use crate::ffi as c;
1919
use crate::io::Result;
2020

21-
#[cfg(any(linux_kernel, bsd))]
21+
#[cfg(any(linux_kernel, bsd, target_os = "redox"))]
2222
use core::mem;
2323

2424
pub use patterns::*;
2525

2626
mod patterns;
2727

28-
#[cfg(linux_kernel)]
28+
#[cfg(any(linux_kernel, target_os = "redox"))]
2929
mod linux;
3030

3131
#[cfg(bsd)]
3232
mod bsd;
3333

34-
#[cfg(linux_kernel)]
34+
#[cfg(any(linux_kernel, target_os = "redox"))]
3535
use linux as platform;
3636

3737
#[cfg(bsd)]
@@ -198,7 +198,7 @@ pub unsafe trait Ioctl {
198198
///
199199
/// If you're writing a driver and defining your own ioctl numbers, it's
200200
/// recommended to use these functions to compute them.
201-
#[cfg(any(linux_kernel, bsd))]
201+
#[cfg(any(linux_kernel, bsd, target_os = "redox"))]
202202
pub mod opcode {
203203
use super::*;
204204

tests/fs/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod invalid_offset;
2727
mod ioctl;
2828
mod linkat;
2929
mod long_paths;
30-
#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))]
30+
#[cfg(not(any(target_os = "haiku", target_os = "wasi")))]
3131
mod makedev;
3232
mod mkdirat;
3333
mod mknodat;

0 commit comments

Comments
 (0)