【发布时间】:2014-10-27 23:39:18
【问题描述】:
我尝试从用户空间程序传递两个参数来更改 char 设备上的缓冲区大小和缓冲区数。我尝试了多次投射,但总是出现投射错误
error: cannot convert to a pointer type copy_from_user((char *)msg, arg, sizeof(msg));
或
cannot convert to a pointer typecopy_from_user((char *)msg, (char *)arg, sizeof(msg));
header.h
struct ioctl_arguments {
int block_number;
int block_size;
};
内核模块和c程序都包含header.h
c 程序
#define DEVICE_PATH "/dev/driver"
#define MAGIC_NO 'k'
struct ioctl_arguments args;
#define IOCTL_CMD _IOWR(MAGIC_NO, 0, args)
int main()
{
int fd;
args.block_number = 10;
args.block_size = 10;
fd = open(DEVICE_PATH, O_RDWR);
ioctl(fd, IOCTL_CMD,&args);
close(fd);
return 0;
}
设备驱动
static int BlockNumber = 20;
static int BlockSize = 5;
struct ioctl_arguments msg;
static int sample_ioctl (struct file *filp, unsigned int cmd, unsigned long arg);
static int sample_ioctl (struct file *filp, unsigned int cmd, unsigned long arg)
{
// copy two parameters from outside, we use struct
copy_from_user((char *)msg, (char *)arg, sizeof(msg));
【问题讨论】:
标签: c kernel-module ioctl