Skip to content

netbsd: Export ioctl request generator macros #4460

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions libc-test/semver/netbsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,17 @@ IFF_SIMPLEX
IFF_UP
IMAXBEL
INIT_PROCESS
IOCBASECMD
IOCGROUP
IOCGROUP_SHIFT
IOCPARM_LEN
IOCPARM_MASK
IOCPARM_SHIFT
IOC_DIRMASK
IOC_IN
IOC_INOUT
IOC_OUT
IOC_VOID
IOV_MAX
IPC_CREAT
IPC_EXCL
Expand Down Expand Up @@ -1116,9 +1127,14 @@ XATTR_CREATE
XATTR_REPLACE
YESEXPR
YESSTR
_IO
_IOC
_IOFBF
_IOLBF
_IONBF
_IOR
_IOW
_IOWR
_PC_2_SYMLINKS
_PC_ACL_EXTENDED
_PC_FILESIZEBITS
Expand Down
14 changes: 14 additions & 0 deletions libc-test/semver/openbsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,15 @@ IFF_SIMPLEX
IFF_STATICARP
IFF_UP
IMAXBEL
IOCBASECMD
IOCGROUP
IOCPARM_LEN
IOCPARM_MASK
IOC_DIRMASK
IOC_IN
IOC_INOUT
IOC_OUT
IOC_VOID
IOV_MAX
IPC_CREAT
IPC_EXCL
Expand Down Expand Up @@ -908,9 +917,14 @@ WSTOPPED
WTRAPPED
YESEXPR
YESSTR
_IO
_IOC
_IOFBF
_IOLBF
_IONBF
_IOR
_IOW
_IOWR
_MAX_PAGE_SHIFT
_PC_2_SYMLINKS
_PC_ALLOC_SIZE_MIN
Expand Down
28 changes: 28 additions & 0 deletions src/unix/bsd/netbsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,34 @@ pub const MNT_NODEV: c_int = 0x00000010;
pub const MNT_LOCAL: c_int = 0x00001000;
pub const MNT_QUOTA: c_int = 0x00002000;

// sys/ioccom.h in NetBSD and OpenBSD
pub const IOCPARM_MASK: u32 = 0x1fff;

pub const IOC_VOID: c_ulong = 0x20000000;
pub const IOC_OUT: c_ulong = 0x40000000;
pub const IOC_IN: c_ulong = 0x80000000;
pub const IOC_INOUT: c_ulong = IOC_IN | IOC_OUT;
pub const IOC_DIRMASK: c_ulong = 0xe0000000;

pub const fn _IO(g: c_ulong, n: c_ulong) -> c_ulong {
_IOC(IOC_VOID, g, n, 0)
}

/// Build an ioctl number for an read-only ioctl.
pub const fn _IOR<T>(g: c_ulong, n: c_ulong) -> c_ulong {
_IOC(IOC_OUT, g, n, mem::size_of::<T>() as c_ulong)
}

/// Build an ioctl number for an write-only ioctl.
pub const fn _IOW<T>(g: c_ulong, n: c_ulong) -> c_ulong {
_IOC(IOC_IN, g, n, mem::size_of::<T>() as c_ulong)
}

/// Build an ioctl number for a read-write ioctl.
pub const fn _IOWR<T>(g: c_ulong, n: c_ulong) -> c_ulong {
_IOC(IOC_INOUT, g, n, mem::size_of::<T>() as c_ulong)
}

pub const AF_UNSPEC: c_int = 0;
pub const AF_LOCAL: c_int = 1;
pub const AF_UNIX: c_int = AF_LOCAL;
Expand Down
20 changes: 20 additions & 0 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,26 @@ pub const MNT_WAIT: c_int = 1;
pub const MNT_NOWAIT: c_int = 2;
pub const MNT_LAZY: c_int = 3;

// sys/ioccom.h
pub const IOCPARM_SHIFT: u32 = 16;
pub const IOCGROUP_SHIFT: u32 = 8;

pub const fn IOCPARM_LEN(x: u32) -> u32 {
(x >> IOCPARM_SHIFT) & crate::IOCPARM_MASK
}

pub const fn IOCBASECMD(x: u32) -> u32 {
x & (!(crate::IOCPARM_MASK << IOCPARM_SHIFT))
}

pub const fn IOCGROUP(x: u32) -> u32 {
(x >> IOCGROUP_SHIFT) & 0xff
}

pub const fn _IOC(inout: c_ulong, group: c_ulong, num: c_ulong, len: c_ulong) -> c_ulong {
(inout) | (((len) & crate::IOCPARM_MASK as c_ulong) << IOCPARM_SHIFT) | ((group) << IOCGROUP_SHIFT) | (num)
}

//<sys/timex.h>
pub const CLOCK_PROCESS_CPUTIME_ID: crate::clockid_t = 2;
pub const CLOCK_THREAD_CPUTIME_ID: crate::clockid_t = 4;
Expand Down
17 changes: 17 additions & 0 deletions src/unix/bsd/netbsdlike/openbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,23 @@ pub const PF_R: u32 = 0x4;
pub const PF_MASKOS: u32 = 0x0ff00000;
pub const PF_MASKPROC: u32 = 0xf0000000;

// sys/ioccom.h
pub const fn IOCPARM_LEN(x: u32) -> u32 {
(x >> 16) & crate::IOCPARM_MASK
}

pub const fn IOCBASECMD(x: u32) -> u32 {
x & (!(crate::IOCPARM_MASK << 16))
}

pub const fn IOCGROUP(x: u32) -> u32 {
(x >> 8) & 0xff
}

pub const fn _IOC(inout: c_ulong, group: c_ulong, num: c_ulong, len: c_ulong) -> c_ulong {
(inout) | (((len) & crate::IOCPARM_MASK as c_ulong) << 16) | ((group) << 8) | (num)
}

// sys/mount.h
pub const MNT_NOPERM: c_int = 0x00000020;
pub const MNT_WXALLOWED: c_int = 0x00000800;
Expand Down
Loading