Cheap website hosting service by Active-Venture.com
  

Domain Registration -
Domain registration and domain transfer  service from just
$5.95/year only

 

Domain Name Registration -
Cheap domain name registration by Cheap Domain Name Registrar.

 Back to Index

13.2 Dynamic Kernel Linker Facility - KLD

The kld interface allows system administrators to dynamically add and remove functionality from a running system. This allows device driver writers to load their new changes into a running kernel without constantly rebooting to test changes.

The kld interface is used through the following privileged commands:

  • kldload - loads a new kernel module

  • kldunload - unloads a kernel module

  • kldstat - lists the currently loaded modules



Skeleton Layout of a kernel module

/*
 * KLD Skeleton
 * Inspired by Andrew Reiter's Daemonnews article
 */

#include <sys/types.h>
#include <sys/module.h>
#include <sys/systm.h>  /* uprintf */ 
#include <sys/errno.h>
#include <sys/param.h>  /* defines used in kernel.h */
#include <sys/kernel.h> /* types used in module initialization */

/* 
 * Load handler that deals with the loading and unloading of a KLD.
 */

static int
skel_loader(struct module *m, int what, void *arg)
{
  int err = 0;
  
  switch (what) {
  case MOD_LOAD:                /* kldload */
    uprintf("Skeleton KLD loaded.\n");
    break;
  case MOD_UNLOAD:
    uprintf("Skeleton KLD unloaded.\n");
    break;
  default:
    err = EINVAL;
    break;
  }
  return(err);
}

/* Declare this module to the rest of the kernel */

static moduledata_t skel_mod = {
  "skel",
  skel_loader,
  NULL
};  

DECLARE_MODULE(skeleton, skel_mod, SI_SUB_KLD, SI_ORDER_ANY);

13.2.1 Makefile

FreeBSD provides a makefile include that you can use to quickly compile your kernel addition.

SRCS=skeleton.c
KMOD=skeleton

.include <bsd.kmod.mk>

Simply running make with this makefile will create a file skeleton.ko that can be loaded into your system by typing:

# kldload -v ./skeleton.ko



 

  

 

 

© 2002-2004 Active-Venture.com Website Hosting Service

 

Disclaimer: This documentation is provided only for the benefits of our website hosting customers.
For authoritative source of the documentation, please refer to http://www.freebsd.org