[patch 1/7] vfs: mountinfo: add dentry_path()
[mszeredi@suse.cz] split big patch into managable chunks Add the following functions: dentry_path() seq_dentry() These are similar to d_path() and seq_path(). But instead of calculating the path within a mount namespace, they calculate the path from the root of the filesystem to a given dentry, ignoring mounts completely. Signed-off-by: Ram Pai <linuxram@us.ibm.com> Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
@@ -350,28 +350,40 @@ int seq_printf(struct seq_file *m, const char *f, ...)
|
||||
}
|
||||
EXPORT_SYMBOL(seq_printf);
|
||||
|
||||
static char *mangle_path(char *s, char *p, char *esc)
|
||||
{
|
||||
while (s <= p) {
|
||||
char c = *p++;
|
||||
if (!c) {
|
||||
return s;
|
||||
} else if (!strchr(esc, c)) {
|
||||
*s++ = c;
|
||||
} else if (s + 4 > p) {
|
||||
break;
|
||||
} else {
|
||||
*s++ = '\\';
|
||||
*s++ = '0' + ((c & 0300) >> 6);
|
||||
*s++ = '0' + ((c & 070) >> 3);
|
||||
*s++ = '0' + (c & 07);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* return the absolute path of 'dentry' residing in mount 'mnt'.
|
||||
*/
|
||||
int seq_path(struct seq_file *m, struct path *path, char *esc)
|
||||
{
|
||||
if (m->count < m->size) {
|
||||
char *s = m->buf + m->count;
|
||||
char *p = d_path(path, s, m->size - m->count);
|
||||
if (!IS_ERR(p)) {
|
||||
while (s <= p) {
|
||||
char c = *p++;
|
||||
if (!c) {
|
||||
p = m->buf + m->count;
|
||||
m->count = s - m->buf;
|
||||
return s - p;
|
||||
} else if (!strchr(esc, c)) {
|
||||
*s++ = c;
|
||||
} else if (s + 4 > p) {
|
||||
break;
|
||||
} else {
|
||||
*s++ = '\\';
|
||||
*s++ = '0' + ((c & 0300) >> 6);
|
||||
*s++ = '0' + ((c & 070) >> 3);
|
||||
*s++ = '0' + (c & 07);
|
||||
}
|
||||
s = mangle_path(s, p, esc);
|
||||
if (s) {
|
||||
p = m->buf + m->count;
|
||||
m->count = s - m->buf;
|
||||
return s - p;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,6 +392,27 @@ int seq_path(struct seq_file *m, struct path *path, char *esc)
|
||||
}
|
||||
EXPORT_SYMBOL(seq_path);
|
||||
|
||||
/*
|
||||
* returns the path of the 'dentry' from the root of its filesystem.
|
||||
*/
|
||||
int seq_dentry(struct seq_file *m, struct dentry *dentry, char *esc)
|
||||
{
|
||||
if (m->count < m->size) {
|
||||
char *s = m->buf + m->count;
|
||||
char *p = dentry_path(dentry, s, m->size - m->count);
|
||||
if (!IS_ERR(p)) {
|
||||
s = mangle_path(s, p, esc);
|
||||
if (s) {
|
||||
p = m->buf + m->count;
|
||||
m->count = s - m->buf;
|
||||
return s - p;
|
||||
}
|
||||
}
|
||||
}
|
||||
m->count = m->size;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void *single_start(struct seq_file *p, loff_t *pos)
|
||||
{
|
||||
return NULL + (*pos == 0);
|
||||
|
Reference in New Issue
Block a user