tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Finding the slot in the ioconf table a module attaches to?
On Wed, Feb 01, 2023 at 11:14:42 -0800, Brian Buhrow wrote:
> hello. Okay. That is helpful. Passing -1 in as the cmajor
> number to the devsw_attach() function does, in fact, assign a
> reasonable major number which seems to work. I use the
> cdevsw_lookup_major() function to retrieve the assigned number and
> print it for the user.
devsw_attach updates &cmajor with the assigned number if you passed
NODEVMAJOR (-1) in it, so you don't even need to look it up
separately. We also have in-kernel convenience "MAKEDEV".
E.g., paraphrasing a bit, vbox guest additions module does:
bmajor = cmajor = NODEVMAJOR;
error = devsw_attach("vboxguest", NULL, &bmajor,
&vboxguest_cdevsw, &cmajor);
if (error)
...
error = do_sys_mknod(curlwp, "/dev/vboxguest",
S_IFCHR | 0666, makedev(cmajor, 0),
&retval, UIO_SYSSPACE);
if (error == EEXIST) {
error = 0;
/*
* Since NetBSD doesn't yet have a major reserved for
* vboxguest, the (first free) major we get will
* change when new devices are added, so an existing
* /dev/vboxguest may now point to some other device,
* creating confusion (tripped me up a few times).
*/
aprint_normal("vboxguest: major %d:"
" check existing /dev/vboxguest\n", cmajor);
}
(The comment is no longer true, as we do have a reserved major for vbox now).
-uwe
Home |
Main Index |
Thread Index |
Old Index