diff options
author | Ram Pai <linuxram@us.ibm.com> | 2008-03-27 08:06:20 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2008-04-23 00:04:32 -0400 |
commit | 6092d048183b76bfa3f84b32f8158dd8d10bd811 (patch) | |
tree | 2d38af32961eb52b36daca2f29ce69e80f6e7283 /fs/seq_file.c | |
parent | 934b25c597c0e98304a7eaec198a87e4633a42bb (diff) |
[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>
Diffstat (limited to 'fs/seq_file.c')
-rw-r--r-- | fs/seq_file.c | 65 |
1 files changed, 49 insertions, 16 deletions
diff --git a/fs/seq_file.c b/fs/seq_file.c index cdfd996ca6ef..ae59f5a6c5c1 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c | |||
@@ -350,28 +350,40 @@ int seq_printf(struct seq_file *m, const char *f, ...) | |||
350 | } | 350 | } |
351 | EXPORT_SYMBOL(seq_printf); | 351 | EXPORT_SYMBOL(seq_printf); |
352 | 352 | ||
353 | static char *mangle_path(char *s, char *p, char *esc) | ||
354 | { | ||
355 | while (s <= p) { | ||
356 | char c = *p++; | ||
357 | if (!c) { | ||
358 | return s; | ||
359 | } else if (!strchr(esc, c)) { | ||
360 | *s++ = c; | ||
361 | } else if (s + 4 > p) { | ||
362 | break; | ||
363 | } else { | ||
364 | *s++ = '\\'; | ||
365 | *s++ = '0' + ((c & 0300) >> 6); | ||
366 | *s++ = '0' + ((c & 070) >> 3); | ||
367 | *s++ = '0' + (c & 07); | ||
368 | } | ||
369 | } | ||
370 | return NULL; | ||
371 | } | ||
372 | |||
373 | /* | ||
374 | * return the absolute path of 'dentry' residing in mount 'mnt'. | ||
375 | */ | ||
353 | int seq_path(struct seq_file *m, struct path *path, char *esc) | 376 | int seq_path(struct seq_file *m, struct path *path, char *esc) |
354 | { | 377 | { |
355 | if (m->count < m->size) { | 378 | if (m->count < m->size) { |
356 | char *s = m->buf + m->count; | 379 | char *s = m->buf + m->count; |
357 | char *p = d_path(path, s, m->size - m->count); | 380 | char *p = d_path(path, s, m->size - m->count); |
358 | if (!IS_ERR(p)) { | 381 | if (!IS_ERR(p)) { |
359 | while (s <= p) { | 382 | s = mangle_path(s, p, esc); |
360 | char c = *p++; | 383 | if (s) { |
361 | if (!c) { | 384 | p = m->buf + m->count; |
362 | p = m->buf + m->count; | 385 | m->count = s - m->buf; |
363 | m->count = s - m->buf; | 386 | return s - p; |
364 | return s - p; | ||
365 | } else if (!strchr(esc, c)) { | ||
366 | *s++ = c; | ||
367 | } else if (s + 4 > p) { | ||
368 | break; | ||
369 | } else { | ||
370 | *s++ = '\\'; | ||
371 | *s++ = '0' + ((c & 0300) >> 6); | ||
372 | *s++ = '0' + ((c & 070) >> 3); | ||
373 | *s++ = '0' + (c & 07); | ||
374 | } | ||
375 | } | 387 | } |
376 | } | 388 | } |
377 | } | 389 | } |
@@ -380,6 +392,27 @@ int seq_path(struct seq_file *m, struct path *path, char *esc) | |||
380 | } | 392 | } |
381 | EXPORT_SYMBOL(seq_path); | 393 | EXPORT_SYMBOL(seq_path); |
382 | 394 | ||
395 | /* | ||
396 | * returns the path of the 'dentry' from the root of its filesystem. | ||
397 | */ | ||
398 | int seq_dentry(struct seq_file *m, struct dentry *dentry, char *esc) | ||
399 | { | ||
400 | if (m->count < m->size) { | ||
401 | char *s = m->buf + m->count; | ||
402 | char *p = dentry_path(dentry, s, m->size - m->count); | ||
403 | if (!IS_ERR(p)) { | ||
404 | s = mangle_path(s, p, esc); | ||
405 | if (s) { | ||
406 | p = m->buf + m->count; | ||
407 | m->count = s - m->buf; | ||
408 | return s - p; | ||
409 | } | ||
410 | } | ||
411 | } | ||
412 | m->count = m->size; | ||
413 | return -1; | ||
414 | } | ||
415 | |||
383 | static void *single_start(struct seq_file *p, loff_t *pos) | 416 | static void *single_start(struct seq_file *p, loff_t *pos) |
384 | { | 417 | { |
385 | return NULL + (*pos == 0); | 418 | return NULL + (*pos == 0); |