Search code examples
clinuxlinux-kernelioctlinode

Where do you get inode functionality from?


I've got some linux drivers I'm trying to port from linux 2.4 to 3.0. During this lengthy span of time, the argument list of ioctl (unlocked_ioctl now) changed a bit:

-static int can_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
+static long can_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 

The code was using the inode to get the minor version and was passing it to some other commands. Now that inode isn't a "free-be" given in the ioctl parameter list, how can I get it?

Is it possible to derive from the file pointer? or should I "save" a global pointer to it when it shows up in the _open() method? I'd rather avoid that if there's a better way.


Solution

  • oop, just figured it out by poking around the kernel and looking at other drivers (don't know why it didn't occur to me to do that before). In case anyone else is interested you can get the inode from the file pointer passed into the ioctl as such:

    long can_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
    {
        struct inode *inode = file->f_path.dentry->d_inode;
    

    If anyone knows why this is a bad idea (I just took it from another driver), or if there's a better/preferred way let me know.