IOCTL Linux device driver -
can explain me,
- what
ioctl
? - what used for?
- how can use it?
- why can't define new function same work
ioctl
?
an ioctl
, means "input-output control" kind of device-specific system call. there few system calls in linux (300-400), not enough express unique functions devices may have. driver can define ioctl allows userspace application send orders. however, ioctls not flexible , tend bit cluttered (dozens of "magic numbers" work... or not), , can insecure, pass buffer kernel - bad handling can break things easily.
an alternative sysfs
interface, set file under /sys/
, read/write information , driver. example of how set up:
static ssize_t mydrvr_version_show(struct device *dev, struct device_attribute *attr, char *buf) { return sprintf(buf, "%s\n", driver_release); } static device_attr(version, s_irugo, mydrvr_version_show, null);
and during driver setup:
device_create_file(dev, &dev_attr_version);
you have file device in /sys/
, example, /sys/block/myblk/version
block driver.
another method heavier use netlink, ipc (inter-process communication) method talk driver on bsd socket interface. used, example, wifi drivers. communicate userspace using libnl
or libnl3
libraries.
Comments
Post a Comment