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.