tags:

views:

668

answers:

2

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?

+1  A: 

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.

paxdiablo
I already noted that in my post. However, that only gives me the inode number, not the struct inode necessary to get at the information about the file.
Dan Fego
+1  A: 

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.

Milan Babuškov
It just hit me (after about 3 hours) that stat() will suffice for my needs, since I only need the information. I became so hell-bent on getting the inode that I partially lost sight of my goal. And I'm doing this from within the kernel. So performing stat() is actually not optimal, but will do.
Dan Fego