I am attepting to write a Linux Kernel Module for the Raspberry Pi. All is good, except that when I try to use either copy_to_user, or put_user, it always returns a value of "34336" if I print it as an llu, and if I print it as a character, it is nothing.
The interesting thing is that it was working, I made some changes, it stopped working, I reverted back to the working version, and it no longer works.
Code from module:
ssize_t st_read(struct file *filp, char *buf, size_t count, loff_t *f_pos)
{
char memory_buffer = 'b';
/* Transferring data to user space */
copy_to_user(buf,memory_buffer,1);
/* Changing reading position as best suits */
if (*f_pos == 0) {
*f_pos+=1;
return 1;
} else {
return 0;
}
}
Code reading value:
fd = open("/dev/systimer", O_RDONLY);
// check for errors
if(fd < 0) {
perror("open(O_RDONLY)");
return errno;
} else
close(fd);
read(fd, &buf, 1);
printf("Buffer: %llu\n", buf);
printf("Buffer2: %c\n", buf);
Output is:
Buffer: 34336
Buffer2:
Thanks.