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.
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 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.
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.
Based on my experience with kernel, I suggest that you always go for top level functions like path_lookup rather than functions in the middle.