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

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

What function can be used to get the inode of this file. In particular, I need to get "inode *" pointing to the inode file.

+4
source share
3 answers

You do not need to open the file. There is a search function in the kernel that translates char *name to struct nameidata . See path_lookup .

You can also see how the path resolution algorithm works here .

+5
source

You can use the filp_open function, but as pointed out in the comment on the function, opening files in the kernel module is not what you want to do.

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

Bonus: Perhaps this is not what you intend to do, but here is an article about reading / writing files from the kernel, and why you do not want to do this.

+1
source

Based on my experience with the kernel, I suggest you always use top-level functions, such as path_lookup, rather than functions in the middle.

+1
source

All Articles