Reputation: 2728
I'm implementing a Character Driver. So I'm registering file operations. When I'm registering read
function i extracted minor
number this way
myread(struct file * file, char __user * ubuf, size_t lbuf, loff_t *offset)
{
int minor;
minor = MINOR(file->f_path.dentry->d_inode->f_pos->i_rdev);
.......
This rule will apply to open
call too.
myopen(struct inode * inode, struct file * file)
struct file
definition have the reference to struct inode
. So one argument is enough for open
call.
My questions are:
open
have two arguments? (or) why read
don't have struct inode *
argument?read
call, i used above instruction. To find the definions and header files it took 1hr 30min to me. Is there any easy way to find the definitions of structures?struct inode
through struct file
and what is the best way?Upvotes: 3
Views: 2370
Reputation: 180050
You must not use that construction to search for the inode; the file or even directory might have been deleted after the file was opened.
The kernel convention (see chapter 3 of Linux Device Drivers) is that
in your open
function, you look up your own data from the inode (or allocate your own data), and set the file->private_data
pointer; and
in your read
function, you then use file->private_data
to access your own stuff.
Upvotes: 4