extunix icon indicating copy to clipboard operation
extunix copied to clipboard

Add support for the ioctl(2) facility

Open artob opened this issue 9 years ago • 2 comments

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:

  1. ioctl(fd, cmd, arg), where arg is an immediate integer input argument.
  2. ioctl(fd, cmd, &arg), where arg is an integer input/output argument.
  3. ioctl(fd, cmd, buf), where arg is effectively a const void* input argument.
  4. ioctl(fd, cmd, &buf), where arg is effectively a void* 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?

artob avatar Nov 29 '15 18:11 artob

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.

ygrek avatar Dec 05 '15 23:12 ygrek

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?

ygrek avatar Dec 06 '15 00:12 ygrek