Discussion:
copy_to_user vs sprintf
(too old to reply)
Hagit
2004-01-28 09:51:34 UTC
Permalink
I just cant get it!
I wrote a module that created its own entry in the /proc file system.
My module implemented read and write functions. When the user call
read(fd, &buff, 1) I am trying to copy to the user buff the character
B. When I use the
copy_to_user() function, the user doesnt get my B, but when I use the
sprintf() function the user gets the B. I cant understand it. what is
wrong???
The relevant calls are described below:

char raed_info = 'B';

copy_to_user(page, &read_info, sizeof(read_info));

sprintf(page,"%c",read_info);


Thanks
Hagit
Josef Möllers
2004-01-28 10:36:24 UTC
Permalink
Post by Hagit
I just cant get it!
I wrote a module that created its own entry in the /proc file system.
My module implemented read and write functions. When the user call
read(fd, &buff, 1) I am trying to copy to the user buff the character
B. When I use the
copy_to_user() function, the user doesnt get my B, but when I use the
sprintf() function the user gets the B. I cant understand it. what is
wrong???
char raed_info = 'B';
copy_to_user(page, &read_info, sizeof(read_info));
sprintf(page,"%c",read_info);
The "copy_to_user" is done when the procfs-function returns (check
fs/proc/generic.c::proc_file_read()).
What you have in "page" is not a user-virtual address but a
kernel-virtual address.

Just use "memcpy" rather than "copy_to_user".

Josef
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
Loading...