Question

I'm currently trying to get an inode for a given pathname in a kernel function. All I have available is the full pathname. I've tried attempts like:

user_path_at(AT_FDCWD, buffer, LOOKUP_FOLLOW, &path);

But the dentry in that given path isn't valid, it seems to turn out. Then I thought perhaps trying stat() and getting the inode number from that. However, that only gives me a number, not a struct inode. I don't know of a way to convert an inode number to an inode without grabbing an existing inode and traversing the entire list of inodes. And I don't even know if that would work. But I certainly don't want to do that.

Is there any simple way to get a struct inode from a char *pathname inside the kernel?

Was it helpful?

Solution

There is no easy way since struct inode is part of the kernel and you are in user space. It all depends on the particular filesystem implementation. Are you sure that info in stat struct is not enough for your needs?

Anyway, this link might help.

OTHER TIPS

stat() will give you the inode of a file in the "st_ino" field.

Sorry, initial misunderstanding of the question.

If you want the actual inode structure within the kernel, I'm pretty certain the kernel itself wouldn't walk an array or list looking for the inode number (unless the list is very small). Since the code to the kernel is publicly available, you should be able to find out how it does it, then do the same.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top