Re: /proc/memmap

Marnix Coppens (maco@telindus.be)
Wed, 17 Dec 1997 14:27:08 +0100


At 14:21 17/12/97 +0200, Craig Schlenter wrote:
>
>The one thing I haven't figured out is how to get from the inode to the
>filename which would be nice ... you comment that this should be possible
>given the dentry stuff in 2.1 but I can't see an obvious path to do this
>looking at the 2.1 structures and code in the kernel.
>

Have a look at how /proc/<pid>/maps does it in fs/proc/array.c
Basically:

buffer = (char *) __get_free_page(GFP_KERNEL);
if (buffer && pdentry)
{
line = d_path(pdentry, buffer, PAGE_SIZE);
free_page((unsigned long) buffer);
}
else
/* show dev, ino instead */

d_path() is exported in fs/dcache.c. It is recommended that you pass it
a buffer of at least a page. It will fill in the name of the inode
starting from the end of the buffer and working its way up to the root inode.
The pointer to the first character of the full name is then returned.
Think of it as a right-aligned strncpy().

buffer: ??
buffer + 1: ??
buffer + 2: ??
...
line: /some/name/here\0

The terminating \0 is aligned at (buffer + PAGE_SIZE - 1) in this expample.

Cheers,

Marnix Coppens

---
Reality is that which                   | Artificial Intelligence
when you stop believing                 | stands no chance against
in it doesn't go away. (Philip K. Dick) | Natural Stupidity.