Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a linux kernel module, how can I get inode of a known path

In a linux kernel module (i.e. working in kernel space), I have a path of a file.

Which function(s) can be used to get the inode of that file. Specifically I need to get the "inode *" pointing to the file's inode.

like image 407
hayalci Avatar asked Nov 16 '09 15:11

hayalci


2 Answers

You don't have to open the file. There is a lookup function available in kernel which translates char *name to struct nameidata. Please refer to path_lookup.

You may also want to take a look at how path resolution algorithm works, here.

like image 96
Vinit Dhatrak Avatar answered Sep 17 '22 23:09

Vinit Dhatrak


You can use the filp_open function, but as stated in the comment of the function, opening files in kernel module is not something you want to do.

Here is a function that will return the struct file for your path. From there I think you can go to the inode

Bonus : May be this is not what you intend to do, but here is an article on file reading / writing from the kernel, and why you don't want to do it.

like image 37
shodanex Avatar answered Sep 20 '22 23:09

shodanex