Managing and Developing Dynamically Loadable Kernel Modules

Managing and Developing Dynamically Loadable Kernel Modules
Developing Dynamically Loadable Kernel Modules
Chapter 12548
drivers must use the drv_info_t structure that is passed as an
argument to the _load() function. The major numbers from this
structure must also be used in the streams_info_t structure passed to
str_install(). Sample _load() and _install() functions for a
STREAMS driver are as follows:
Example 12-9 STREAMS Driver _load and _install Functions
static drv_info_t str_drv_info = { ... };
static drv_info_t *drv_info_p = &str_drv_info;
static streams_info_t str_info = { ... };
static drv_ops_t
module_name
_str_drv_ops = { ... };
int
module_name
_load(void *arg)
{
int retval;
/* Use the drv_info passed to us instead of the static
* version */
drv_info_p = (drv_info_t *) arg;
str_info.inst_major = drv_info_p->c_major;
if (
module_name
_install())
return ENXIO;
return 0;
}
int
module_name
_install(void)
{
int retval;
/* Install in cdevsw */
if ((retval=install_driver(drv_info_p,
&
module_name
_str_drv_ops)) != 0)
return (retval); /* install failed */
/* Install in Streams */
if ((retval = str_install(&str_info)) != 0)
{
uninstall_driver(drv_info_p);
return retval;
}
return 0;
}