I have written a small character device driver.
I want to add a semaphore to it.
Any idea as what should I be doing.
How I have implemented my code is
I defined four functions in
struct file_operation
as open,read,write,release
I register my device using register_chrdev
now how do I implement a semaphore or mutex so that if 10 process try to access same device or write
some thing to the file they do not do it.Which may give undesired results.
Though I have written my driver I am not clear
as how the user space program implements it.
What my device is doing is
echo -n ddt >> /dev/bond
it will write ddt to /dev/bond
I am not clear as when echo is used which system calls (fopen,fread,fwrite)
are working
in back ground which in turn communicate with my device driver.
My driver does define open,read,write,close function but how as user space system call is accessing it that I am not clear.
So that I can implement some sort of lock in it.