Updated: April 19, 2023 |
Get major and minor device numbers
#include <sys/rsrcdbmgr.h> #include <sys/rsrcdbmsg.h> dev_t rsrcdbmgr_devno_attach( const char * name, int minor_request, int flags );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The rsrcdbmgr_devno_attach() function reserves a device number that consists of:
There's a maximum of 64 major numbers (0 through 63) on the system, and a maximum of 1024 minor numbers (0 through 1023) per major number.
Major and minor numbers are used only by resource managers and are exposed through the rdev member of the iofunc_attr_t structure, and correspondingly the st_rdev member of the stat structure. They aren't required for proper operation; on simple devices, an entry will be simulated for you.
If the requested device number is already in use (whether by the calling process or a different process), this function returns -1 and sets errno to EINVAL.
To detach a device, call rsrcdbmgr_devno_detach(). If you don't detach a device, it's released when the process that attached it terminates.
Class names
As mentioned above, the name of the class of devices can be anything, but can't include any slashes. The following class names are defined in <sys/ftype.h>:
Constant | Value | Class |
---|---|---|
_MAJOR_PATHMGR | "pathmgr" | Used only by the path manager |
_MAJOR_DEV | "dev" | Devices in /dev with only one instance (e.g., /dev/tty) |
_MAJOR_BLK_PREFIX | "blk-" | All block devices (e.g., /dev/hd[0-9]* would be "blk-hd") |
_MAJOR_CHAR_PREFIX | "char-" | All character devices (e.g., /dev/ser[0-9]* would be "char-ser") |
_MAJOR_FSYS | "fsys" | All filesystems |
A dev_t object that contains the major and minor numbers, or (dev_t)-1 if an error occurs (errno is set).
You can extract the major and minor number values from the dev_t object by using the major() and minor() macros defined in <sys/types.h>. For more information, see the documentation for stat().
#include <sys/rsrcdbmgr.h> #include <sys/rsrcdbmsg.h> char *dev_name; int myminor_request, flags=0; dev_t major_minor; major_minor = rsrcdbmgr_devno_attach ( dev_name, myminor_request, flags ); … rsrcdbmgr_devno_detach( major_minor, flags );
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |