Rishi Agrawal | 7 Aug 2012 16:41
Picon

How to get the inode - no path_lookup

Hi All,


I had a module which used the path_lookup function to print the details of any file's inode. I now want to rewrite that module in order to show some juniors how to write some code in kernel.

I am using 3.4.6 kernel, I tried finding out path_lookup but google showed that it has been removed.

I tried the following code then which did not work

.
.
.
dentry = kern_path_create(AT_FDCWD, filename, &path, 1);

if (IS_ERR(dentry)) {
              printk("Failed to obtain the dentry");
               return;
       }

its not returning dentry

I again tried after seeing the implementation of vfs_stat function

user_path_at(AT_FDCWD, filename, lookup_flags, &path);

but this also fails.


I am using a proc interface to pass the filename, and copying the filename into a kernel buffer.

How can I get a copy of vfs inode for a file name.


--
Regards,
Rishi Agrawal

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Rohan Puri | 8 Aug 2012 09:16
Picon
Gravatar

Re: How to get the inode - no path_lookup



On Tue, Aug 7, 2012 at 8:11 PM, Rishi Agrawal <rishi.b.agrawal <at> gmail.com> wrote:
Hi All,


I had a module which used the path_lookup function to print the details of any file's inode. I now want to rewrite that module in order to show some juniors how to write some code in kernel.

I am using 3.4.6 kernel, I tried finding out path_lookup but google showed that it has been removed.

I tried the following code then which did not work

.
.
.
dentry = kern_path_create(AT_FDCWD, filename, &path, 1);

if (IS_ERR(dentry)) {
              printk("Failed to obtain the dentry");
               return;
       }

its not returning dentry

I again tried after seeing the implementation of vfs_stat function

user_path_at(AT_FDCWD, filename, lookup_flags, &path);

but this also fails.


I am using a proc interface to pass the filename, and copying the filename into a kernel buffer.

How can I get a copy of vfs inode for a file name.


Need to use vfs_path_lookup for this, present in fs/namei.c file, which would give you filled nameidata nd that contais inodes pointer.
--
Regards,
Rishi Agrawal


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


- Rohan
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Rishi Agrawal | 9 Aug 2012 05:15
Picon

Re: How to get the inode - no path_lookup



On Wed, Aug 8, 2012 at 12:46 PM, Rohan Puri <rohan.puri15 <at> gmail.com> wrote:


On Tue, Aug 7, 2012 at 8:11 PM, Rishi Agrawal <rishi.b.agrawal <at> gmail.com> wrote:
Hi All,


I had a module which used the path_lookup function to print the details of any file's inode. I now want to rewrite that module in order to show some juniors how to write some code in kernel.

I am using 3.4.6 kernel, I tried finding out path_lookup but google showed that it has been removed.

I tried the following code then which did not work

.
.
.
dentry = kern_path_create(AT_FDCWD, filename, &path, 1);

if (IS_ERR(dentry)) {
              printk("Failed to obtain the dentry");
               return;
       }

its not returning dentry

I again tried after seeing the implementation of vfs_stat function

user_path_at(AT_FDCWD, filename, lookup_flags, &path);

but this also fails.


I am using a proc interface to pass the filename, and copying the filename into a kernel buffer.

How can I get a copy of vfs inode for a file name.


Need to use vfs_path_lookup for this, present in fs/namei.c file, which would give you filled nameidata nd that contais inodes pointer.
--
Regards,
Rishi Agrawal


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


- Rohan

vfs_path_lookup needs a dentry/mountpoint for the current path.

How will I get those.


/**
 * vfs_path_lookup - lookup a file path relative to a dentry-vfsmount pair
 * <at> dentry:  pointer to dentry of the base directory
 * <at> mnt: pointer to vfs mount of the base directory
 * <at> name: pointer to file name
 * <at> flags: lookup flags
 * <at> path: pointer to struct path to fill
 */


--
Regards,
Rishi Agrawal

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Rohan Puri | 9 Aug 2012 09:09
Picon
Gravatar

Re: How to get the inode - no path_lookup



On Thu, Aug 9, 2012 at 8:45 AM, Rishi Agrawal <rishi.b.agrawal <at> gmail.com> wrote:


On Wed, Aug 8, 2012 at 12:46 PM, Rohan Puri <rohan.puri15 <at> gmail.com> wrote:


On Tue, Aug 7, 2012 at 8:11 PM, Rishi Agrawal <rishi.b.agrawal <at> gmail.com> wrote:
Hi All,


I had a module which used the path_lookup function to print the details of any file's inode. I now want to rewrite that module in order to show some juniors how to write some code in kernel.

I am using 3.4.6 kernel, I tried finding out path_lookup but google showed that it has been removed.

I tried the following code then which did not work

.
.
.
dentry = kern_path_create(AT_FDCWD, filename, &path, 1);

if (IS_ERR(dentry)) {
              printk("Failed to obtain the dentry");
               return;
       }

its not returning dentry

I again tried after seeing the implementation of vfs_stat function

user_path_at(AT_FDCWD, filename, lookup_flags, &path);

but this also fails.


I am using a proc interface to pass the filename, and copying the filename into a kernel buffer.

How can I get a copy of vfs inode for a file name.


Need to use vfs_path_lookup for this, present in fs/namei.c file, which would give you filled nameidata nd that contais inodes pointer.
--
Regards,
Rishi Agrawal


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


- Rohan

vfs_path_lookup needs a dentry/mountpoint for the current path.

How will I get those.


