chardev.h 1.5 KB

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