Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm trying to use the function copy_to_user() to transfer an integer into user space but it transfers only 1 byte. For example, if I try to transfer the integer 300, it transfers only the first byte from 300:
300=12Ch
in this case only 2Ch will be transfered, so in the user space, with the function fread(), I get always 44 (44 = 2Ch). I have tried to change the parameters from fread(), to take more bytes, but it didn't work. I'm still getting only 1 byte per transfer.
ssize_t read(struct file *filp, int __user *buff,
size_t count, loff_t *offp)
{
int value;
copy_to_user(buf, &value,4);
return 1;
}
This is a simplfied version of this function's implementation. The rest is the same as in the "linux Device Drivers" book.
thank you for your help
Leonardo
You should return the number of bytes read (not 1, but 4). Other than that, it looks OK (except you never actually assign to value, and you have an extra ‘f’ in one of your variable names).
Btw, you if you enclose sourcecode like this: [code]Paste code here[/code], it is easier to read on the forum.
fread should return how many data elements have been succesfully read. And that should go to same value as count, if I understood correctly. If I increase size from 1 that means bytes_read goes to zero. File size seems also to be 1B. Is this how it should be ??
As I said only first data byte gets through and I have hard time figuring that out...
Fixed it now. I had a couple of mishaps there. One of them was to somehow mix size and count in fread. Silly me!
Last edited by bay_sic; 02-27-2008 at 01:52 AM.
Reason: Fixed it.
copy_to _user(__user *buf,__ker *buf,count) is transmit the address,and it has the bits limit (8 bit at most), the value count is to point out how many values that will transmit at the address
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.