From 3da7f698c17f64512994593e9c368181d4c52488 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 8 Nov 2012 14:43:38 +0100 Subject: libmount: convert /dev/root from mountinfo to the device name Signed-off-by: Karel Zak --- libmount/src/tab_parse.c | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'libmount/src/tab_parse.c') diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index 2cae750dc..ad8832064 100644 --- a/libmount/src/tab_parse.c +++ b/libmount/src/tab_parse.c @@ -452,6 +452,43 @@ done: return tid; } +static int kernel_fs_postparse(struct libmnt_table *tb, + struct libmnt_fs *fs, pid_t *tid, + const char *filename) +{ + int rc = 0; + const char *src = mnt_fs_get_srcpath(fs); + + /* This is filesystem description from /proc, so we're in some process + * namespace. Let's remember the process PID. + */ + if (filename && *tid == -1) + *tid = path_to_tid(filename); + + fs->tid = *tid; + + /* + * Convert obscure /dev/root to something more usable + */ + if (src && strcmp(src, "/dev/root") == 0) { + char *spec = mnt_get_kernel_cmdline_option("root="); + char *real = NULL; + + DBG(TAB, mnt_debug_h(tb, "root FS: %s", spec)); + if (spec) + real = mnt_resolve_spec(spec, tb->cache); + if (real) { + DBG(TAB, mnt_debug_h(tb, "canonical root FS: %s", real)); + rc = mnt_fs_set_source(fs, real); + if (!tb->cache) + free(real); + } + free(spec); + } + + return rc; +} + /** * mnt_table_parse_stream: * @tb: tab pointer @@ -494,11 +531,9 @@ int mnt_table_parse_stream(struct libmnt_table *tb, FILE *f, const char *filenam if (!rc) { rc = mnt_table_add_fs(tb, fs); fs->flags |= flags; - if (tb->fmt == MNT_FMT_MOUNTINFO && filename) { - if (tid == -1) - tid = path_to_tid(filename); - fs->tid = tid; - } + + if (rc == 0 && tb->fmt == MNT_FMT_MOUNTINFO) + rc = kernel_fs_postparse(tb, fs, &tid, filename); } if (rc) { mnt_free_fs(fs); -- cgit v1.2.3-55-g7522