Skip to content

posix: add device mknod support - #911

Open
avsm wants to merge 3 commits into
ocaml-multicore:mainfrom
avsm:mknod-support
Open

posix: add device mknod support#911
avsm wants to merge 3 commits into
ocaml-multicore:mainfrom
avsm:mknod-support

Conversation

@avsm

@avsm avsm commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

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

@avsm
avsm marked this pull request as ready for review July 30, 2026 13:54
@avsm

avsm commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Works across the board now!

Comment thread lib_eio_posix/eio_posix_stubs.c Outdated
#include <sys/uio.h>
#include <sys/stat.h>
#ifdef __linux__
#include <sys/sysmacros.h>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 talex5 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib_eio_posix/low_level.ml Outdated

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 ]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should probably match the names in Eio.File.Stat.kind (e.g. Regular_file).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread lib_eio_posix/low_level.mli Outdated
Comment on lines +65 to +66
val to_int64 : t -> int64
(** [to_int64 t] is the raw [dev_t] value of [t], as the OS represents it. *)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh the Wayland >uint64_t is a new one on me, I'll look at that...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in b8e6769

@avsm

avsm commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Not sure where this should go so it can work with Eio_linux as well. eio.unix would be pulled in on Windows too so not appropriate. Can Eio_linux depend on Eio_posix?

@avsm

avsm commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

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

@avsm
avsm force-pushed the mknod-support branch 2 times, most recently from 50973bc to e798377 Compare August 5, 2026 11:22
avsm added 3 commits August 5, 2026 11:23
This allows for the creation of a range of devices more so than
just FIFOs
@avsm

avsm commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Rebased and tweaked to use alcotest in eio_posix as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants