-
Notifications
You must be signed in to change notification settings - Fork 1k
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
add major/minor on BSDs/illumos #2999
Conversation
r? @JohnTitor (rust-highfive has picked a reviewer for you, use r? to override) |
facdcab
to
3e4b6b4
Compare
Those are not the major/minor/makdev macros for illumos itself. Although it's not advertised especially well, |
And, critically, #include <stdlib.h>
#include <stdio.h>
#include <sys/mkdev.h>
int
main()
{
dev_t dev = makedev(0x81, 0x82);
printf("dev = %lx\n", dev);
}
|
Thank you both for showing me this! I just took a look at So If we want them in Rust, is there any way we can do this? Thanks:) |
You are most welcome!
That's correct. We implement them as functions, rather than as macros, so that we can make changes to their implementation without requiring people to recompile their applications.
Definitely! You'll need to create an Something like: extern "C" {
fn __makedev(version: ::c_int, majdev: ::major_t, mindev: ::mindev) -> ::dev_t;
}
const NEWDEV: ::c_int = 1;
pub fn makedev(maj: ::major_t, min: ::mindev) -> ::dev_t {
unsafe { __makedev(NEWDEV, maj, min) }
} (I have not tried this myself) |
I would use something like: #[link_name="__makedev"]
extern "C" {
pub fn makedev(maj: ::major_t, min: ::mindev) -> ::dev_t;
} the name |
ah, my bad. I didn't noticed that |
regarding the OpenBSD part, it LGTM. |
3e4b6b4
to
f3ebb6d
Compare
Thanks! Let's link to it! |
☔ The latest upstream changes (presumably #3021) made this pull request unmergeable. Please resolve the merge conflicts. |
f3ebb6d
to
a96465d
Compare
Rebased this branch to the latest master:) |
Please add the necessary header requirement so that libc-test is appeased: diff --git a/libc-test/build.rs b/libc-test/build.rs
index ac0f996fc4..8c20546771 100644
--- a/libc-test/build.rs
+++ b/libc-test/build.rs
@@ -821,6 +821,7 @@ fn test_solarish(target: &str) {
"sys/ioctl.h",
"sys/lgrp_user.h",
"sys/loadavg.h",
+ "sys/mkdev.h",
"sys/mman.h",
"sys/mount.h",
"sys/priv.h", Otherwise the illumos bits look good to me. Thanks |
Header added:) @JohnTitor Let's give CI a try, if passed, then I will squash my commits |
👍 @bors try |
add major/minor on BSDs/illumos This PR adds `major/minor` on BSDs and `major/minor/makedev` on illumos. Ref: * [FreeBSD 11](https://github.com/freebsd/freebsd-src/blob/3e9337c6b211e778829ed3af783cd41447a8721b/sys/sys/types.h#L372-L374) ```c #define major(x) ((int)(((u_int)(x) >> 8)&0xff)) /* major number */ #define minor(x) ((int)((x)&0xffff00ff)) /* minor number */ ``` * [FreeBSD 12/13/14](https://github.com/freebsd/freebsd-src/blob/3d98e253febf816e6e2aea7d3b1c013c421895de/sys/sys/types.h#L332-L341) ```c static __inline int __major(dev_t _d) { return (((_d >> 32) & 0xffffff00) | ((_d >> 8) & 0xff)); } static __inline int __minor(dev_t _d) { return (((_d >> 24) & 0xff00) | (_d & 0xffff00ff)); } ``` * [DragonFly](https://github.com/DragonFlyBSD/DragonFlyBSD/blob/d7a10f947f5344fc95e874ca3b83e9e8d0986b25/sys/sys/types.h#L170-L171) ```c #define major(x) ((int)(((u_int)(x) >> 8)&0xff)) /* major number */ #define minor(x) ((int)((x)&0xffff00ff)) /* minor number */ ``` * [NetBSD](https://github.com/NetBSD/src/blob/a25a6fec1b0a676fc5b36fa01b2990e775775d90/sys/sys/types.h#L264-L266) ```c #define major(x) ((devmajor_t)(((uint32_t)(x) & 0x000fff00) >> 8)) #define minor(x) ((devminor_t)((((uint32_t)(x) & 0xfff00000) >> 12) | \ (((uint32_t)(x) & 0x000000ff) >> 0))) ``` * [OpenBSD](https://github.com/openbsd/src/blob/05cbc9aa8d8372e83274c75e35add6b8073c26f5/sys/sys/types.h#L211-L212) ```c #define major(x) (((unsigned)(x) >> 8) & 0xff) #define minor(x) ((unsigned)((x) & 0xff) | (((x) & 0xffff0000) >> 8)) ``` * illumos: 1. [mkdev.c](https://github.com/illumos/illumos-gate/blob/8b26092d555bd1deaacf79ea64da374602aefb65/usr/src/lib/libc/port/gen/mkdev.c#L40-L146) 2. [mkdev.h](https://github.com/illumos/illumos-gate/blob/8b26092d555bd1deaacf79ea64da374602aefb65/usr/src/uts/common/sys/mkdev.h#L97-L99)
💔 Test failed - checks-actions |
Build Channels Linux (beta) failed due to an unnecessary parentheses, just have it fixed, let's try the CI again:) |
@bors try |
add major/minor on BSDs/illumos This PR adds `major/minor` on BSDs and `major/minor/makedev` on illumos. Ref: * [FreeBSD 11](https://github.com/freebsd/freebsd-src/blob/3e9337c6b211e778829ed3af783cd41447a8721b/sys/sys/types.h#L372-L374) ```c #define major(x) ((int)(((u_int)(x) >> 8)&0xff)) /* major number */ #define minor(x) ((int)((x)&0xffff00ff)) /* minor number */ ``` * [FreeBSD 12/13/14](https://github.com/freebsd/freebsd-src/blob/3d98e253febf816e6e2aea7d3b1c013c421895de/sys/sys/types.h#L332-L341) ```c static __inline int __major(dev_t _d) { return (((_d >> 32) & 0xffffff00) | ((_d >> 8) & 0xff)); } static __inline int __minor(dev_t _d) { return (((_d >> 24) & 0xff00) | (_d & 0xffff00ff)); } ``` * [DragonFly](https://github.com/DragonFlyBSD/DragonFlyBSD/blob/d7a10f947f5344fc95e874ca3b83e9e8d0986b25/sys/sys/types.h#L170-L171) ```c #define major(x) ((int)(((u_int)(x) >> 8)&0xff)) /* major number */ #define minor(x) ((int)((x)&0xffff00ff)) /* minor number */ ``` * [NetBSD](https://github.com/NetBSD/src/blob/a25a6fec1b0a676fc5b36fa01b2990e775775d90/sys/sys/types.h#L264-L266) ```c #define major(x) ((devmajor_t)(((uint32_t)(x) & 0x000fff00) >> 8)) #define minor(x) ((devminor_t)((((uint32_t)(x) & 0xfff00000) >> 12) | \ (((uint32_t)(x) & 0x000000ff) >> 0))) ``` * [OpenBSD](https://github.com/openbsd/src/blob/05cbc9aa8d8372e83274c75e35add6b8073c26f5/sys/sys/types.h#L211-L212) ```c #define major(x) (((unsigned)(x) >> 8) & 0xff) #define minor(x) ((unsigned)((x) & 0xff) | (((x) & 0xffff0000) >> 8)) ``` * illumos: 1. [mkdev.c](https://github.com/illumos/illumos-gate/blob/8b26092d555bd1deaacf79ea64da374602aefb65/usr/src/lib/libc/port/gen/mkdev.c#L40-L146) 2. [mkdev.h](https://github.com/illumos/illumos-gate/blob/8b26092d555bd1deaacf79ea64da374602aefb65/usr/src/uts/common/sys/mkdev.h#L97-L99)
☀️ Try build successful - checks-actions, checks-cirrus-freebsd-12, checks-cirrus-freebsd-13, checks-cirrus-freebsd-14 |
6c19c7c
to
0449416
Compare
Commits squashed, Let's merge it😆 |
Thanks! @bors r+ |
☀️ Test successful - checks-actions, checks-cirrus-freebsd-12, checks-cirrus-freebsd-13, checks-cirrus-freebsd-14 |
This PR adds
major/minor
on BSDs andmajor/minor/makedev
on illumos.Ref:
FreeBSD 11
FreeBSD 12/13/14
DragonFly
NetBSD
OpenBSD
illumos: