FreeBSD/share/examples/kld/cdev/module/cdevmod.c
/*
 * This function is called each time the module is loaded or unloaded.
 * Since we are a miscellaneous module, we have to provide whatever
 * code is necessary to patch ourselves into the area we are being
 * loaded to change.
 *
 * The stat information is basically common to all modules, so there
 * is no real issue involved with stat; we will leave it lkm_nullcmd(),
 * since we don't have to do anything about it.
 */
This function is called each time the module is loaded or unloaded.
Since we are a miscellaneous module, we have to provide whatever
code is necessary to patch ourselves into the area we are being
loaded to change.

The stat information is basically common to all modules, so there
is no real issue involved with stat; we will leave it lkm_nullcmd(),
since we don't have to do anything about it.
This function is called each time the module is loaded or unloaded . Since we are a miscellaneous module we have to provide whatever code is necessary to patch ourselves into the area we are being loaded to change . The stat information is basically common to all modules so there is no real issue involved with stat ; we will leave it lkm_nullcmd () since we don ' t have to do anything about it .
static int
cdev_load(module_t mod, int cmd, void *arg)
{
    int  err = 0;
    switch (cmd) {
    case MOD_LOAD:
	printf("\nSample Loaded kld character device driver\n");
	printf("Copyright (c) 1998\n");
	printf("Rajesh Vaidheeswarran\n");
	printf("All rights reserved\n");
	sdev = make_dev(&my_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "cdev");
	break;		
    case MOD_UNLOAD:
	printf("Unloaded kld character device driver\n");
	destroy_dev(sdev);
	break;		
    default:	
	err = EOPNOTSUPP;
	break;
    }
    return(err);
}
static int cdev_load ( module_t mod , int cmd , void * arg ) { int err = 0 ; switch ( cmd ) { case MOD_LOAD : printf ( " \n \n " ) ; printf ( " \n " ) ; printf ( " \n " ) ; printf ( " \n " ) ; sdev = make_dev ( & my_devsw , 0 , UID_ROOT , GID_WHEEL , 0600 , " " ) ; break ; case MOD_UNLOAD : printf ( " \n " ) ; destroy_dev ( sdev ) ; break ; default : err = EOPNOTSUPP ; break ; } return ( err ) ; }
This function is called each time the module is loaded or unloaded.
This function is called each time the module is loaded or unloaded .
/* Do any initialization that you should do with the kernel */ /* if we make it to here, print copyright on console*/ /* Success*/ /* Success*/ /* we only understand load/unload*/