diff options
author | bors <bors@rust-lang.org> | 2023-05-06 10:03:01 +0000 |
---|---|---|
committer | bors <bors@rust-lang.org> | 2023-05-06 10:03:01 +0000 |
commit | cdf9aa767435b892cc8a211c4b88b3268a996478 (patch) | |
tree | a7d7f1ca05bd51b8ab11bb0613c27e5372c88733 /src/unix/solarish/mod.rs | |
parent | a11d63a0c747c8991bb488e62de0ebd14b86bae9 (diff) | |
parent | 044941617a2695ea0050f682a2d4a5e57a65799d (diff) | |
download | rust-libc-cdf9aa767435b892cc8a211c4b88b3268a996478.tar.gz |
Auto merge of #2999 - SteveLauC:major/minor-on-BSDs, r=JohnTitor
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)
Diffstat (limited to 'src/unix/solarish/mod.rs')
-rw-r--r-- | src/unix/solarish/mod.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index cc688331f4..48ab4dbb92 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -2584,6 +2584,8 @@ const _CMSG_HDR_ALIGNMENT: usize = 4; const _CMSG_DATA_ALIGNMENT: usize = ::mem::size_of::<::c_int>(); +const NEWDEV: ::c_int = 1; + const_fn! { {const} fn _CMSG_HDR_ALIGN(p: usize) -> usize { (p + _CMSG_HDR_ALIGNMENT - 1) & !(_CMSG_HDR_ALIGNMENT - 1) @@ -3198,6 +3200,10 @@ extern "C" { ) -> ::c_int; pub fn sync(); + + fn __major(version: ::c_int, devnum: ::dev_t) -> ::major_t; + fn __minor(version: ::c_int, devnum: ::dev_t) -> ::minor_t; + fn __makedev(version: ::c_int, majdev: ::major_t, mindev: ::minor_t) -> ::dev_t; } #[link(name = "sendfile")] @@ -3254,6 +3260,18 @@ extern "C" { pub fn lgrp_root(cookie: ::lgrp_cookie_t) -> ::lgrp_id_t; } +pub unsafe fn major(device: ::dev_t) -> ::major_t { + __major(NEWDEV, device) +} + +pub unsafe fn minor(device: ::dev_t) -> ::minor_t { + __minor(NEWDEV, device) +} + +pub unsafe fn makedev(maj: ::major_t, min: ::minor_t) -> ::dev_t { + __makedev(NEWDEV, maj, min) +} + mod compat; pub use self::compat::*; |