gpt4 book ai didi

c - ioctl调用程序编译错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:06:11 25 4
gpt4 key购买 nike

我想用 c 程序从用户空间调用内核模块 driver.ko ioctl。编译时出现此错误

header.h:13:38: error: expected expression before ‘char’
#define IOCTL_CMD _IORW(MAGIC_NO, 0, char *)

根据定义,我输入了正确的参数:_IORW(int type, int number, data_type)

主.c

#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include "header.h"

int main()
{
int fd;
char * msg = "5";
fd = open(DEVICE_PATH, O_RDWR);
ioctl(fd, IOCTL_CMD, msg);
printf("ioctl executed\n");
close(fd);
return 0;
}

标题.h

#include <linux/ioctl.h>
#include <linux/kdev_t.h> /* for MKDEV */

#define DEVICE_NAME "driver"
#define DEVICE_PATH "/dev/driver"
#define WRITE 0
static int major_no;

#define MAGIC_NO '4'
/*
* Set the message of the device driver
*/
#define IOCTL_CMD _IORW(MAGIC_NO, 0, char *)

最佳答案

_IORW 似乎不存在于 Linux header 中,请尝试使用 _IOWR 代替。我也不认为你在这里使用 char * 是正确的。这意味着 ioctl 的最后一个参数是 char * 变量的地址,而不是字符串。

关于c - ioctl调用程序编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25185767/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com