Managing and Developing Dynamically Loadable Kernel Modules

Managing and Developing Dynamically Loadable Kernel Modules
Developing Dynamically Loadable Kernel Modules
Chapter 12546
return (wsio_install_driver(&wsio_info);
}
/* Common attach function for both dynamic and
* static modules */
int
module_name
_attach(int id, struct isc_table_type *isc)
{
/* Normal attach function operations */
...
}
/* Attach function called from attach chain for static modules
* only
*/
int
module_name
_attach_linked (int id, struct isc_table_type *isc)
{
module_name
_attach(id, isc);
return ((*
module_name
_saved_attach)(id, isc));
}
The _unload() function determines if the driver is still busy, and if not,
it cleans up all resources that were obtained by the driver. It should free
memory that it allocated and remove the attach() function from the
attach list. It should also unregister any _probe() function pointers
that the driver has registered with other kernel services; for example,
the _unload() function should unlink the interrupt service function. If
an operation fails while unloading, the _unload() function must be able
to restore the driver to a working state and return a nonzero value.
Unlike class drivers, there is no automatic method for the system to
determine if an interface driver is still busy. This problem can sometimes
be avoided by making class drivers that use the interface driver
dependent upon the interface driver. With this dependency relationship
in place, the system will not allow the interface driver to be unloaded as
long as any class driver that depends upon it is still loaded. If it is not
appropriate for the interface driver to rely on dependencies, then it must
determine via other means if it is possible to unload the driver. The
_unload() function is always free to return a nonzero value, and the
module will remain loaded. A sample _unload() function for a WSIO
interface driver is as follows: