ret=copy_from_user(&tmp->value,buff++,1); 返回值为0,可以读出的结果是正确的。

63 views
Skip to first unread message

Dean Sinaean

unread,
May 14, 2010, 7:46:56 AM5/14/10
to linux-kernel
ret=copy_from_user(&tmp->value,buff++,1);
我用这句话向内核中的链表写入数据。读出来的是正确的数据。但是这个函数本身返回来的值却是0,这是为什么呢?
_______________________________________________
Linux 内核开发中文邮件列表
Linux-...@zh-kernel.org
http://zh-kernel.org/mailman/listinfo/linux-kernel
Linux 内核开发中文社区: http://zh-kernel.org

--
这是zh-kernel邮件列表内容的只读归档,如果想参与讨论请访问http://zh-kernel.org进行订阅。

. dyron

unread,
May 15, 2010, 10:26:46 PM5/15/10
to Dean Sinaean, linux-kernel
copy正功,将返回0,看注释红色部分
/**
* copy_from_user: - Copy a block of data from user space.
* @to: Destination address, in kernel space.
* @from: Source address, in user space.
* @n: Number of bytes to copy.
*
* Context: User context only. This function may sleep.
*
* Copy data from user space to kernel space.
*
* * **Returns number of bytes that could not be copied.
* On success, this will be zero.
* *
* If some data could not be copied, this function will pad the copied
* data to the requested size using zero bytes.
*/
unsigned long
copy_from_user(void *to, const void __user *from, unsigned long n)
{
BUG_ON((long) n < 0);
if (access_ok(VERIFY_READ, from, n))
n = __copy_from_user(to, from, n);
else
memset(to, 0, n);
return n;
Reply all
Reply to author
Forward
0 new messages