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
| Name | Type | Dir | Description |
|---|---|---|---|
| fd | int | - | |
| com | u_long | - | |
| data | caddr_t | - |
Version history
| XNU tag | macOS | # |
|---|---|---|
| xnu-1456.1.26 | macOS 10.6 Snow Leopard | 54 |
| xnu-1486.2.11 | — | 54 |
| xnu-1504.15.3 | — | 54 |
| xnu-1504.3.12 | — | 54 |
| xnu-1504.7.4 | — | 54 |
| xnu-1504.9.17 | — | 54 |
| xnu-1504.9.26 | — | 54 |
| xnu-1504.9.37 | — | 54 |
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