1
0

chardev.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * chardev.h - the header file with the ioctl definitions.
  3. *
  4. * The declarations here have to be in a header file, because they need
  5. * to be known both to the kernel module (in chardev2.c) and the process
  6. * calling ioctl() (in userspace_ioctl.c).
  7. */
  8. #ifndef CHARDEV_H
  9. #define CHARDEV_H
  10. #include <linux/ioctl.h>
  11. /* The major device number. We can not rely on dynamic registration
  12. * any more, because ioctls need to know it.
  13. */
  14. #define MAJOR_NUM 100
  15. /* Set the message of the device driver */
  16. #define IOCTL_SET_MSG _IOW(MAJOR_NUM, 0, char *)
  17. /* _IOW means that we are creating an ioctl command number for passing
  18. * information from a user process to the kernel module.
  19. *
  20. * The first arguments, MAJOR_NUM, is the major device number we are using.
  21. *
  22. * The second argument is the number of the command (there could be several
  23. * with different meanings).
  24. *
  25. * The third argument is the type we want to get from the process to the
  26. * kernel.
  27. */
  28. /* Get the message of the device driver */
  29. #define IOCTL_GET_MSG _IOR(MAJOR_NUM, 1, char *)
  30. /* This IOCTL is used for output, to get the message of the device driver.
  31. * However, we still need the buffer to place the message in to be input,
  32. * as it is allocated by the process.
  33. */
  34. /* Get the n'th byte of the message */
  35. #define IOCTL_GET_NTH_BYTE _IOWR(MAJOR_NUM, 2, int)
  36. /* The IOCTL is used for both input and output. It receives from the user
  37. * a number, n, and returns message[n].
  38. */
  39. /* The name of the device file */
  40. #define DEVICE_FILE_NAME "char_dev"
  41. #define DEVICE_PATH "/dev/char_dev"
  42. #endif