Skip to content
BSD syscall#54

svc · unix #54

ioctl

Issues a device-specific control request against the kernel object behind a file descriptor.

Prototype

int ioctl(int fd, u_long com, caddr_t data);

Returns: int

Arguments

NameTypeDirDescription
fdint-
comu_long-
datacaddr_t-

Version history

XNU tagmacOS#
xnu-1456.1.26macOS 10.6 Snow Leopard54
xnu-1486.2.1154
xnu-1504.15.354
xnu-1504.3.1254
xnu-1504.7.454
xnu-1504.9.1754
xnu-1504.9.2654
xnu-1504.9.3754

Examples

C — terminal window size

struct winsize ws;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);

Notes

Each driver defines its own request numbers via _IO/_IOR/_IOW/_IOWR macros. ioctl is the primary API for terminal control (TIOC*), socket configuration (SIOC*), disk geometry (DKIOC*) and BPF. Many requests require root or specific entitlements; SIP further restricts unsigned binaries from issuing privileged DKIOC ops.

Detection

syscall::ioctl:entry in DTrace surfaces the request number; correlate with sys/ioccom.h to decode direction and group. No native ES event.

Related APIs

fcntlopentcgetattrtcsetattrselect