hayalci
hayalci

Reputation: 4119

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.

Upvotes: 6

Views: 6678

Answers (3)

Boolean
Boolean

Reputation: 14660

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.

Upvotes: 1

Vinit Dhatrak
Vinit Dhatrak

Reputation: 7054

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.

Upvotes: 5

shodanex
shodanex

Reputation: 15456

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.

Upvotes: 1

Related Questions