enum {
TABTYPE_FSTAB = 1,
TABTYPE_MTAB,
- TABTYPE_KERNEL_MOUNTINFO
+ TABTYPE_KERNEL_MOUNTINFO,
+ TABTYPE_KERNEL_LISTMOUNT
};
/* column names */
bool filtered = false;
if (has_line(table, fs))
goto leave;
+
line = add_line(table, fs, parent_line, findmnt, &filtered);
if (filtered)
line = parent_line;
(size_t) scols_table_get_nlines(table)) {
mnt_reset_iter(itr, MNT_ITER_FORWARD);
fs = NULL;
-
while (mnt_table_next_fs(tb, itr, &fs) == 0) {
if (!has_line(table, fs) && match_func(fs, findmnt))
create_treenode(table, tb, fs, NULL, findmnt);
return tb;
}
+static struct libmnt_table *fetch_listmount(void)
+{
+ struct libmnt_table *tb;
+ struct libmnt_statmnt *sm;
+
+ sm = mnt_new_statmnt();
+ if (!sm) {
+ warn(_("failed to allocate statmnt handler"));
+ return NULL;
+ }
+
+ tb = mnt_new_table();
+ if (!tb) {
+ warn(_("failed to initialize libmount table"));
+ return NULL;
+ }
+
+ mnt_table_refer_statmnt(tb, sm);
+
+ if (mnt_table_fetch_listmount(tb) != 0) {
+ warn(_("failed to fetch mount nodes"));
+ mnt_unref_table(tb);
+ mnt_unref_statmnt(sm);
+ return NULL;
+ }
+
+ return tb;
+}
+
/*
* Parses mountinfo and calls mnt_cache_set_targets(cache, mtab). Only
* necessary if @tb in main() was read from a non-kernel source.
if (optarg) {
if (strcmp(optarg, "mountinfo") == 0)
tabtype = TABTYPE_KERNEL_MOUNTINFO;
+ else if (strcmp(optarg, "listmount") == 0)
+ tabtype = TABTYPE_KERNEL_LISTMOUNT;
else
errx(EXIT_FAILURE, _("invalid --kernel argument"));
} else
if ((findmnt.flags & FL_POLL) && ntabfiles > 1)
errx(EXIT_FAILURE, _("--poll accepts only one file, but more specified by --tab-file"));
+ if (ntabfiles && tabtype == TABTYPE_KERNEL_LISTMOUNT)
+ errx(EXIT_FAILURE, _(
+ "options --kernel=listmount and --tab-file or --task can't be used together"));
+
if (optind < argc && (get_match(COL_SOURCE) || get_match(COL_TARGET)))
errx(EXIT_FAILURE, _(
"options --target and --source can't be used together "
*/
mnt_init_debug(0);
- tb = parse_tabfiles(tabfiles, ntabfiles, tabtype);
+ if (tabtype == TABTYPE_KERNEL_LISTMOUNT)
+ tb = fetch_listmount();
+ else
+ tb = parse_tabfiles(tabfiles, ntabfiles, tabtype);
if (!tb)
goto leave;
mnt_table_set_userdata(tb, &findmnt);
}
mnt_table_set_cache(tb, findmnt.cache);
- if (tabtype != TABTYPE_KERNEL_MOUNTINFO)
+ if (tabtype == TABTYPE_FSTAB || tabtype == TABTYPE_MTAB)
cache_set_targets(findmnt.cache);
}