一、Copy_to_user( to, &from, sizeof(from))
To:用戶空間函數 (可以是數組)
From:內核空間函數(可以是數組)
sizeof(from):內核空間要傳遞的數組的長度
二、Copy_from_user(&from , to , sizeof(to) )
To:用戶空間函數 (可以是數組)
From:內核空間函數(可以是數組)
sizeof(from):內核空間要傳遞的數組的長度
成功返回0,
失敗返回失敗數目。
例子:
static ssize_t keys4_read(struct inode *inode, char *buf, unsigned long count,loff_t *ppos)
{
int co;
char buff[2];
buff[0] = times3;
buff[1] = times4;
if((co=copy_to_user(buf ,&buff , sizeof(buff))))
return -EFAULT;
else printk("copy to user is okn");
Return 1;
}