kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* How to get the inode - no path_lookup
@ 2012-08-07 14:41 Rishi Agrawal
  2012-08-08  7:16 ` Rohan Puri
  0 siblings, 1 reply; 9+ messages in thread
From: Rishi Agrawal @ 2012-08-07 14:41 UTC (permalink / raw)
  To: kernelnewbies

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120807/2c863831/attachment.html 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* How to get the inode - no path_lookup
  2012-08-07 14:41 How to get the inode - no path_lookup Rishi Agrawal
@ 2012-08-08  7:16 ` Rohan Puri
  2012-08-09  3:15   ` Rishi Agrawal
  0 siblings, 1 reply; 9+ messages in thread
From: Rohan Puri @ 2012-08-08  7:16 UTC (permalink / raw)
  To: kernelnewbies

On Tue, Aug 7, 2012 at 8:11 PM, Rishi Agrawal <rishi.b.agrawal@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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120808/073a62a7/attachment.html 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* How to get the inode - no path_lookup
  2012-08-08  7:16 ` Rohan Puri
@ 2012-08-09  3:15   ` Rishi Agrawal
  2012-08-09  7:09     ` Rohan Puri
  0 siblings, 1 reply; 9+ messages in thread
From: Rishi Agrawal @ 2012-08-09  3:15 UTC (permalink / raw)
  To: kernelnewbies

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

>
>
> On Tue, Aug 7, 2012 at 8:11 PM, Rishi Agrawal <rishi.b.agrawal@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
 * @dentry:  pointer to dentry of the base directory
 * @mnt: pointer to vfs mount of the base directory
 * @name: pointer to file name
 * @flags: lookup flags
 * @path: pointer to struct path to fill
 */


-- 
Regards,
Rishi Agrawal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120809/d518d7dd/attachment.html 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* How to get the inode - no path_lookup
  2012-08-09  3:15   ` Rishi Agrawal
@ 2012-08-09  7:09     ` Rohan Puri
  2012-08-13  8:47       ` Rishi Agrawal
  0 siblings, 1 reply; 9+ messages in thread
From: Rohan Puri @ 2012-08-09  7:09 UTC (permalink / raw)
  To: kernelnewbies

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

>
>
> On Wed, Aug 8, 2012 at 12:46 PM, Rohan Puri <rohan.puri15@gmail.com>wrote:
>
>>
>>
>> On Tue, Aug 7, 2012 at 8:11 PM, Rishi Agrawal <rishi.b.agrawal@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
>  * @dentry:  pointer to dentry of the base directory
>  * @mnt: pointer to vfs mount of the base directory
>  * @name: pointer to file name
>  * @flags: lookup flags
>  * @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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120809/929e66df/attachment.html 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* How to get the inode - no path_lookup
  2012-08-09  7:09     ` Rohan Puri
@ 2012-08-13  8:47       ` Rishi Agrawal
  2012-08-13  9:34         ` Rohan Puri
  0 siblings, 1 reply; 9+ messages in thread
From: Rishi Agrawal @ 2012-08-13  8:47 UTC (permalink / raw)
  To: kernelnewbies

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

>
>
> On Thu, Aug 9, 2012 at 8:45 AM, Rishi Agrawal <rishi.b.agrawal@gmail.com>wrote:
>
>>
>>
>> On Wed, Aug 8, 2012 at 12:46 PM, Rohan Puri <rohan.puri15@gmail.com>wrote:
>>
>>>
>>>
>>> On Tue, Aug 7, 2012 at 8:11 PM, Rishi Agrawal <rishi.b.agrawal@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
>>  * @dentry:  pointer to dentry of the base directory
>>  * @mnt: pointer to vfs mount of the base directory
>>  * @name: pointer to file name
>>  * @flags: lookup flags
>>  * @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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120813/effeee59/attachment.html 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* How to get the inode - no path_lookup
  2012-08-13  8:47       ` Rishi Agrawal
@ 2012-08-13  9:34         ` Rohan Puri
  2015-09-04 16:26           ` priyamn
  0 siblings, 1 reply; 9+ messages in thread
From: Rohan Puri @ 2012-08-13  9:34 UTC (permalink / raw)
  To: kernelnewbies

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

>
>
> On Thu, Aug 9, 2012 at 12:39 PM, Rohan Puri <rohan.puri15@gmail.com>wrote:
>
>>
>>
>> On Thu, Aug 9, 2012 at 8:45 AM, Rishi Agrawal <rishi.b.agrawal@gmail.com>wrote:
>>
>>>
>>>
>>> On Wed, Aug 8, 2012 at 12:46 PM, Rohan Puri <rohan.puri15@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
>>>  * @dentry:  pointer to dentry of the base directory
>>>  * @mnt: pointer to vfs mount of the base directory
>>>  * @name: pointer to file name
>>>  * @flags: lookup flags
>>>  * @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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120813/13887e12/attachment.html 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* How to get the inode - no path_lookup
  2012-08-13  9:34         ` Rohan Puri
