Skip to Content
FreeBSD Device Drivers
book

FreeBSD Device Drivers

by Joseph Kong
April 2012
Intermediate to advanced
352 pages
8h
English
No Starch Press
Content preview from FreeBSD Device Drivers

Invoking ioctl

To invoke a d_ioctl function, you’d use the ioctl(2) system call.

#include <sys/ioctl.h>

int
ioctl(int d, unsigned long request, ...);

The d argument, which stands for descriptor, expects a file descriptor for a device node. The request argument is the ioctl command to be issued (for example, ECHO_CLEAR_BUFFER). The remaining argument (...) is a pointer to the data that’ll be passed to the d_ioctl function.

Example 3-2 presents a command-line utility designed to invoke the echo_ioctl function in Example 3-1:

Example 3-2. echo_config.c

#include <sys/types.h>
  #include <sys/ioctl.h>

  #include <err.h>
  #include <fcntl.h>
  #include <limits.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include <unistd.h>

 #define ECHO_CLEAR_BUFFER       _IO('E', 1)
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Embedded Linux

Embedded Linux

John Lombardo
Essential Linux Device Drivers

Essential Linux Device Drivers

Sreekrishnan Venkateswaran

Publisher Resources

ISBN: 9781457166716Errata