O'Reilly logo

FreeBSD Device Drivers by Joseph Kong

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing sysctls, Part 2

Now that you know how to create sysctls during runtime, let’s do some actual device control (as opposed to quoting Monty Python).

Example 3-4 is a revision of Example 3-1 that employs a sysctl to resize the memory buffer.

Note

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 3-4. echo-4.0.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> #include <sys/ioccom.h> #include <sys/sysctl.h> MALLOC_DEFINE(M_ECHO, "echo_buffer", "buffer for echo driver"); #define ECHO_CLEAR_BUFFER _IO('E', 1) static d_open_t echo_open; static d_close_t ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required