Find the answer to your Linux question:
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 ...
  1. #1
    Just 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

    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);
    }
    thank you in advance!

    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

  2. #2
    Linux Guru Rubberman's Avatar
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...