1
votes

ioctl codes in Kernel modules are usually defined as macros inside .c or .h file, i.e.:

#define DRV_CTL_RESET          _IO(DRV_MAGIC, 0x01)
#define DRV_CTL_DSP_TO         _IO(DRV_MAGIC, 0x02)

and the usage in Userspace program is:

ioctl(drv_fd, DRV_CTL_DSP_TO, (unsigned long)tmo);

Everything is fine, but..

The problem is: what are good practices of synchronizing ioctl codes between Kernel and Userspace?

My current solution is to auto-generate an API header file from the source of Kernel module and include it in the Userspace program. But I hope, maybe there is a more convenient way.

1

1 Answers

2
votes

Just put the ioctl codes in a .h file, and use the same .h from kernel space and userspace. What could be more convenient than that? ;)