|
|
The following coding examples show some typical wrappers for the different loadable module types. Note that all loadable modules must include <sys/moddefs.h> in their wrapper definitions.
``Generic device driver wrapper coding example'' shows a sample wrapper for a device driver.
Generic device driver wrapper coding example
#include <sys/moddefs.h>. . .
#define DRVNAME "fd - Floppy disk driver"
STATIC int fd_load(), fd_unload();
MOD_DRV_WRAPPER(fd, fd_load, fd_unload, NULL, DRVNAME);
STATIC int fd_load() { fdinit(); mod_drvattach(&fd_attach_info); fdstart();
return(0); }
STATIC int fd_unload() { mod_drvdetach(&fd_attach_info);
. . .
return(0); }
``File system module wrapper coding example'' shows a sample wrapper for a file system module. Notice that this file system module does not need to do any clean-up when it is unloaded, so its wrapper defines a NULL _unload( ) routine.
File system module wrapper coding example
#include <sys/moddefs.h>STATIC int s5_load(void);
MOD_FS_WRAPPER(s5, s5_load, NULL, "Loadable s5 FS Type");
STATIC int s5_load(void) { inoinit();
bzero((caddr_t)&s5fshead, sizeof(s5fshead)); s5fshead.f_freelist = &s5ifreelist; s5fshead.f_inode_cleanup = s5_cleanup; s5fshead.f_maxpages = 1; s5fshead.f_isize = sizeof (struct inode); s5fshead.f_max = ninode;
fs_ipoolinit(&s5fshead); return 0; }
``Miscellaneous module wrapper coding example'' shows a sample wrapper for a miscellaneous module. Notice that, once loaded, this module wants to remain loaded, so its _unload( ) routine always returns EBUSY.
Miscellaneous module wrapper coding example
#include <sys/moddefs.h>STATIC int clis_load(), clis_unload();
MOD_MISC_WRAPPER(clis, clis_load, clis_unload, "clist - character io"); . . .
STATIC int clis_load() { . . .
cinit(); return(0); }
STATIC int clis_unload() { /* * This module can not be unloaded. */ return(EBUSY); }