2007-08-21 02:58:37

by Xin Zhao

[permalink] [raw]
Subject: How Linux /proc filesystem convert a fd to the actual pathname?

Hi,

In the Linux proc filesystem, /proc/[pid]/fd is a link to the
actually the actual pathname of the opened file.

I am curious how Linux convert an fd to the pathname? Does it
recursively walk back from current dentry to the root?

Can someone point me to the right place in the kernel where this
functionality is implemented?

Many thanks in advance!

-x


2007-08-21 05:32:20

by Jan Engelhardt

[permalink] [raw]
Subject: Re: How Linux /proc filesystem convert a fd to the actual pathname?


>In the Linux proc filesystem, /proc/[pid]/fd is a link to the
>actually the actual pathname of the opened file.
>
>I am curious how Linux convert an fd to the pathname? Does it
>recursively walk back from current dentry to the root?

AFAICS the fd has a pointer to the vma of the file (don't ask me why),
which in turn has a 'struct file' pointer, which in turn has the
required 'struct dentry' in it.


Jan
--

2007-08-21 06:04:25

by Kevin Hao

[permalink] [raw]
Subject: Re: How Linux /proc filesystem convert a fd to the actual pathname?

> I am curious how Linux convert an fd to the pathname? Does it
> recursively walk back from current dentry to the root?
Using d_path.
> Can someone point me to the right place in the kernel where this
> functionality is implemented?
do_proc_readlink may be the function you want.

2007-08-21 06:41:20

by Xin Zhao

[permalink] [raw]
Subject: Re: How Linux /proc filesystem convert a fd to the actual pathname?

Thanks! That perfectly answered my question.

-x

On 8/21/07, Kevin Hao <[email protected]> wrote:
> > I am curious how Linux convert an fd to the pathname? Does it
> > recursively walk back from current dentry to the root?
> Using d_path.
> > Can someone point me to the right place in the kernel where this
> > functionality is implemented?
>
may be the function you want.
>