【发布时间】:2014-09-30 21:17:00
【问题描述】:
我想用c程序从用户空间调用内核模块driver.koioctl。编译时出现此错误
header.h:13:38: error: expected expression before ‘char’
#define IOCTL_CMD _IORW(MAGIC_NO, 0, char *)
根据定义,我提出了正确的论点:_IORW(int type, int number, data_type)
main.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;
}
header.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 *)
【问题讨论】:
-
你可能想看看这个问题:stackoverflow.com/questions/2264384/…
标签: c linux kernel-module ioctl