Results 1 to 2 of 2
Hi there,
how are you doing?
I am writing a simple char device that generates pseudo-random numbers, the problem is that I cant seem to figure out how to test ...
- 06-16-2009 #1Just Joined!
- Join Date
- May 2009
- Posts
- 35
how can I read from a char device?
Hi there,
how are you doing?
I am writing a simple char device that generates pseudo-random numbers, the problem is that I cant seem to figure out how to test it, i tired using "cat /dev/(device's name)" but all i get is an infinite loop, though that happens as well when i use cat on other devices in the /dev dictionary.
anyone can help me out please?
here is the code of my read function of my device
thank you in advance!Code:ssize_t read(struct file *file, char __user *buf, size_t len, loff_t *offset) { ssize_t ret = 0; if(copy_to_user(buf, (int)rg_hw(), (int)len)) { return -EFUALT; } return ret; } unsigned char rg_hw() { random_seed = random_seed * 32423423 + 12324; return (unsigned char)((unsigned int)(random_seed /234234) % 256); }
EDIT: upon further testing i think the problem is with my read function, i think i misused copy_to_user. but i dont whats wrong with it, any ideas
- 06-16-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Questions about kernel programming issues should be posted to The Linux Kernel forum. Please move your question there.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote