Skip to content

Commit 0fc5409

Browse files
jackpot51tgross35
authored andcommitted
redox: add makedev, major, minor, and fix dev_t
(backport <#4928>) (cherry picked from commit 76e737e)
1 parent 99c0a2b commit 0fc5409

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

‎src/unix/redox/mod.rs‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub type blkcnt_t = c_ulong;
66
pub type blksize_t = c_long;
77
pub type clock_t = c_long;
88
pub type clockid_t = c_int;
9-
pub type dev_t = c_long;
9+
pub type dev_t = c_ulonglong;
1010
pub type fsblkcnt_t = c_ulong;
1111
pub type fsfilcnt_t = c_ulong;
1212
pub type ino_t = c_ulonglong;
@@ -1162,6 +1162,31 @@ safe_f! {
11621162
pub const fn WCOREDUMP(status: c_int) -> bool {
11631163
(status & 0x80) != 0
11641164
}
1165+
1166+
pub const fn makedev(major: c_uint, minor: c_uint) -> dev_t {
1167+
let major = major as dev_t;
1168+
let minor = minor as dev_t;
1169+
let mut dev = 0;
1170+
dev |= (major & 0x00000fff) << 8;
1171+
dev |= (major & 0xfffff000) << 32;
1172+
dev |= (minor & 0x000000ff) << 0;
1173+
dev |= (minor & 0xffffff00) << 12;
1174+
dev
1175+
}
1176+
1177+
pub const fn major(dev: dev_t) -> c_uint {
1178+
let mut major = 0;
1179+
major |= (dev & 0x00000000000fff00) >> 8;
1180+
major |= (dev & 0xfffff00000000000) >> 32;
1181+
major as c_uint
1182+
}
1183+
1184+
pub const fn minor(dev: dev_t) -> c_uint {
1185+
let mut minor = 0;
1186+
minor |= (dev & 0x00000000000000ff) >> 0;
1187+
minor |= (dev & 0x00000ffffff00000) >> 12;
1188+
minor as c_uint
1189+
}
11651190
}
11661191

11671192
extern "C" {

0 commit comments

Comments
 (0)