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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With