我在内核模块中创建了 WRITE_IOCTL 并在用户模式下调用它:
ioctl(fd, WRITE_IOCTL, "Hello, Kernel!");
在内核模式下,我有:
static int device_ioctl(struct file *filp,
unsigned int cmd, unsigned long args) {
char buff[14];
switch (cmd) {
case WRITE_IOCTL:
copy_from_user( buff,(char *)args, 14);
printk("This message received from User Space: %s\n", buff);
break;
}
return 0;
}
当我运行这个 ioctl 时,我在 /var/log/kern.log 中有一些类似论文的东西:
This message received from User Space: Hello, Kernel!vE�
This message received from User Space: Hello, Kernel!M�
This message received from User Space: Hello, Kernel!M�
我怎么解决这个问题??