Makedev, major, minor for dev_t

I stumbled into clang 12 halting on ‘major’ call, which is not defined anywhere (as “error: implicit declaration of function ‘major’ is invalid in C99”).

Now I see on haiku that definition is missing, as well as ‘minor’ and ‘makedev’ (freebsd has those).

As into ‘sys/types.h’ I see dev_t is defined as

typedef __haiku_int32 dev_t;

I wonder, is there no concept of class (major) and instance (minor) of a device ID in haiku?

Or are there other ways of getting those?

1 Like

There are no major/minor concept in Haiku. dev_t is just an identifier that is allocated by kernel and it has no extra structure. dev_t values are not preserved on reboot.

Unlike usual UNIX-like systems, Haiku can’t create character devices using mknod function, character devices can be only created from kernel mode code and exposed in dedicated file system “devfs” (usually mounted at /dev). It is impossible to create block/character devices outside of devfs.

1 Like

This is basically how I understood it as well, just that to me it sounded like what it is, not what it should be (e.g. a more stable variant being possible if anyone would write a high quality patch).

What this meant to me was that the classical way of matching st_dev and st_rdev did not work as expected.

So at this point I would warn about using those values at all in userland. So depending on what @topolinik tries to do, it might not be as easy as having some dummy macros or checking the value in another way (e.g. memcmp(3)).

It is probably fine to define major(x) = 0 and minor(x) = x because Haiku dev_t do not store device type.

Yes, that is what I was thinking at first. But… Depending on what you do it might just hide errors.

Except major/minor separation, st_dev, st_rdev should work as expected on Haiku. Matching should work.

As discussed on IRC, with a quick check, it doesn’t seem matching works as expected on my side. Happy to have another look another time (just ping me on IRC).