copy_to_user,copy_from_use…

来源:互联网 发布:返利网是淘宝客吗 编辑:程序博客网 时间:2024/05/24 05:48
原文地址:copy_to_user,copy_from_user,get_user,put_user函数作者:卓俊

copy_to_user,copy_from_user,get_user,put_user函数比较

copy_to_user-- Copy a block of data into user space.

copy_from_user-- Copy a block of data from user space.

get_user-- Get a simplevariable from user space.

put_user-- Write a simple value into user space.

copy_from_user

Name

copy_from_user-- Copy a block of data from user space.

Synopsis

unsigned long copy_from_user (void *to, const void __user * from, unsigned longn);

Arguments

to

Destinationaddress, in kernel space.

from

Sourceaddress, in user space.

n

Number ofbytes to copy.

Context

User contextonly. This function may sleep.

Description

Copy datafrom user space to kernel space.

Returnsnumber of bytes that could not be copied. On success, this will bezero.

If some datacould not be copied, this function will pad the copied data to therequested size using zero bytes.

 

copy_to_user

Name

copy_to_user --Copy a block of data into user space.

Synopsis

unsigned long copy_to_user (void__user * to, const void * from, unsigned longn);

Arguments

to

Destinationaddress, in user space.

from

Sourceaddress, in kernel space.

n

Number ofbytes to copy.

Context

User contextonly. This function may sleep.

Description

Copy datafrom kernel space to user space.

Returnsnumber of bytes that could not be copied. On success, this will bezero.

put_user

Name

put_user --Write a simple value into user space.

Synopsis

put_user ( x,ptr);

Arguments

x

Value tocopy to user space.

ptr

Destinationaddress, in user space.

Context

User contextonly. This function may sleep.

Description

This macrocopies a single simple value from kernel space to user space. Itsupports simple types like char and int, but not larger data typeslike structures or arrays.

ptr musthave pointer-to-simple-variable type, and x must be assignable tothe result of dereferencing ptr.

Returns zeroon success, or -EFAULT on error.

get_user

Name

get_user -- Geta simple variable from user space.

Synopsis

get_user ( x,ptr);

Arguments

x

Variable tostore result.

ptr

Sourceaddress, in user space.

Context

User contextonly. This function may sleep.

Description

This macrocopies a single simple variable from user space to kernel space. Itsupports simple types like char and int, but not larger data typeslike structures or arrays.

ptr musthave pointer-to-simple-variable type, and the result ofdereferencing ptr must be assignable to x without acast.

Returns zeroon success, or -EFAULT on error. On error, the variable x is set tozero.

原创粉丝点击