October 2017
Intermediate to advanced
586 pages
14h 8m
English
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); ...