/**
 * vfs_path_lookup - lookup a file path relative to a dentry-vfsmount pair
 * <at> dentry:  pointer to dentry of the base directory
 * <at> mnt: pointer to vfs mount of the base directory
 * <at> name: pointer to file name
 * <at> flags: lookup flags
 * <at> path: pointer to struct path to fill
 */


--
Regards,
Rishi Agrawal

If you dont have vfsmount's ptr, then you can make use of kern_path api with the LOOKUP_FOLLOW as second parameter. This will return the struct path ptr which contains vfsmount and the dentry's ptr. Now the dentry's ptr will contain the inode that you require.

- Rohan
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Rishi Agrawal | 13 Aug 2012 10:47
Picon

Re: How to get the inode - no path_lookup



On Thu, Aug 9, 2012 at 12:39 PM, Rohan Puri <rohan.puri15 <at> gmail.com> wrote:


On Thu, Aug 9, 2012 at 8:45 AM, Rishi Agrawal <rishi.b.agrawal <at> gmail.com> wrote:


On Wed, Aug 8, 2012 at 12:46 PM, Rohan Puri <rohan.puri15 <at> gmail.com> wrote:


On Tue, Aug 7, 2012 at 8:11 PM, Rishi Agrawal <rishi.b.agrawal <at> gmail.com> wrote:
Hi All,


I had a module which used the path_lookup function to print the details of any file's inode. I now want to rewrite that module in order to show some juniors how to write some code in kernel.

I am using 3.4.6 kernel, I tried finding out path_lookup but google showed that it has been removed.

I tried the following code then which did not work

.
.
.
dentry = kern_path_create(AT_FDCWD, filename, &path, 1);

if (IS_ERR(dentry)) {
              printk("Failed to obtain the dentry");
               return;
       }

its not returning dentry

I again tried after seeing the implementation of vfs_stat function

user_path_at(AT_FDCWD, filename, lookup_flags, &path);

but this also fails.


I am using a proc interface to pass the filename, and copying the filename into a kernel buffer.

How can I get a copy of vfs inode for a file name.


Need to use vfs_path_lookup for this, present in fs/namei.c file, which would give you filled nameidata nd that contais inodes pointer.
--
Regards,
Rishi Agrawal


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


- Rohan

vfs_path_lookup needs a dentry/mountpoint for the current path.

How will I get those.


/**
 * vfs_path_lookup - lookup a file path relative to a dentry-vfsmount pair
 * <at> dentry:  pointer to dentry of the base directory
 * <at> mnt: pointer to vfs mount of the base directory
 * <at> name: pointer to file name
 * <at> flags: lookup flags
 * <at> path: pointer to struct path to fill
 */


--
Regards,
Rishi Agrawal

If you dont have vfsmount's ptr, then you can make use of kern_path api with the LOOKUP_FOLLOW as second parameter. This will return the struct path ptr which contains vfsmount and the dentry's ptr. Now the dentry's ptr will contain the inode that you require.

- Rohan

Thanks, used that and its working now

--
Regards,
Rishi Agrawal

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Rohan Puri | 13 Aug 2012 11:34
Picon
Gravatar

Re: How to get the inode - no path_lookup



On Mon, Aug 13, 2012 at 2:17 PM, Rishi Agrawal <rishi.b.agrawal <at> gmail.com> wrote:


On Thu, Aug 9, 2012 at 12:39 PM, Rohan Puri <rohan.puri15 <at> gmail.com> wrote:


On Thu, Aug 9, 2012 at 8:45 AM, Rishi Agrawal <rishi.b.agrawal <at> gmail.com> wrote:


On Wed, Aug 8, 2012 at 12:46 PM, Rohan Puri <rohan.puri15 <at> gmail.com> wrote:


On Tue, Aug 7, 2012 at 8:11 PM, Rishi Agrawal <rishi.b.agrawal <at> gmail.com> wrote:
Hi All,


I had a module which used the path_lookup function to print the details of any file's inode. I now want to rewrite that module in order to show some juniors how to write some code in kernel.

I am using 3.4.6 kernel, I tried finding out path_lookup but google showed that it has been removed.

I tried the following code then which did not work

.
.
.
dentry = kern_path_create(AT_FDCWD, filename, &path, 1);

if (IS_ERR(dentry)) {
              printk("Failed to obtain the dentry");
               return;
       }

its not returning dentry

I again tried after seeing the implementation of vfs_stat function

user_path_at(AT_FDCWD, filename, lookup_flags, &path);

but this also fails.


I am using a proc interface to pass the filename, and copying the filename into a kernel buffer.

How can I get a copy of vfs inode for a file name.


Need to use vfs_path_lookup for this, present in fs/namei.c file, which would give you filled nameidata nd that contais inodes pointer.
--
Regards,
Rishi Agrawal


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


- Rohan

vfs_path_lookup needs a dentry/mountpoint for the current path.

How will I get those.


/**
 * vfs_path_lookup - lookup a file path relative to a dentry-vfsmount pair
 * <at> dentry:  pointer to dentry of the base directory
 * <at> mnt: pointer to vfs mount of the base directory
 * <at> name: pointer to file name
 * <at> flags: lookup flags
 * <at> path: pointer to struct path to fill
 */


--
Regards,
Rishi Agrawal

If you dont have vfsmount's ptr, then you can make use of kern_path api with the LOOKUP_FOLLOW as second parameter. This will return the struct path ptr which contains vfsmount and the dentry's ptr. Now the dentry's ptr will contain the inode that you require.

- Rohan

Thanks, used that and its working now

--
Regards,
Rishi Agrawal

Good to know :)

- Rohan
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies <at> kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Gmane