Skip to Content
Linux Device Drivers Development
book

Linux Device Drivers Development

by John Madieu
October 2017
Intermediate to advanced
586 pages
14h 8m
English
Packt Publishing
Content preview from Linux Device Drivers Development

Steps for ioctl

First, let's have a look at its prototype. It looks as follows:

long ioctl(struct file *f, unsigned int cmd, unsigned long arg); 

There is only one step: use a switch ... case statement and return an -ENOTTY error when an undefined ioctl command is called. You can find more information at http://man7.org/linux/man-pages/man2/ioctl.2.html:

/* * User space code also need to include the header file in which ioctls * defined are defined. This is eep_ioctl.h in our case. */ #include "eep_ioctl.h" static long eep_ioctl(struct file *f, unsigned int cmd, unsigned long arg) { int part; char *buf = NULL; int size = 1300; switch(cmd){ case EEP_ERASE: erase_eeprom(); break; case EEP_RENAME_PART: buf = kmalloc(MAX_PART_NAME, GFP_KERNEL); ...
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

Linux Device Drivers, Second Edition

Linux Device Drivers, Second Edition

Jonathan Corbet, Alessandro Rubini
Linux Device Drivers, 3rd Edition

Linux Device Drivers, 3rd Edition

Jonathan Corbet, Alessandro Rubini, Greg Kroah-Hartman

Publisher Resources

ISBN: 9781785280009Supplemental Content