diff options
author | Karel Zak | 2010-12-07 00:16:47 +0100 |
---|---|---|
committer | Karel Zak | 2011-01-03 12:28:47 +0100 |
commit | 62a1000803445e0cf377e0f6f8e9f48b460b8f74 (patch) | |
tree | 58cefff75dc7d1eb550109feb9f6b179623b61ad | |
parent | build-sys: add --enable-libmount-mount (diff) | |
download | kernel-qcow2-util-linux-62a1000803445e0cf377e0f6f8e9f48b460b8f74.tar.gz kernel-qcow2-util-linux-62a1000803445e0cf377e0f6f8e9f48b460b8f74.tar.xz kernel-qcow2-util-linux-62a1000803445e0cf377e0f6f8e9f48b460b8f74.zip |
mount: read mtab by libmount
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | mount/fstab.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/mount/fstab.c b/mount/fstab.c index bfb2e5d35..0156017ec 100644 --- a/mount/fstab.c +++ b/mount/fstab.c @@ -148,10 +148,55 @@ read_mntentchn(mntFILE *mfp, const char *fnam, struct mntentchn *mc0) { my_endmntent(mfp); } +#ifdef HAVE_LIBMOUNT_MOUNT + +#define USE_UNSTABLE_LIBMOUNT_API +#include <mount.h> /* libmount */ + +static void read_mounttable() +{ + struct mntentchn *mc0 = &mounttable, *mc = mc0; + mnt_tab *tb = mnt_new_tab(); + mnt_iter *itr = mnt_new_iter(MNT_ITER_FORWARD); + mnt_fs *fs; + + got_mtab = 1; + mc->nxt = mc->prev = NULL; + + if (!tb || !itr) + goto err; + if (mnt_tab_parse_mtab(tb, NULL)) + goto err; + + while(mnt_tab_next_fs(tb, itr, &fs) == 0) { + const char *type = mnt_fs_get_fstype(fs); + struct my_mntent *mnt = NULL; + + if (type && strcmp(type, MNTTYPE_IGNORE) == 0) + continue; + if (mnt_fs_to_mntent(fs, (struct mntent **) &mnt)) + goto err; + mc->nxt = xmalloc(sizeof(*mc)); + mc->nxt->prev = mc; + mc = mc->nxt; + mc->m = *mnt; + mc->nxt = mc0; + } + + mc0->prev = mc; + return; +err: + error(_("warning: failed to read mtab")); + mnt_free_tab(tb); + mnt_free_iter(itr); + mc->nxt = mc->prev = NULL; +} + +#else /* !HAVE_LIBMOUNT_MOUNT */ + /* * Read /etc/mtab. If that fails, try /proc/mounts. * This produces a linked list. The list head mounttable is a dummy. - * Return 0 on success. */ static void read_mounttable() { @@ -180,6 +225,7 @@ read_mounttable() { } read_mntentchn(mfp, fnam, mc); } +#endif /* HAVE_LIBMOUNT_MOUNT */ static void read_fstab() { |