一、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;

}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2021-07-26
  • 2022-02-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2022-02-10
  • 2021-06-06
相关资源
相似解决方案