Messages in this thread | | | Date | Tue, 16 Nov 1999 21:08:11 -0500 | From | "Theodore Y. Ts'o" <> | Subject | Re: Drivers in 2.2.x: Best way to get minor number from within xxx_read() |
| |
From: Drew Bertola <drew@drewb.com> Date: Tue, 16 Nov 1999 17:51:27 -0800 (PST)
The problem I have is that I don't want to grab the offset from tsio_open() and store it in a static int as that would not allow simultaneous opens of different ports.
I am now using filp->private_data to hold the minor and them accessing it to find the offset within each tsio_read() / tsio_write(), but that seems akward. Does anyone have a suggestion as to a better way to do this or an explanation as to why I can't MINOR(inode->i_rdev) within the read / write operations themselves?
Usually what is done is in open() call, the open call allocates a structure, and places a pointer to that structure in filp->private_data. This allows the driver to store various bits of state information, either pre-calculated at device open time, or for state information which is associated with the open file descriptor.
If you *only* need the I/O port offset, and you're willing to calculate it each time in the read() and write() call, you can get access to the inode from those functions. Just reference it as filp->f_dentry->d_inode. So for example you can get the minor number by calculating MINOR(filp->f_dentry->d_inode).
Hope this helps!
- Ted
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |