Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting inode from path in Linux Kernel

Tags:

linux

kernel

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?

like image 558
Dan Fego Avatar asked Nov 05 '22 21:11

Dan Fego


1 Answers

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.

like image 54
Scott Colby Avatar answered Nov 12 '22 13:11

Scott Colby