posix: add device mknod support - #911
Conversation
|
Works across the board now! |
| #include <sys/uio.h> | ||
| #include <sys/stat.h> | ||
| #ifdef __linux__ | ||
| #include <sys/sysmacros.h> |
There was a problem hiding this comment.
This is the best I could find; I'm surprised that Linux needs a special include but its like this since glibc 2.28 https://www.man7.org/linux/man-pages/man3/makedev.3.html
talex5
left a comment
There was a problem hiding this comment.
It's strange that this is only for eio_posix and not available with eio_linux. Probably it needs moving so it can be shared.
Eio.File.Stat.t uses Int64.t for devices. We should probably use the same type here. We could add an Eio.File.Dev.t type (just an alias to int64 at first, then maybe private later).
The conversions to/from major/minor pairs could go in Eio_unix somewhere.
|
|
||
| external eio_mknodat : Unix.file_descr -> string -> int -> Dev.t -> unit = "caml_eio_posix_mknodat" | ||
|
|
||
| type node_kind = [ `Fifo | `Sock | `Reg | `Chr of Dev.t | `Blk of Dev.t ] |
There was a problem hiding this comment.
These should probably match the names in Eio.File.Stat.kind (e.g. Regular_file).
There was a problem hiding this comment.
Yeah, the problem with exposing this in Eio.File is that it should be portable to Windows as well, so now I'm spelunking in there to find out what's going on :-)
There was a problem hiding this comment.
Done in b8e6769, with the slight annoyance that the types aren't exactly the same since the Eio.File.Stat.kind doesn't have a payload for Dev.t (since it can be constructed by getdents which doesn't supply the full device number)
| val to_int64 : t -> int64 | ||
| (** [to_int64 t] is the raw [dev_t] value of [t], as the OS represents it. *) |
There was a problem hiding this comment.
Needs a from_int64 too.
(and in the past I've had a from_raw for Wayland, which doesn't assume devices fit in 64 bits: https://github.com/talex5/libdrm-ocaml/blob/main/lib/dev_t.mli)
There was a problem hiding this comment.
Oh the Wayland >uint64_t is a new one on me, I'll look at that...
There was a problem hiding this comment.
Actually maybe it's not that it's larger, just that the size varies by platform, so it sends it as an array of bytes:
https://wayland.app/protocols/linux-dmabuf-v1#zwp_linux_dmabuf_feedback_v1:event:main_device
|
Not sure where this should go so it can work with Eio_linux as well. |
|
I've moved it into Eio_unix in b8e6769. One breaking change to look at is that the Eio.File.t now switches to a Dev.t, and also a Dev.t option for rdev. This is because the Windows Unix layer in OCaml sets rdev to dev during its 'emulation'. It seems better for our portable layer to explicitly mark this as None. For the dev layer, it is indeed set to the volume serial number on Windows, so that works well as a private int64 |
50973bc to
e798377
Compare
This allows for the creation of a range of devices more so than just FIFOs
review changes were suggested by @talex5
|
Rebased and tweaked to use alcotest in eio_posix as well |
This allows for the creation of a range of devices more so than just FIFOs.
Draft PR until it runs over the BSD CIs to test there, only manually tested on macOS and Linux