@ 2015-09-04 16:26           ` priyamn
  2015-09-16 22:31             ` Greg KH
  0 siblings, 1 reply; 9+ messages in thread
From: priyamn @ 2015-09-04 16:26 UTC (permalink / raw)
  To: kernelnewbies


Hi,

I happened to come across this discussion. I am having a similar issue. 
I am using Rhel7-3.10.0-123 
kernel. I tried all the options that are mentioned above and none of the api's 
including kern_path() return valid dentry value. 
My requirement is to fetch directory name from filepath.

Can anybody suggest a work-around for this ?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* How to get the inode - no path_lookup
  2015-09-04 16:26           ` priyamn
@ 2015-09-16 22:31             ` Greg KH
  2015-09-17  8:10               ` Rohan Puri
  0 siblings, 1 reply; 9+ messages in thread
From: Greg KH @ 2015-09-16 22:31 UTC (permalink / raw)
  To: kernelnewbies

On Fri, Sep 04, 2015 at 04:26:06PM +0000, priyamn wrote:
> 
> Hi,
> 
> I happened to come across this discussion. I am having a similar issue. 
> I am using Rhel7-3.10.0-123 
> kernel. I tried all the options that are mentioned above and none of the api's 
> including kern_path() return valid dentry value. 
> My requirement is to fetch directory name from filepath.

Why do you need a directory name from a filepath within the kernel?
What problem are you trying to solve that you feel a directory name is
the correct solution?

And remember, namespaces, what does a "directory name" really mean... :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 9+ messages in thread

* How to get the inode - no path_lookup
  2015-09-16 22:31             ` Greg KH
@ 2015-09-17  8:10               ` Rohan Puri
  0 siblings, 0 replies; 9+ messages in thread
From: Rohan Puri @ 2015-09-17  8:10 UTC (permalink / raw)
  To: kernelnewbies

On 17 Sep 2015 04:02, "Greg KH" <greg@kroah.com> wrote:
>
> On Fri, Sep 04, 2015 at 04:26:06PM +0000, priyamn wrote:
> >
> > Hi,
> >
> > I happened to come across this discussion. I am having a similar issue.
> > I am using Rhel7-3.10.0-123
> > kernel. I tried all the options that are mentioned above and none of
the api's
> > including kern_path() return valid dentry value.
> > My requirement is to fetch directory name from filepath.
>
> Why do you need a directory name from a filepath within the kernel?
> What problem are you trying to solve that you feel a directory name is
> the correct solution?
>
> And remember, namespaces, what does a "directory name" really mean... :)
>
> thanks,
>
> greg k-h
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Hi Priya,

Please make use of a single thread for one topic. There was another thread
by you on the same topic. Anyways, I am replying to this one.

Greg has asked questions that you should ask yourself before going on with
choosing one approach.

I had suggested you using kern_path() earlier, since it doesn't makes use
of nameidata, but as you are telling its not working too. Here I would like
to know the actual context of the approach so as to figure out if something
I know that can work for you or maybe you shouldn't be doing it that way.

Enjoy life,
Rohan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150917/8a6be1e8/attachment.html 

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-09-17  8:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-07 14:41 How to get the inode - no path_lookup Rishi Agrawal
2012-08-08  7:16 ` Rohan Puri
2012-08-09  3:15   ` Rishi Agrawal
2012-08-09  7:09     ` Rohan Puri
2012-08-13  8:47       ` Rishi Agrawal
2012-08-13  9:34         ` Rohan Puri
2015-09-04 16:26           ` priyamn
2015-09-16 22:31             ` Greg KH
2015-09-17  8:10               ` Rohan Puri

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).