extunix
extunix copied to clipboard
Add support for the ioctl(2) facility
This pull request adds initial basic support for the ioctl(2)
facility long missing from OCaml. By specifying only the nullary command version (i.e., suitable only to ioctl_list(2)
requests that don't take any argument), this initial implementation is of limited utility but also a no-brainer to provide as a bare minimum.
As you'll note in the evolution of the commit history for this branch, I've checked that the signature is compatible with at least Linux, Darwin, FreeBSD, OpenBSD, and NetBSD. The obsolescent POSIX definition of ioctl(2)
has hence been superseded in actual practice by all major platforms of note.
In terms of future directions to extend this to a fully-functional unary-argument version, I believe that there are four distinct cases to handle:
-
ioctl(fd, cmd, arg)
, wherearg
is an immediate integer input argument. -
ioctl(fd, cmd, &arg)
, wherearg
is an integer input/output argument. -
ioctl(fd, cmd, buf)
, wherearg
is effectively aconst void*
input argument. -
ioctl(fd, cmd, &buf)
, wherearg
is effectively avoid*
input/output argument.
The first case would be trivial, but I'd appreciate guidance on what an extended interface for all the above might best look like in terms of the conventions of and facilities provided by ExtUnix. Two options that come to mind would be to either provide a variant type to facilitate case analysis of the argument, or else to provide (at least) four distinct functions (e.g., ioctl_int
, etc). Thoughts?
Note that there are already several specific bindings to some ioctl functions - namely siocgifconf and 4 tty ioctls - we will probably need to unify the code at some point. As for the future interface - looks like we will be able to generically cover not many cases bc many ioctls take or return C struct and will require a specific binding.
Can you give some examples of ioctl's that use this NULL-arg form? I imagine that we will have a list of "popular" ioctls builtin in extunix, but will also let users call ioctl functions with different type signatures implemented in extunix with user-provided ioctl cmd number (which is inherently unsafe) - this is a valid use-case?