mirror of
https://github.com/sysprog21/lkmpg.git
synced 2024-11-29 12:16:41 +08:00
d8216ff7b6
Previously ioctl.c is a userspace program for chardev2.c and chardev.h [1]. But now, this file is an independent kernel module, and the original code disappear. This patch adds back the original userspace code and renames it to userspace_ioctl.c. [1] https://tldp.org/LDP/lkmpg/2.4/html/x856.html
51 lines
1.5 KiB
C
51 lines
1.5 KiB
C
/*
|
|
* chardev.h - the header file with the ioctl definitions.
|
|
*
|
|
* The declarations here have to be in a header file, because they need
|
|
* to be known both to the kernel module (in chardev2.c) and the process
|
|
* calling ioctl() (in userspace_ioctl.c).
|
|
*/
|
|
|
|
#ifndef CHARDEV_H
|
|
#define CHARDEV_H
|
|
|
|
#include <linux/ioctl.h>
|
|
|
|
/* The major device number. We can not rely on dynamic registration
|
|
* any more, because ioctls need to know it.
|
|
*/
|
|
#define MAJOR_NUM 100
|
|
|
|
/* Set the message of the device driver */
|
|
#define IOCTL_SET_MSG _IOW(MAJOR_NUM, 0, char *)
|
|
/* _IOW means that we are creating an ioctl command number for passing
|
|
* information from a user process to the kernel module.
|
|
*
|
|
* The first arguments, MAJOR_NUM, is the major device number we are using.
|
|
*
|
|
* The second argument is the number of the command (there could be several
|
|
* with different meanings).
|
|
*
|
|
* The third argument is the type we want to get from the process to the
|
|
* kernel.
|
|
*/
|
|
|
|
/* Get the message of the device driver */
|
|
#define IOCTL_GET_MSG _IOR(MAJOR_NUM, 1, char *)
|
|
/* This IOCTL is used for output, to get the message of the device driver.
|
|
* However, we still need the buffer to place the message in to be input,
|
|
* as it is allocated by the process.
|
|
*/
|
|
|
|
/* Get the n'th byte of the message */
|
|
#define IOCTL_GET_NTH_BYTE _IOWR(MAJOR_NUM, 2, int)
|
|
/* The IOCTL is used for both input and output. It receives from the user
|
|
* a number, n, and returns message[n].
|
|
*/
|
|
|
|
/* The name of the device file */
|
|
#define DEVICE_FILE_NAME "char_dev"
|
|
#define DEVICE_PATH "/dev/char_dev"
|
|
|
|
#endif
|