Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Example 2-2 modifies Example 2-1 to use contigmalloc and contigfree instead of malloc and free. Example 2-2 should clarify any misunderstandings you may have about contigmalloc and contigfree.
To save space, the functions echo_open, echo_close, echo_write, and echo_read aren’t listed here, as they haven’t been changed.
Example 2-2. echo_contig.c
#include <sys/param.h>
#include <sys/module.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/uio.h>
#include <sys/malloc.h>
#define BUFFER_SIZE 256
MALLOC_DEFINE(M_ECHO, "echo_buffer", "buffer for echo driver");
static d_open_t echo_open;
static d_close_t echo_close;
static d_read_t echo_read;
static d_write_t echo_write;
static struct cdevsw echo_cdevsw = {
.d_version = D_VERSION,
.d_open = echo_open,
.d_close = echo_close,
.d_read = echo_read,
.d_write = echo_write,
.d_name = "echo"
};
typedef struct echo {
char buffer[BUFFER_SIZE];
int length;
} echo_t;
static echo_t....





