/** * mnt_table_parse_stream: * @tb: tab pointer * @f: file stream * @filename: filename used for debug and error messages * * Returns: 0 on success, negative number in case of error. */ int mnt_table_parse_stream(struct libmnt_table *tb, FILE *f, const char *filename) { int nlines = 0; int rc = -1; int flags = 0; pid_t tid = -1; assert(tb); assert(f); assert(filename); DBG(TAB, mnt_debug_h(tb, "%s: start parsing (%d entries)", filename, mnt_table_get_nents(tb))); /* necessary for /proc/mounts only, the /proc/self/mountinfo * parser sets the flag properly */ if (filename && strcmp(filename, _PATH_PROC_MOUNTS) == 0) flags = MNT_FS_KERNEL; while (!feof(f)) { struct libmnt_fs *fs = mnt_new_fs(); if (!fs) goto err; rc = mnt_table_parse_next(tb, f, fs, filename, &nlines); if (!rc && tb->fltrcb && tb->fltrcb(fs, tb->fltrcb_data)) rc = 1; /* filtered out by callback... */ 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) { mnt_free_fs(fs); if (rc == 1) continue; /* recoverable error */ if (feof(f)) break; goto err; /* fatal error */ } } DBG(TAB, mnt_debug_h(tb, "%s: stop parsing (%d entries)", filename, mnt_table_get_nents(tb))); return 0; err: DBG(TAB, mnt_debug_h(tb, "%s: parse error (rc=%d)", filename, rc)); return rc; }
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 a 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 *real = NULL; rc = mnt_guess_system_root(fs->devno, tb->cache, &real); if (rc < 0) return rc; if (rc == 0 && real) { DBG(TAB, ul_debugobj(tb, "canonical root FS: %s", real)); rc = __mnt_fs_set_source_ptr(fs, real); } else if (rc == 1) { /* mnt_guess_system_root() returns 1 if not able to conver to * the real devname; ignore this problem */ rc = 0; } } return rc; }
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 a 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; }