|
|
dd59ef |
From e82cfd53cfd127e5877aefa5ea1d50bfe71d1788 Mon Sep 17 00:00:00 2001
|
|
|
dd59ef |
From: Fridolin Pokorny <fpokorny@redhat.com>
|
|
|
dd59ef |
Date: Wed, 27 Aug 2014 15:25:30 +0200
|
|
|
dd59ef |
Subject: [PATCH 1/9] mountlist: use /proc/self/mountinfo when available
|
|
|
dd59ef |
|
|
|
dd59ef |
Use libmount to propagate device IDs provided by Linux in
|
|
|
dd59ef |
/proc/self/mountinfo. This will give more accurate output when
|
|
|
dd59ef |
using df in chroot'ed environments as the device IDs are not
|
|
|
dd59ef |
determined by stat() which may be inaccurate within the chroot.
|
|
|
dd59ef |
|
|
|
dd59ef |
* lib/mountlist.c (read_file_system_list): Use the libmount routines
|
|
|
dd59ef |
from util-linux to parse "/proc/self/mountinfo" or fall back to
|
|
|
dd59ef |
standard getmntent() processing.
|
|
|
dd59ef |
* m4/ls-mntd-fs.m4: Check for libmount only when 1-argument
|
|
|
dd59ef |
getmntent() is used, as is the case on GNU/Linux.
|
|
|
dd59ef |
* DEPENDENCIES: Mention the optional util-linux dependency.
|
|
|
dd59ef |
|
|
|
dd59ef |
Upstream-commit: 3ea43e02541ece750ffc6cd1dfe34195421b4ef3
|
|
|
dd59ef |
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
|
|
|
dd59ef |
---
|
|
|
dd59ef |
lib/mountlist.c | 82 ++++++++++++++++++++++++++++++++++++------------
|
|
|
dd59ef |
m4/ls-mntd-fs.m4 | 15 ++++++++-
|
|
|
dd59ef |
2 files changed, 76 insertions(+), 21 deletions(-)
|
|
|
dd59ef |
|
|
|
dd59ef |
diff --git a/lib/mountlist.c b/lib/mountlist.c
|
|
|
dd59ef |
index 17779f6..617fa88 100644
|
|
|
dd59ef |
--- a/lib/mountlist.c
|
|
|
dd59ef |
+++ b/lib/mountlist.c
|
|
|
dd59ef |
@@ -128,6 +128,12 @@
|
|
|
dd59ef |
# include <sys/mntent.h>
|
|
|
dd59ef |
#endif
|
|
|
dd59ef |
|
|
|
dd59ef |
+#ifdef MOUNTED_PROC_MOUNTINFO
|
|
|
dd59ef |
+/* Use /proc/self/mountinfo instead of /proc/self/mounts (/etc/mtab)
|
|
|
dd59ef |
+ * on Linux, if available */
|
|
|
dd59ef |
+# include <libmount/libmount.h>
|
|
|
dd59ef |
+#endif
|
|
|
dd59ef |
+
|
|
|
dd59ef |
#ifndef HAVE_HASMNTOPT
|
|
|
dd59ef |
# define hasmntopt(mnt, opt) ((char *) 0)
|
|
|
dd59ef |
#endif
|
|
|
dd59ef |
@@ -430,32 +436,68 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
|
|
|
dd59ef |
#ifdef MOUNTED_GETMNTENT1 /* GNU/Linux, 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
|
|
dd59ef |
{
|
|
|
dd59ef |
- struct mntent *mnt;
|
|
|
dd59ef |
- char const *table = MOUNTED;
|
|
|
dd59ef |
- FILE *fp;
|
|
|
dd59ef |
+#ifdef MOUNTED_PROC_MOUNTINFO
|
|
|
dd59ef |
+ struct libmnt_table *fstable = NULL;
|
|
|
dd59ef |
|
|
|
dd59ef |
- fp = setmntent (table, "r");
|
|
|
dd59ef |
- if (fp == NULL)
|
|
|
dd59ef |
- return NULL;
|
|
|
dd59ef |
+ fstable = mnt_new_table_from_file ("/proc/self/mountinfo");
|
|
|
dd59ef |
|
|
|
dd59ef |
- while ((mnt = getmntent (fp)))
|
|
|
dd59ef |
+ if (fstable != NULL)
|
|
|
dd59ef |
{
|
|
|
dd59ef |
- me = xmalloc (sizeof *me);
|
|
|
dd59ef |
- me->me_devname = xstrdup (mnt->mnt_fsname);
|
|
|
dd59ef |
- me->me_mountdir = xstrdup (mnt->mnt_dir);
|
|
|
dd59ef |
- me->me_type = xstrdup (mnt->mnt_type);
|
|
|
dd59ef |
- me->me_type_malloced = 1;
|
|
|
dd59ef |
- me->me_dummy = ME_DUMMY (me->me_devname, me->me_type, mnt);
|
|
|
dd59ef |
- me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
|
|
|
dd59ef |
- me->me_dev = dev_from_mount_options (mnt->mnt_opts);
|
|
|
dd59ef |
+ struct libmnt_fs *fs;
|
|
|
dd59ef |
+ struct libmnt_iter *iter;
|
|
|
dd59ef |
|
|
|
dd59ef |
- /* Add to the linked list. */
|
|
|
dd59ef |
- *mtail = me;
|
|
|
dd59ef |
- mtail = &me->me_next;
|
|
|
dd59ef |
+ iter = mnt_new_iter (MNT_ITER_FORWARD);
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ while (iter && mnt_table_next_fs (fstable, iter, &fs) == 0)
|
|
|
dd59ef |
+ {
|
|
|
dd59ef |
+ me = xmalloc (sizeof *me);
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ me->me_devname = xstrdup (mnt_fs_get_source (fs));
|
|
|
dd59ef |
+ me->me_mountdir = xstrdup (mnt_fs_get_target (fs));
|
|
|
dd59ef |
+ me->me_type = xstrdup (mnt_fs_get_fstype (fs));
|
|
|
dd59ef |
+ me->me_type_malloced = 1;
|
|
|
dd59ef |
+ me->me_dev = mnt_fs_get_devno (fs);
|
|
|
dd59ef |
+ me->me_dummy = mnt_fs_is_pseudofs (fs);
|
|
|
dd59ef |
+ me->me_remote = mnt_fs_is_netfs (fs);
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ /* Add to the linked list. */
|
|
|
dd59ef |
+ *mtail = me;
|
|
|
dd59ef |
+ mtail = &me->me_next;
|
|
|
dd59ef |
+ }
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ mnt_free_iter (iter);
|
|
|
dd59ef |
+ mnt_free_table (fstable);
|
|
|
dd59ef |
}
|
|
|
dd59ef |
+ else /* fallback to /proc/self/mounts (/etc/mtab) if anything failed */
|
|
|
dd59ef |
+#endif /* MOUNTED_PROC_MOUNTINFO */
|
|
|
dd59ef |
+ {
|
|
|
dd59ef |
+ FILE * fp;
|
|
|
dd59ef |
+ struct mntent *mnt;
|
|
|
dd59ef |
+ char const *table = MOUNTED;
|
|
|
dd59ef |
|
|
|
dd59ef |
- if (endmntent (fp) == 0)
|
|
|
dd59ef |
- goto free_then_fail;
|
|
|
dd59ef |
+ fp = setmntent (table, "r");
|
|
|
dd59ef |
+ if (fp == NULL)
|
|
|
dd59ef |
+ return NULL;
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ while ((mnt = getmntent (fp)))
|
|
|
dd59ef |
+ {
|
|
|
dd59ef |
+ me = xmalloc (sizeof *me);
|
|
|
dd59ef |
+ me->me_devname = xstrdup (mnt->mnt_fsname);
|
|
|
dd59ef |
+ me->me_mountdir = xstrdup (mnt->mnt_dir);
|
|
|
dd59ef |
+ me->me_type = xstrdup (mnt->mnt_type);
|
|
|
dd59ef |
+ me->me_type_malloced = 1;
|
|
|
dd59ef |
+ me->me_dummy = ME_DUMMY (me->me_devname, me->me_type, mnt);
|
|
|
dd59ef |
+ me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
|
|
|
dd59ef |
+ me->me_dev = dev_from_mount_options (mnt->mnt_opts);
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ /* Add to the linked list. */
|
|
|
dd59ef |
+ *mtail = me;
|
|
|
dd59ef |
+ mtail = &me->me_next;
|
|
|
dd59ef |
+ }
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ if (endmntent (fp) == 0)
|
|
|
dd59ef |
+ goto free_then_fail;
|
|
|
dd59ef |
+ }
|
|
|
dd59ef |
}
|
|
|
dd59ef |
#endif /* MOUNTED_GETMNTENT1. */
|
|
|
dd59ef |
|
|
|
dd59ef |
diff --git a/m4/ls-mntd-fs.m4 b/m4/ls-mntd-fs.m4
|
|
|
dd59ef |
index fb116c8..bc5ed82 100644
|
|
|
dd59ef |
--- a/m4/ls-mntd-fs.m4
|
|
|
dd59ef |
+++ b/m4/ls-mntd-fs.m4
|
|
|
dd59ef |
@@ -1,4 +1,4 @@
|
|
|
dd59ef |
-# serial 30
|
|
|
dd59ef |
+# serial 31
|
|
|
dd59ef |
# How to list mounted file systems.
|
|
|
dd59ef |
|
|
|
dd59ef |
# Copyright (C) 1998-2004, 2006, 2009-2013 Free Software Foundation, Inc.
|
|
|
dd59ef |
@@ -168,6 +168,19 @@ if test $ac_cv_func_getmntent = yes; then
|
|
|
dd59ef |
[Define if there is a function named getmntent for reading the list of
|
|
|
dd59ef |
mounted file systems, and that function takes two arguments. (SVR4)])
|
|
|
dd59ef |
AC_CHECK_FUNCS([hasmntopt])
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ # Check for libmount to support /proc/self/mountinfo on Linux
|
|
|
dd59ef |
+ AC_CACHE_VAL([ac_cv_lib_libmount_mnt_table_parse_stream],
|
|
|
dd59ef |
+ [AC_CHECK_LIB([mount], [mnt_new_table_from_file],
|
|
|
dd59ef |
+ ac_cv_lib_mount_mnt_table_parse_stream=yes,
|
|
|
dd59ef |
+ ac_cv_lib_mount_mnt_table_parse_stream=no)])
|
|
|
dd59ef |
+ if test $ac_cv_lib_mount_mnt_table_parse_stream = yes; then
|
|
|
dd59ef |
+ AC_DEFINE([MOUNTED_PROC_MOUNTINFO], [1],
|
|
|
dd59ef |
+ [Define if want to use /proc/self/mountinfo on Linux.])
|
|
|
dd59ef |
+ LIBS="-lmount $LIBS"
|
|
|
dd59ef |
+ elif test -f /proc/self/mountinfo; then
|
|
|
dd59ef |
+ AC_MSG_WARN([/proc/self/mountinfo present but libmount is missing.])
|
|
|
dd59ef |
+ fi
|
|
|
dd59ef |
fi
|
|
|
dd59ef |
fi
|
|
|
dd59ef |
|
|
|
dd59ef |
--
|
|
|
dd59ef |
2.17.2
|
|
|
dd59ef |
|
|
|
dd59ef |
|
|
|
dd59ef |
From 7e5e39933b60761dbd5ad1b0e2d8c075d72ef322 Mon Sep 17 00:00:00 2001
|
|
|
dd59ef |
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
|
|
|
dd59ef |
Date: Thu, 30 Oct 2014 04:08:50 +0000
|
|
|
dd59ef |
Subject: [PATCH 2/9] mountlist: don't use libmount to decide on dummy/remote
|
|
|
dd59ef |
|
|
|
dd59ef |
* lib/mountlist.c (read_file_system_list): Don't use the libmount
|
|
|
dd59ef |
routines to determine whether a file system is dummy or remote,
|
|
|
dd59ef |
as they're not currently compatible. For example the remoteness
|
|
|
dd59ef |
is determined on file system type (for which the list seems incomplete),
|
|
|
dd59ef |
rather than simply checking for a ':' in the device name.
|
|
|
dd59ef |
Also libmount currently determines that 'tmpfs' is a dummy file system
|
|
|
dd59ef |
even though it has associated storage.
|
|
|
dd59ef |
|
|
|
dd59ef |
Upstream-commit: 2768ceb7994506e2cfba88be3b6bd13ef5440a90
|
|
|
dd59ef |
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
|
|
|
dd59ef |
---
|
|
|
dd59ef |
lib/mountlist.c | 19 +++++++++++++------
|
|
|
dd59ef |
1 file changed, 13 insertions(+), 6 deletions(-)
|
|
|
dd59ef |
|
|
|
dd59ef |
diff --git a/lib/mountlist.c b/lib/mountlist.c
|
|
|
dd59ef |
index 617fa88..b01846c 100644
|
|
|
dd59ef |
--- a/lib/mountlist.c
|
|
|
dd59ef |
+++ b/lib/mountlist.c
|
|
|
dd59ef |
@@ -182,10 +182,9 @@
|
|
|
dd59ef |
we grant an exception to any with "bind" in its list of mount options.
|
|
|
dd59ef |
I.e., those are *not* dummy entries. */
|
|
|
dd59ef |
#ifdef MOUNTED_GETMNTENT1
|
|
|
dd59ef |
-# define ME_DUMMY(Fs_name, Fs_type, Fs_ent) \
|
|
|
dd59ef |
+# define ME_DUMMY(Fs_name, Fs_type, Bind) \
|
|
|
dd59ef |
(ME_DUMMY_0 (Fs_name, Fs_type) \
|
|
|
dd59ef |
- || (strcmp (Fs_type, "none") == 0 \
|
|
|
dd59ef |
- && !hasmntopt (Fs_ent, "bind")))
|
|
|
dd59ef |
+ || (strcmp (Fs_type, "none") == 0 && !Bind))
|
|
|
dd59ef |
#else
|
|
|
dd59ef |
# define ME_DUMMY(Fs_name, Fs_type) \
|
|
|
dd59ef |
(ME_DUMMY_0 (Fs_name, Fs_type) || strcmp (Fs_type, "none") == 0)
|
|
|
dd59ef |
@@ -457,8 +456,14 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
me->me_type = xstrdup (mnt_fs_get_fstype (fs));
|
|
|
dd59ef |
me->me_type_malloced = 1;
|
|
|
dd59ef |
me->me_dev = mnt_fs_get_devno (fs);
|
|
|
dd59ef |
- me->me_dummy = mnt_fs_is_pseudofs (fs);
|
|
|
dd59ef |
- me->me_remote = mnt_fs_is_netfs (fs);
|
|
|
dd59ef |
+ /* Note we don't use mnt_fs_is_pseudofs() or mnt_fs_is_netfs() here
|
|
|
dd59ef |
+ as libmount's classification is non-compatible currently.
|
|
|
dd59ef |
+ Also we pass "false" for the "Bind" option as that's only
|
|
|
dd59ef |
+ significant when the Fs_type is "none" which will not be
|
|
|
dd59ef |
+ the case when parsing "/proc/self/mountinfo", and only
|
|
|
dd59ef |
+ applies for static /etc/mtab files. */
|
|
|
dd59ef |
+ me->me_dummy = ME_DUMMY (me->me_devname, me->me_type, false);
|
|
|
dd59ef |
+ me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
|
|
|
dd59ef |
|
|
|
dd59ef |
/* Add to the linked list. */
|
|
|
dd59ef |
*mtail = me;
|
|
|
dd59ef |
@@ -481,12 +486,14 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
|
|
|
dd59ef |
while ((mnt = getmntent (fp)))
|
|
|
dd59ef |
{
|
|
|
dd59ef |
+ bool bind = hasmntopt (mnt, "bind");
|
|
|
dd59ef |
+
|
|
|
dd59ef |
me = xmalloc (sizeof *me);
|
|
|
dd59ef |
me->me_devname = xstrdup (mnt->mnt_fsname);
|
|
|
dd59ef |
me->me_mountdir = xstrdup (mnt->mnt_dir);
|
|
|
dd59ef |
me->me_type = xstrdup (mnt->mnt_type);
|
|
|
dd59ef |
me->me_type_malloced = 1;
|
|
|
dd59ef |
- me->me_dummy = ME_DUMMY (me->me_devname, me->me_type, mnt);
|
|
|
dd59ef |
+ me->me_dummy = ME_DUMMY (me->me_devname, me->me_type, bind);
|
|
|
dd59ef |
me->me_remote = ME_REMOTE (me->me_devname, me->me_type);
|
|
|
dd59ef |
me->me_dev = dev_from_mount_options (mnt->mnt_opts);
|
|
|
dd59ef |
|
|
|
dd59ef |
--
|
|
|
dd59ef |
2.17.2
|
|
|
dd59ef |
|
|
|
dd59ef |
|
|
|
dd59ef |
From e51d88d267c5222ed2bd852bc4701dfe87d8360a Mon Sep 17 00:00:00 2001
|
|
|
dd59ef |
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
|
|
|
dd59ef |
Date: Thu, 2 Apr 2015 04:18:02 +0100
|
|
|
dd59ef |
Subject: [PATCH 3/9] mountlist: remove dependency on libmount
|
|
|
dd59ef |
|
|
|
dd59ef |
* lib/mountlist.c (read_file_system_list): Parse /proc/self/mountinfo
|
|
|
dd59ef |
directly, rather than depending on libmount, which has many
|
|
|
dd59ef |
dependencies due to its dependence on libselinux, as detailed at:
|
|
|
dd59ef |
http://lists.gnu.org/archive/html/bug-gnulib/2015-01/msg00063.html
|
|
|
dd59ef |
Note we restrict this to __linux__ as that's probably where this
|
|
|
dd59ef |
interface will remain. If ever porting, it would be best
|
|
|
dd59ef |
to first pull the makedev() wrapper from coreutils to a gnulib module.
|
|
|
dd59ef |
Note also we don't add a getline dependency to the mountlist module,
|
|
|
dd59ef |
as all Linux versions are sufficient.
|
|
|
dd59ef |
|
|
|
dd59ef |
Upstream-commit: 3fb6e360363744462ce15c381f0b116c6fc4ce82
|
|
|
dd59ef |
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
|
|
|
dd59ef |
---
|
|
|
dd59ef |
lib/mountlist.c | 128 ++++++++++++++++++++++++++++++++++++-----------
|
|
|
dd59ef |
m4/ls-mntd-fs.m4 | 17 +------
|
|
|
dd59ef |
2 files changed, 102 insertions(+), 43 deletions(-)
|
|
|
dd59ef |
|
|
|
dd59ef |
diff --git a/lib/mountlist.c b/lib/mountlist.c
|
|
|
dd59ef |
index b01846c..2dbb245 100644
|
|
|
dd59ef |
--- a/lib/mountlist.c
|
|
|
dd59ef |
+++ b/lib/mountlist.c
|
|
|
dd59ef |
@@ -58,6 +58,7 @@
|
|
|
dd59ef |
|
|
|
dd59ef |
#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
|
|
dd59ef |
# include <mntent.h>
|
|
|
dd59ef |
+# include <sys/types.h>
|
|
|
dd59ef |
# if !defined MOUNTED
|
|
|
dd59ef |
# if defined _PATH_MOUNTED /* GNU libc */
|
|
|
dd59ef |
# define MOUNTED _PATH_MOUNTED
|
|
|
dd59ef |
@@ -128,12 +129,6 @@
|
|
|
dd59ef |
# include <sys/mntent.h>
|
|
|
dd59ef |
#endif
|
|
|
dd59ef |
|
|
|
dd59ef |
-#ifdef MOUNTED_PROC_MOUNTINFO
|
|
|
dd59ef |
-/* Use /proc/self/mountinfo instead of /proc/self/mounts (/etc/mtab)
|
|
|
dd59ef |
- * on Linux, if available */
|
|
|
dd59ef |
-# include <libmount/libmount.h>
|
|
|
dd59ef |
-#endif
|
|
|
dd59ef |
-
|
|
|
dd59ef |
#ifndef HAVE_HASMNTOPT
|
|
|
dd59ef |
# define hasmntopt(mnt, opt) ((char *) 0)
|
|
|
dd59ef |
#endif
|
|
|
dd59ef |
@@ -389,6 +384,34 @@ dev_from_mount_options (char const *mount_options)
|
|
|
dd59ef |
|
|
|
dd59ef |
#endif
|
|
|
dd59ef |
|
|
|
dd59ef |
+#if defined MOUNTED_GETMNTENT1 && defined __linux__
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+/* Unescape the paths in mount tables.
|
|
|
dd59ef |
+ STR is updated in place. */
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+static void
|
|
|
dd59ef |
+unescape_tab (char *str)
|
|
|
dd59ef |
+{
|
|
|
dd59ef |
+ size_t i, j = 0;
|
|
|
dd59ef |
+ size_t len = strlen (str) + 1;
|
|
|
dd59ef |
+ for (i = 0; i < len; i++)
|
|
|
dd59ef |
+ {
|
|
|
dd59ef |
+ if (str[i] == '\\' && (i + 4 < len)
|
|
|
dd59ef |
+ && str[i + 1] >= '0' && str[i + 1] <= '3'
|
|
|
dd59ef |
+ && str[i + 2] >= '0' && str[i + 2] <= '7'
|
|
|
dd59ef |
+ && str[i + 3] >= '0' && str[i + 3] <= '7')
|
|
|
dd59ef |
+ {
|
|
|
dd59ef |
+ str[j++] = (str[i + 1] - '0') * 64 +
|
|
|
dd59ef |
+ (str[i + 2] - '0') * 8 +
|
|
|
dd59ef |
+ (str[i + 3] - '0');
|
|
|
dd59ef |
+ i += 3;
|
|
|
dd59ef |
+ }
|
|
|
dd59ef |
+ else
|
|
|
dd59ef |
+ str[j++] = str[i];
|
|
|
dd59ef |
+ }
|
|
|
dd59ef |
+}
|
|
|
dd59ef |
+#endif
|
|
|
dd59ef |
+
|
|
|
dd59ef |
/* Return a list of the currently mounted file systems, or NULL on error.
|
|
|
dd59ef |
Add each entry to the tail of the list so that they stay in order.
|
|
|
dd59ef |
If NEED_FS_TYPE is true, ensure that the file system type fields in
|
|
|
dd59ef |
@@ -435,30 +458,70 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
|
|
|
dd59ef |
#ifdef MOUNTED_GETMNTENT1 /* GNU/Linux, 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
|
|
dd59ef |
{
|
|
|
dd59ef |
-#ifdef MOUNTED_PROC_MOUNTINFO
|
|
|
dd59ef |
- struct libmnt_table *fstable = NULL;
|
|
|
dd59ef |
-
|
|
|
dd59ef |
- fstable = mnt_new_table_from_file ("/proc/self/mountinfo");
|
|
|
dd59ef |
+ FILE *fp;
|
|
|
dd59ef |
|
|
|
dd59ef |
- if (fstable != NULL)
|
|
|
dd59ef |
+#ifdef __linux__
|
|
|
dd59ef |
+ /* Try parsing mountinfo first, as that make device IDs available.
|
|
|
dd59ef |
+ Note we could use libmount routines to simplify this parsing a little
|
|
|
dd59ef |
+ (and that code is in previous versions of this function), however
|
|
|
dd59ef |
+ libmount depends on libselinux which pulls in many dependencies. */
|
|
|
dd59ef |
+ char const *mountinfo = "/proc/self/mountinfo";
|
|
|
dd59ef |
+ fp = fopen (mountinfo, "r");
|
|
|
dd59ef |
+ if (fp != NULL)
|
|
|
dd59ef |
{
|
|
|
dd59ef |
- struct libmnt_fs *fs;
|
|
|
dd59ef |
- struct libmnt_iter *iter;
|
|
|
dd59ef |
+ char *line = NULL;
|
|
|
dd59ef |
+ size_t buf_size = 0;
|
|
|
dd59ef |
|
|
|
dd59ef |
- iter = mnt_new_iter (MNT_ITER_FORWARD);
|
|
|
dd59ef |
-
|
|
|
dd59ef |
- while (iter && mnt_table_next_fs (fstable, iter, &fs) == 0)
|
|
|
dd59ef |
+ while (getline (&line, &buf_size, fp) != -1)
|
|
|
dd59ef |
{
|
|
|
dd59ef |
+ unsigned int devmaj, devmin;
|
|
|
dd59ef |
+ int target_s, target_e, type_s, type_e, source_s, source_e;
|
|
|
dd59ef |
+ char test;
|
|
|
dd59ef |
+ char *dash;
|
|
|
dd59ef |
+ int rc;
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ rc = sscanf(line, "%*u " /* id - discarded */
|
|
|
dd59ef |
+ "%*u " /* parent - discarded */
|
|
|
dd59ef |
+ "%u:%u " /* dev major:minor */
|
|
|
dd59ef |
+ "%*s " /* mountroot - discarded */
|
|
|
dd59ef |
+ "%n%*s%n" /* target, start and end */
|
|
|
dd59ef |
+ "%c", /* more data... */
|
|
|
dd59ef |
+ &devmaj, &devmin,
|
|
|
dd59ef |
+ &target_s, &target_e,
|
|
|
dd59ef |
+ &test);
|
|
|
dd59ef |
+ if (rc != 3 && rc != 5) /* 5 if %n included in count. */
|
|
|
dd59ef |
+ continue;
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ /* skip optional fields, terminated by " - " */
|
|
|
dd59ef |
+ dash = strstr (line + target_e, " - ");
|
|
|
dd59ef |
+ if (! dash)
|
|
|
dd59ef |
+ continue;
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ rc = sscanf(dash, " - "
|
|
|
dd59ef |
+ "%n%*s%n " /* FS type, start and end */
|
|
|
dd59ef |
+ "%n%*s%n " /* source, start and end */
|
|
|
dd59ef |
+ "%c", /* more data... */
|
|
|
dd59ef |
+ &type_s, &type_e,
|
|
|
dd59ef |
+ &source_s, &source_e,
|
|
|
dd59ef |
+ &test);
|
|
|
dd59ef |
+ if (rc != 1 && rc != 5) /* 5 if %n included in count. */
|
|
|
dd59ef |
+ continue;
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ /* manipulate the sub-strings in place. */
|
|
|
dd59ef |
+ line[target_e] = '\0';
|
|
|
dd59ef |
+ dash[type_e] = '\0';
|
|
|
dd59ef |
+ dash[source_e] = '\0';
|
|
|
dd59ef |
+ unescape_tab (dash + source_s);
|
|
|
dd59ef |
+ unescape_tab (line + target_s);
|
|
|
dd59ef |
+
|
|
|
dd59ef |
me = xmalloc (sizeof *me);
|
|
|
dd59ef |
|
|
|
dd59ef |
- me->me_devname = xstrdup (mnt_fs_get_source (fs));
|
|
|
dd59ef |
- me->me_mountdir = xstrdup (mnt_fs_get_target (fs));
|
|
|
dd59ef |
- me->me_type = xstrdup (mnt_fs_get_fstype (fs));
|
|
|
dd59ef |
+ me->me_devname = xstrdup (dash + source_s);
|
|
|
dd59ef |
+ me->me_mountdir = xstrdup (line + target_s);
|
|
|
dd59ef |
+ me->me_type = xstrdup (dash + type_s);
|
|
|
dd59ef |
me->me_type_malloced = 1;
|
|
|
dd59ef |
- me->me_dev = mnt_fs_get_devno (fs);
|
|
|
dd59ef |
- /* Note we don't use mnt_fs_is_pseudofs() or mnt_fs_is_netfs() here
|
|
|
dd59ef |
- as libmount's classification is non-compatible currently.
|
|
|
dd59ef |
- Also we pass "false" for the "Bind" option as that's only
|
|
|
dd59ef |
+ me->me_dev = makedev (devmaj, devmin);
|
|
|
dd59ef |
+ /* we pass "false" for the "Bind" option as that's only
|
|
|
dd59ef |
significant when the Fs_type is "none" which will not be
|
|
|
dd59ef |
the case when parsing "/proc/self/mountinfo", and only
|
|
|
dd59ef |
applies for static /etc/mtab files. */
|
|
|
dd59ef |
@@ -470,13 +533,22 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
mtail = &me->me_next;
|
|
|
dd59ef |
}
|
|
|
dd59ef |
|
|
|
dd59ef |
- mnt_free_iter (iter);
|
|
|
dd59ef |
- mnt_free_table (fstable);
|
|
|
dd59ef |
+ free (line);
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ if (ferror (fp))
|
|
|
dd59ef |
+ {
|
|
|
dd59ef |
+ int saved_errno = errno;
|
|
|
dd59ef |
+ fclose (fp);
|
|
|
dd59ef |
+ errno = saved_errno;
|
|
|
dd59ef |
+ goto free_then_fail;
|
|
|
dd59ef |
+ }
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ if (fclose (fp) == EOF)
|
|
|
dd59ef |
+ goto free_then_fail;
|
|
|
dd59ef |
}
|
|
|
dd59ef |
- else /* fallback to /proc/self/mounts (/etc/mtab) if anything failed */
|
|
|
dd59ef |
-#endif /* MOUNTED_PROC_MOUNTINFO */
|
|
|
dd59ef |
+ else /* fallback to /proc/self/mounts (/etc/mtab). */
|
|
|
dd59ef |
+#endif /* __linux __ */
|
|
|
dd59ef |
{
|
|
|
dd59ef |
- FILE * fp;
|
|
|
dd59ef |
struct mntent *mnt;
|
|
|
dd59ef |
char const *table = MOUNTED;
|
|
|
dd59ef |
|
|
|
dd59ef |
diff --git a/m4/ls-mntd-fs.m4 b/m4/ls-mntd-fs.m4
|
|
|
dd59ef |
index bc5ed82..412fbfc 100644
|
|
|
dd59ef |
--- a/m4/ls-mntd-fs.m4
|
|
|
dd59ef |
+++ b/m4/ls-mntd-fs.m4
|
|
|
dd59ef |
@@ -1,4 +1,4 @@
|
|
|
dd59ef |
-# serial 31
|
|
|
dd59ef |
+# serial 32
|
|
|
dd59ef |
# How to list mounted file systems.
|
|
|
dd59ef |
|
|
|
dd59ef |
# Copyright (C) 1998-2004, 2006, 2009-2013 Free Software Foundation, Inc.
|
|
|
dd59ef |
@@ -120,7 +120,7 @@ if test $ac_cv_func_getmntent = yes; then
|
|
|
dd59ef |
# Determine whether it's the one-argument variant or the two-argument one.
|
|
|
dd59ef |
|
|
|
dd59ef |
if test -z "$ac_list_mounted_fs"; then
|
|
|
dd59ef |
- # 4.3BSD, SunOS, HP-UX, Dynix, Irix
|
|
|
dd59ef |
+ # GNU/Linux, 4.3BSD, SunOS, HP-UX, Dynix, Irix
|
|
|
dd59ef |
AC_MSG_CHECKING([for one-argument getmntent function])
|
|
|
dd59ef |
AC_CACHE_VAL([fu_cv_sys_mounted_getmntent1],
|
|
|
dd59ef |
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
|
|
dd59ef |
@@ -168,19 +168,6 @@ if test $ac_cv_func_getmntent = yes; then
|
|
|
dd59ef |
[Define if there is a function named getmntent for reading the list of
|
|
|
dd59ef |
mounted file systems, and that function takes two arguments. (SVR4)])
|
|
|
dd59ef |
AC_CHECK_FUNCS([hasmntopt])
|
|
|
dd59ef |
-
|
|
|
dd59ef |
- # Check for libmount to support /proc/self/mountinfo on Linux
|
|
|
dd59ef |
- AC_CACHE_VAL([ac_cv_lib_libmount_mnt_table_parse_stream],
|
|
|
dd59ef |
- [AC_CHECK_LIB([mount], [mnt_new_table_from_file],
|
|
|
dd59ef |
- ac_cv_lib_mount_mnt_table_parse_stream=yes,
|
|
|
dd59ef |
- ac_cv_lib_mount_mnt_table_parse_stream=no)])
|
|
|
dd59ef |
- if test $ac_cv_lib_mount_mnt_table_parse_stream = yes; then
|
|
|
dd59ef |
- AC_DEFINE([MOUNTED_PROC_MOUNTINFO], [1],
|
|
|
dd59ef |
- [Define if want to use /proc/self/mountinfo on Linux.])
|
|
|
dd59ef |
- LIBS="-lmount $LIBS"
|
|
|
dd59ef |
- elif test -f /proc/self/mountinfo; then
|
|
|
dd59ef |
- AC_MSG_WARN([/proc/self/mountinfo present but libmount is missing.])
|
|
|
dd59ef |
- fi
|
|
|
dd59ef |
fi
|
|
|
dd59ef |
fi
|
|
|
dd59ef |
|
|
|
dd59ef |
--
|
|
|
dd59ef |
2.17.2
|
|
|
dd59ef |
|
|
|
dd59ef |
|
|
|
dd59ef |
From a6a7c39b36699fdbbb57679f2f71fc3ae08e8ba2 Mon Sep 17 00:00:00 2001
|
|
|
dd59ef |
From: Dave Chiluk <chiluk@canonical.com>
|
|
|
dd59ef |
Date: Mon, 31 Aug 2015 16:07:58 -0500
|
|
|
dd59ef |
Subject: [PATCH 4/9] mountlist: add me_mntroot field on Linux machines
|
|
|
dd59ef |
|
|
|
dd59ef |
* lib/mountlist.c (read_file_system_list): Populate me_mntroot in
|
|
|
dd59ef |
mount_entry so Linux machines based on /proc/self/mountinfo can
|
|
|
dd59ef |
distinguish between bind mounts and original mounts. In reality bind
|
|
|
dd59ef |
mounts aren't treated differently than mountroot=/ mounts by the
|
|
|
dd59ef |
kernel, but the user often wants these bind mounts distinguished.
|
|
|
dd59ef |
* lib/mountlist.h (struct mount_entry): Add me_mntroot element.
|
|
|
dd59ef |
More details at https://pad.lv/1432871
|
|
|
dd59ef |
|
|
|
dd59ef |
Upstream-commit: c6148bca89e9465fd6ba3a10d273ec4cb58c2dbe
|
|
|
dd59ef |
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
|
|
|
dd59ef |
---
|
|
|
dd59ef |
lib/mountlist.c | 25 ++++++++++++++++++++++---
|
|
|
dd59ef |
lib/mountlist.h | 2 ++
|
|
|
dd59ef |
2 files changed, 24 insertions(+), 3 deletions(-)
|
|
|
dd59ef |
|
|
|
dd59ef |
diff --git a/lib/mountlist.c b/lib/mountlist.c
|
|
|
dd59ef |
index 2dbb245..f4d285a 100644
|
|
|
dd59ef |
--- a/lib/mountlist.c
|
|
|
dd59ef |
+++ b/lib/mountlist.c
|
|
|
dd59ef |
@@ -444,6 +444,7 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
me = xmalloc (sizeof *me);
|
|
|
dd59ef |
me->me_devname = xstrdup (mnt->mnt_fsname);
|
|
|
dd59ef |
me->me_mountdir = xstrdup (mnt->mnt_dir);
|
|
|
dd59ef |
+ me->me_mntroot = NULL;
|
|
|
dd59ef |
me->me_type = xstrdup (mnt->mnt_type);
|
|
|
dd59ef |
me->me_type_malloced = 1;
|
|
|
dd59ef |
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
|
|
|
dd59ef |
@@ -475,7 +476,8 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
while (getline (&line, &buf_size, fp) != -1)
|
|
|
dd59ef |
{
|
|
|
dd59ef |
unsigned int devmaj, devmin;
|
|
|
dd59ef |
- int target_s, target_e, type_s, type_e, source_s, source_e;
|
|
|
dd59ef |
+ int target_s, target_e, type_s, type_e;
|
|
|
dd59ef |
+ int source_s, source_e, mntroot_s, mntroot_e;
|
|
|
dd59ef |
char test;
|
|
|
dd59ef |
char *dash;
|
|
|
dd59ef |
int rc;
|
|
|
dd59ef |
@@ -483,13 +485,15 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
rc = sscanf(line, "%*u " /* id - discarded */
|
|
|
dd59ef |
"%*u " /* parent - discarded */
|
|
|
dd59ef |
"%u:%u " /* dev major:minor */
|
|
|
dd59ef |
- "%*s " /* mountroot - discarded */
|
|
|
dd59ef |
+ "%n%*s%n " /* mountroot */
|
|
|
dd59ef |
"%n%*s%n" /* target, start and end */
|
|
|
dd59ef |
"%c", /* more data... */
|
|
|
dd59ef |
&devmaj, &devmin,
|
|
|
dd59ef |
+ &mntroot_s, &mntroot_e,
|
|
|
dd59ef |
&target_s, &target_e,
|
|
|
dd59ef |
&test);
|
|
|
dd59ef |
- if (rc != 3 && rc != 5) /* 5 if %n included in count. */
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ if (rc != 3 && rc != 7) /* 7 if %n included in count. */
|
|
|
dd59ef |
continue;
|
|
|
dd59ef |
|
|
|
dd59ef |
/* skip optional fields, terminated by " - " */
|
|
|
dd59ef |
@@ -508,16 +512,19 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
continue;
|
|
|
dd59ef |
|
|
|
dd59ef |
/* manipulate the sub-strings in place. */
|
|
|
dd59ef |
+ line[mntroot_e] = '\0';
|
|
|
dd59ef |
line[target_e] = '\0';
|
|
|
dd59ef |
dash[type_e] = '\0';
|
|
|
dd59ef |
dash[source_e] = '\0';
|
|
|
dd59ef |
unescape_tab (dash + source_s);
|
|
|
dd59ef |
unescape_tab (line + target_s);
|
|
|
dd59ef |
+ unescape_tab (line + mntroot_s);
|
|
|
dd59ef |
|
|
|
dd59ef |
me = xmalloc (sizeof *me);
|
|
|
dd59ef |
|
|
|
dd59ef |
me->me_devname = xstrdup (dash + source_s);
|
|
|
dd59ef |
me->me_mountdir = xstrdup (line + target_s);
|
|
|
dd59ef |
+ me->me_mntroot = xstrdup (line + mntroot_s);
|
|
|
dd59ef |
me->me_type = xstrdup (dash + type_s);
|
|
|
dd59ef |
me->me_type_malloced = 1;
|
|
|
dd59ef |
me->me_dev = makedev (devmaj, devmin);
|
|
|
dd59ef |
@@ -563,6 +570,7 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
me = xmalloc (sizeof *me);
|
|
|
dd59ef |
me->me_devname = xstrdup (mnt->mnt_fsname);
|
|
|
dd59ef |
me->me_mountdir = xstrdup (mnt->mnt_dir);
|
|
|
dd59ef |
+ me->me_mntroot = NULL;
|
|
|
dd59ef |
me->me_type = xstrdup (mnt->mnt_type);
|
|
|
dd59ef |
me->me_type_malloced = 1;
|
|
|
dd59ef |
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type, bind);
|
|
|
dd59ef |
@@ -595,6 +603,7 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
me = xmalloc (sizeof *me);
|
|
|
dd59ef |
me->me_devname = xstrdup (fsp->f_mntfromname);
|
|
|
dd59ef |
me->me_mountdir = xstrdup (fsp->f_mntonname);
|
|
|
dd59ef |
+ me->me_mntroot = NULL;
|
|
|
dd59ef |
me->me_type = fs_type;
|
|
|
dd59ef |
me->me_type_malloced = 0;
|
|
|
dd59ef |
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
|
|
|
dd59ef |
@@ -621,6 +630,7 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
me = xmalloc (sizeof *me);
|
|
|
dd59ef |
me->me_devname = xstrdup (fsp->f_mntfromname);
|
|
|
dd59ef |
me->me_mountdir = xstrdup (fsp->f_mntonname);
|
|
|
dd59ef |
+ me->me_mntroot = NULL;
|
|
|
dd59ef |
me->me_type = xstrdup (fsp->f_fstypename);
|
|
|
dd59ef |
me->me_type_malloced = 1;
|
|
|
dd59ef |
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
|
|
|
dd59ef |
@@ -647,6 +657,7 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
me = xmalloc (sizeof *me);
|
|
|
dd59ef |
me->me_devname = xstrdup (fsd.fd_req.devname);
|
|
|
dd59ef |
me->me_mountdir = xstrdup (fsd.fd_req.path);
|
|
|
dd59ef |
+ me->me_mntroot = NULL;
|
|
|
dd59ef |
me->me_type = gt_names[fsd.fd_req.fstype];
|
|
|
dd59ef |
me->me_type_malloced = 0;
|
|
|
dd59ef |
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
|
|
|
dd59ef |
@@ -745,6 +756,7 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
me->me_devname = xstrdup (fi.device_name[0] != '\0'
|
|
|
dd59ef |
? fi.device_name : fi.fsh_name);
|
|
|
dd59ef |
me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name);
|
|
|
dd59ef |
+ me->me_mntroot = NULL;
|
|
|
dd59ef |
me->me_type = xstrdup (fi.fsh_name);
|
|
|
dd59ef |
me->me_type_malloced = 1;
|
|
|
dd59ef |
me->me_dev = fi.dev;
|
|
|
dd59ef |
@@ -794,6 +806,7 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
me = xmalloc (sizeof *me);
|
|
|
dd59ef |
me->me_devname = xstrdup (stats[counter].f_mntfromname);
|
|
|
dd59ef |
me->me_mountdir = xstrdup (stats[counter].f_mntonname);
|
|
|
dd59ef |
+ me->me_mntroot = NULL;
|
|
|
dd59ef |
me->me_type = xstrdup (FS_TYPE (stats[counter]));
|
|
|
dd59ef |
me->me_type_malloced = 1;
|
|
|
dd59ef |
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
|
|
|
dd59ef |
@@ -830,6 +843,7 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
strcpy (me->me_devname + 5, mnt.mt_dev);
|
|
|
dd59ef |
# endif
|
|
|
dd59ef |
me->me_mountdir = xstrdup (mnt.mt_filsys);
|
|
|
dd59ef |
+ me->me_mntroot = NULL;
|
|
|
dd59ef |
me->me_dev = (dev_t) -1; /* Magic; means not known yet. */
|
|
|
dd59ef |
me->me_type = "";
|
|
|
dd59ef |
me->me_type_malloced = 0;
|
|
|
dd59ef |
@@ -877,6 +891,7 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
me = xmalloc (sizeof *me);
|
|
|
dd59ef |
me->me_devname = xstrdup ((*ent)->mt_resource);
|
|
|
dd59ef |
me->me_mountdir = xstrdup ((*ent)->mt_directory);
|
|
|
dd59ef |
+ me->me_mntroot = NULL;
|
|
|
dd59ef |
me->me_type = xstrdup ((*ent)->mt_fstype);
|
|
|
dd59ef |
me->me_type_malloced = 1;
|
|
|
dd59ef |
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
|
|
|
dd59ef |
@@ -939,6 +954,7 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
me = xmalloc (sizeof *me);
|
|
|
dd59ef |
me->me_devname = xstrdup (mnt.mnt_special);
|
|
|
dd59ef |
me->me_mountdir = xstrdup (mnt.mnt_mountp);
|
|
|
dd59ef |
+ me->me_mntroot = NULL;
|
|
|
dd59ef |
me->me_type = xstrdup (mnt.mnt_fstype);
|
|
|
dd59ef |
me->me_type_malloced = 1;
|
|
|
dd59ef |
me->me_dummy = MNT_IGNORE (&mnt) != 0;
|
|
|
dd59ef |
@@ -1015,6 +1031,7 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
vmp->vmt_data[VMT_OBJECT].vmt_off);
|
|
|
dd59ef |
}
|
|
|
dd59ef |
me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off);
|
|
|
dd59ef |
+ me->me_mntroot = NULL;
|
|
|
dd59ef |
me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype));
|
|
|
dd59ef |
me->me_type_malloced = 1;
|
|
|
dd59ef |
options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off;
|
|
|
dd59ef |
@@ -1058,6 +1075,7 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
me = xmalloc (sizeof *me);
|
|
|
dd59ef |
me->me_devname = xstrdup (dev.f_mntfromname);
|
|
|
dd59ef |
me->me_mountdir = xstrdup (dev.f_mntonname);
|
|
|
dd59ef |
+ me->me_mntroot = NULL;
|
|
|
dd59ef |
me->me_type = xstrdup (dev.f_fstypename);
|
|
|
dd59ef |
me->me_type_malloced = 1;
|
|
|
dd59ef |
me->me_dummy = ME_DUMMY (me->me_devname, me->me_type);
|
|
|
dd59ef |
@@ -1100,6 +1118,7 @@ void free_mount_entry (struct mount_entry *me)
|
|
|
dd59ef |
{
|
|
|
dd59ef |
free (me->me_devname);
|
|
|
dd59ef |
free (me->me_mountdir);
|
|
|
dd59ef |
+ free (me->me_mntroot);
|
|
|
dd59ef |
if (me->me_type_malloced)
|
|
|
dd59ef |
free (me->me_type);
|
|
|
dd59ef |
free (me);
|
|
|
dd59ef |
diff --git a/lib/mountlist.h b/lib/mountlist.h
|
|
|
dd59ef |
index 55877e2..1872b2b 100644
|
|
|
dd59ef |
--- a/lib/mountlist.h
|
|
|
dd59ef |
+++ b/lib/mountlist.h
|
|
|
dd59ef |
@@ -27,6 +27,8 @@ struct mount_entry
|
|
|
dd59ef |
{
|
|
|
dd59ef |
char *me_devname; /* Device node name, including "/dev/". */
|
|
|
dd59ef |
char *me_mountdir; /* Mount point directory name. */
|
|
|
dd59ef |
+ char *me_mntroot; /* Directory on filesystem of device used */
|
|
|
dd59ef |
+ /* as root for the (bind) mount. */
|
|
|
dd59ef |
char *me_type; /* "nfs", "4.2", etc. */
|
|
|
dd59ef |
dev_t me_dev; /* Device number of me_mountdir. */
|
|
|
dd59ef |
unsigned int me_dummy : 1; /* Nonzero for dummy file systems. */
|
|
|
dd59ef |
--
|
|
|
dd59ef |
2.17.2
|
|
|
dd59ef |
|
|
|
dd59ef |
|
|
|
dd59ef |
From 6b301e5f89d4555e33b267e3ea5a709a4b584038 Mon Sep 17 00:00:00 2001
|
|
|
dd59ef |
From: Andrew Borodin <aborodin@vmail.ru>
|
|
|
dd59ef |
Date: Sun, 27 Sep 2015 11:41:17 +0300
|
|
|
dd59ef |
Subject: [PATCH 5/9] mountlist: clean up of variable duplication
|
|
|
dd59ef |
|
|
|
dd59ef |
* lib/mountlist.c (read_file_system_list) [MOUNTED_LISTMNTENT]:
|
|
|
dd59ef |
the 'me' variable is already declared above. Remove it here.
|
|
|
dd59ef |
|
|
|
dd59ef |
Upstream-commit: 1eda6d17e93fa496368f82cac6317b8045cc9373
|
|
|
dd59ef |
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
|
|
|
dd59ef |
---
|
|
|
dd59ef |
lib/mountlist.c | 1 -
|
|
|
dd59ef |
1 file changed, 1 deletion(-)
|
|
|
dd59ef |
|
|
|
dd59ef |
diff --git a/lib/mountlist.c b/lib/mountlist.c
|
|
|
dd59ef |
index f4d285a..6f66996 100644
|
|
|
dd59ef |
--- a/lib/mountlist.c
|
|
|
dd59ef |
+++ b/lib/mountlist.c
|
|
|
dd59ef |
@@ -429,7 +429,6 @@ read_file_system_list (bool need_fs_type)
|
|
|
dd59ef |
{
|
|
|
dd59ef |
struct tabmntent *mntlist, *p;
|
|
|
dd59ef |
struct mntent *mnt;
|
|
|
dd59ef |
- struct mount_entry *me;
|
|
|
dd59ef |
|
|
|
dd59ef |
/* the third and fourth arguments could be used to filter mounts,
|
|
|
dd59ef |
but Crays doesn't seem to have any mounts that we want to
|
|
|
dd59ef |
--
|
|
|
dd59ef |
2.17.2
|
|
|
dd59ef |
|
|
|
dd59ef |
|
|
|
dd59ef |
From b2063df8d13fc279f3fa38d1315e3ff3f66c70e5 Mon Sep 17 00:00:00 2001
|
|
|
dd59ef |
From: Eric Blake <eblake@redhat.com>
|
|
|
dd59ef |
Date: Wed, 14 Sep 2016 19:21:42 -0500
|
|
|
dd59ef |
Subject: [PATCH 6/9] mountlist: include sysmacros.h for glibc
|
|
|
dd59ef |
|
|
|
dd59ef |
On Fedora rawhide (glibc 2.25), './gnulib-tool --test mountlist'
|
|
|
dd59ef |
reports:
|
|
|
dd59ef |
../../gllib/mountlist.c: In function 'read_file_system_list':
|
|
|
dd59ef |
../../gllib/mountlist.c:534:13: warning: '__makedev_from_sys_types' is deprecated:
|
|
|
dd59ef |
In the GNU C Library, `makedev' is defined by <sys/sysmacros.h>.
|
|
|
dd59ef |
For historical compatibility, it is currently defined by
|
|
|
dd59ef |
<sys/types.h> as well, but we plan to remove this soon.
|
|
|
dd59ef |
To use `makedev', include <sys/sysmacros.h> directly.
|
|
|
dd59ef |
If you did not intend to use a system-defined macro `makedev',
|
|
|
dd59ef |
you should #undef it after including <sys/types.h>.
|
|
|
dd59ef |
[-Wdeprecated-declarations]
|
|
|
dd59ef |
me->me_dev = makedev (devmaj, devmin);
|
|
|
dd59ef |
^~
|
|
|
dd59ef |
In file included from /usr/include/features.h:397:0,
|
|
|
dd59ef |
from /usr/include/sys/types.h:25,
|
|
|
dd59ef |
from ./sys/types.h:28,
|
|
|
dd59ef |
from ../../gllib/mountlist.h:23,
|
|
|
dd59ef |
from ../../gllib/mountlist.c:20:
|
|
|
dd59ef |
/usr/include/sys/sysmacros.h:89:1: note: declared here
|
|
|
dd59ef |
__SYSMACROS_DEFINE_MAKEDEV (__SYSMACROS_FST_IMPL_TEMPL)
|
|
|
dd59ef |
^
|
|
|
dd59ef |
|
|
|
dd59ef |
Fix it by including the right headers. We also need a fix to
|
|
|
dd59ef |
autoconf's AC_HEADER_MAJOR, but that's a separate patch.
|
|
|
dd59ef |
|
|
|
dd59ef |
* m4/mountlist.m4 (gl_PREREQ_MOUTLIST_EXTRA): Include
|
|
|
dd59ef |
AC_HEADER_MAJOR.
|
|
|
dd59ef |
* lib/mountlist.c (includes): Use correct headers.
|
|
|
dd59ef |
|
|
|
dd59ef |
Signed-off-by: Eric Blake <eblake@redhat.com>
|
|
|
dd59ef |
|
|
|
dd59ef |
Upstream-commit: 4da63c5881f60f71999a943612da9112232b9161
|
|
|
dd59ef |
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
|
|
|
dd59ef |
---
|
|
|
dd59ef |
lib/mountlist.c | 6 ++++++
|
|
|
dd59ef |
m4/mountlist.m4 | 3 ++-
|
|
|
dd59ef |
2 files changed, 8 insertions(+), 1 deletion(-)
|
|
|
dd59ef |
|
|
|
dd59ef |
diff --git a/lib/mountlist.c b/lib/mountlist.c
|
|
|
dd59ef |
index 6f66996..40338ac 100644
|
|
|
dd59ef |
--- a/lib/mountlist.c
|
|
|
dd59ef |
+++ b/lib/mountlist.c
|
|
|
dd59ef |
@@ -37,6 +37,12 @@
|
|
|
dd59ef |
# include <sys/param.h>
|
|
|
dd59ef |
#endif
|
|
|
dd59ef |
|
|
|
dd59ef |
+#if MAJOR_IN_MKDEV
|
|
|
dd59ef |
+# include <sys/mkdev.h>
|
|
|
dd59ef |
+#elif MAJOR_IN_SYSMACROS
|
|
|
dd59ef |
+# include <sys/sysmacros.h>
|
|
|
dd59ef |
+#endif
|
|
|
dd59ef |
+
|
|
|
dd59ef |
#if defined MOUNTED_GETFSSTAT /* OSF_1 and Darwin1.3.x */
|
|
|
dd59ef |
# if HAVE_SYS_UCRED_H
|
|
|
dd59ef |
# include <grp.h> /* needed on OSF V4.0 for definition of NGROUPS,
|
|
|
dd59ef |
diff --git a/m4/mountlist.m4 b/m4/mountlist.m4
|
|
|
dd59ef |
index cd137c9..2f47ce2 100644
|
|
|
dd59ef |
--- a/m4/mountlist.m4
|
|
|
dd59ef |
+++ b/m4/mountlist.m4
|
|
|
dd59ef |
@@ -1,4 +1,4 @@
|
|
|
dd59ef |
-# serial 11
|
|
|
dd59ef |
+# serial 12
|
|
|
dd59ef |
dnl Copyright (C) 2002-2006, 2009-2013 Free Software Foundation, Inc.
|
|
|
dd59ef |
dnl This file is free software; the Free Software Foundation
|
|
|
dd59ef |
dnl gives unlimited permission to copy and/or distribute it,
|
|
|
dd59ef |
@@ -15,5 +15,6 @@ AC_DEFUN([gl_PREREQ_MOUNTLIST_EXTRA],
|
|
|
dd59ef |
[
|
|
|
dd59ef |
dnl Note gl_LIST_MOUNTED_FILE_SYSTEMS checks for mntent.h, not sys/mntent.h.
|
|
|
dd59ef |
AC_CHECK_HEADERS([sys/mntent.h])
|
|
|
dd59ef |
+ AC_HEADER_MAJOR()dnl for use of makedev ()
|
|
|
dd59ef |
gl_FSTYPENAME
|
|
|
dd59ef |
])
|
|
|
dd59ef |
--
|
|
|
dd59ef |
2.17.2
|
|
|
dd59ef |
|
|
|
dd59ef |
|
|
|
dd59ef |
From 472ef28870dce7ca7505fa2ca477040da347a567 Mon Sep 17 00:00:00 2001
|
|
|
dd59ef |
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
|
|
|
dd59ef |
Date: Thu, 2 Apr 2015 05:34:07 +0100
|
|
|
dd59ef |
Subject: [PATCH 7/9] df: fix use of uninitialized variable reported by
|
|
|
dd59ef |
valgrind
|
|
|
dd59ef |
|
|
|
dd59ef |
Conditional jump or move depends on uninitialised value(s)
|
|
|
dd59ef |
at 0x40380C: get_field_values (df.c:840)
|
|
|
dd59ef |
by 0x403E16: get_dev (df.c:994)
|
|
|
dd59ef |
by 0x404D65: get_all_entries (df.c:1364)
|
|
|
dd59ef |
by 0x405926: main (df.c:1714)
|
|
|
dd59ef |
|
|
|
dd59ef |
* src/df.c (get_dev): Initialize the fsu.fsu_bavail_top_bit_set
|
|
|
dd59ef |
member, when adding placeholder entries.
|
|
|
dd59ef |
(main): Avoid a "definitely lost" memory leak warning from valgrind,
|
|
|
dd59ef |
reported by Bernhard Voelker.
|
|
|
dd59ef |
|
|
|
dd59ef |
Upstream-commit: bf180f8f5a53eb82054e85e26dcd1ea7c43dbdfe
|
|
|
dd59ef |
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
|
|
|
dd59ef |
---
|
|
|
dd59ef |
src/df.c | 4 ++++
|
|
|
dd59ef |
1 file changed, 4 insertions(+)
|
|
|
dd59ef |
|
|
|
dd59ef |
diff --git a/src/df.c b/src/df.c
|
|
|
dd59ef |
index ce11b50..5ffd0a5 100644
|
|
|
dd59ef |
--- a/src/df.c
|
|
|
dd59ef |
+++ b/src/df.c
|
|
|
dd59ef |
@@ -935,6 +935,7 @@ get_dev (char const *disk, char const *mount_point, char const* file,
|
|
|
dd59ef |
return;
|
|
|
dd59ef |
|
|
|
dd59ef |
fstype = "-";
|
|
|
dd59ef |
+ fsu.fsu_bavail_top_bit_set = false;
|
|
|
dd59ef |
fsu.fsu_blocksize = fsu.fsu_blocks = fsu.fsu_bfree =
|
|
|
dd59ef |
fsu.fsu_bavail = fsu.fsu_files = fsu.fsu_ffree = UINTMAX_MAX;
|
|
|
dd59ef |
}
|
|
|
dd59ef |
@@ -959,6 +960,7 @@ get_dev (char const *disk, char const *mount_point, char const* file,
|
|
|
dd59ef |
&& (! dev_me->me_remote || ! me_remote))
|
|
|
dd59ef |
{
|
|
|
dd59ef |
fstype = "-";
|
|
|
dd59ef |
+ fsu.fsu_bavail_top_bit_set = false;
|
|
|
dd59ef |
fsu.fsu_blocksize = fsu.fsu_blocks = fsu.fsu_bfree =
|
|
|
dd59ef |
fsu.fsu_bavail = fsu.fsu_files = fsu.fsu_ffree = UINTMAX_MAX;
|
|
|
dd59ef |
}
|
|
|
dd59ef |
@@ -1736,6 +1738,8 @@ main (int argc, char **argv)
|
|
|
dd59ef |
for (i = optind; i < argc; ++i)
|
|
|
dd59ef |
if (argv[i])
|
|
|
dd59ef |
get_entry (argv[i], &stats[i - optind]);
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ IF_LINT (free (stats));
|
|
|
dd59ef |
}
|
|
|
dd59ef |
else
|
|
|
dd59ef |
get_all_entries ();
|
|
|
dd59ef |
--
|
|
|
dd59ef |
2.17.2
|
|
|
dd59ef |
|
|
|
dd59ef |
|
|
|
dd59ef |
From fc6104cc9d8d2908b3225b035def82d3a95bdfd0 Mon Sep 17 00:00:00 2001
|
|
|
dd59ef |
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
|
|
|
dd59ef |
Date: Sun, 5 Apr 2015 18:21:38 +0100
|
|
|
dd59ef |
Subject: [PATCH 8/9] df: fix --local hanging with inaccessible remote mounts
|
|
|
dd59ef |
|
|
|
dd59ef |
* src/df.c (filter_mount_list): With -l, avoid stating remote mounts.
|
|
|
dd59ef |
* init.cfg: Avoid test hangs with inaccessible remote mounts.
|
|
|
dd59ef |
* tests/df/no-mtab-status.sh: Skip with inaccessible remote mounts.
|
|
|
dd59ef |
* tests/df/skip-rootfs.sh: Likewise.
|
|
|
dd59ef |
* tests/df/total-verify.sh: Likewise.
|
|
|
dd59ef |
* NEWS: Mention the bug fix.
|
|
|
dd59ef |
Reported at http://bugzilla.redhat.com/1199679
|
|
|
dd59ef |
|
|
|
dd59ef |
Upstream-commit: 1b1c40e1d6f8cf30b6c7c9d31bbddbc3d5cc72e6
|
|
|
dd59ef |
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
|
|
|
dd59ef |
---
|
|
|
dd59ef |
init.cfg | 2 +-
|
|
|
dd59ef |
tests/df/no-mtab-status.sh | 3 ++-
|
|
|
dd59ef |
tests/df/skip-rootfs.sh | 3 ++-
|
|
|
dd59ef |
tests/df/total-verify.sh | 3 ++-
|
|
|
dd59ef |
4 files changed, 7 insertions(+), 4 deletions(-)
|
|
|
dd59ef |
|
|
|
dd59ef |
diff --git a/init.cfg b/init.cfg
|
|
|
dd59ef |
index 3364a73..d5a80bb 100644
|
|
|
dd59ef |
--- a/init.cfg
|
|
|
dd59ef |
+++ b/init.cfg
|
|
|
dd59ef |
@@ -79,7 +79,7 @@ is_local_dir_()
|
|
|
dd59ef |
require_mount_list_()
|
|
|
dd59ef |
{
|
|
|
dd59ef |
local mount_list_fail='cannot read table of mounted file systems'
|
|
|
dd59ef |
- df 2>&1 | grep -F "$mount_list_fail" >/dev/null &&
|
|
|
dd59ef |
+ df --local 2>&1 | grep -F "$mount_list_fail" >/dev/null &&
|
|
|
dd59ef |
skip_ "$mount_list_fail"
|
|
|
dd59ef |
}
|
|
|
dd59ef |
|
|
|
dd59ef |
diff --git a/tests/df/no-mtab-status.sh b/tests/df/no-mtab-status.sh
|
|
|
dd59ef |
index 2e6b61b..9b6b9d3 100755
|
|
|
dd59ef |
--- a/tests/df/no-mtab-status.sh
|
|
|
dd59ef |
+++ b/tests/df/no-mtab-status.sh
|
|
|
dd59ef |
@@ -21,7 +21,8 @@
|
|
|
dd59ef |
print_ver_ df
|
|
|
dd59ef |
require_gcc_shared_
|
|
|
dd59ef |
|
|
|
dd59ef |
-df || skip_ "df fails"
|
|
|
dd59ef |
+# Protect against inaccessible remote mounts etc.
|
|
|
dd59ef |
+timeout 10 df || skip_ "df fails"
|
|
|
dd59ef |
|
|
|
dd59ef |
# Simulate "mtab" failure.
|
|
|
dd59ef |
cat > k.c <<'EOF' || framework_failure_
|
|
|
dd59ef |
diff --git a/tests/df/skip-rootfs.sh b/tests/df/skip-rootfs.sh
|
|
|
dd59ef |
index 9c5d0a9..b79751e 100755
|
|
|
dd59ef |
--- a/tests/df/skip-rootfs.sh
|
|
|
dd59ef |
+++ b/tests/df/skip-rootfs.sh
|
|
|
dd59ef |
@@ -19,7 +19,8 @@
|
|
|
dd59ef |
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
|
|
|
dd59ef |
print_ver_ df
|
|
|
dd59ef |
|
|
|
dd59ef |
-df || skip_ "df fails"
|
|
|
dd59ef |
+# Protect against inaccessible remote mounts etc.
|
|
|
dd59ef |
+timeout 10 df || skip_ "df fails"
|
|
|
dd59ef |
|
|
|
dd59ef |
# Verify that rootfs is in mtab (and shown when the -a option is specified).
|
|
|
dd59ef |
df -a >out || fail=1
|
|
|
dd59ef |
diff --git a/tests/df/total-verify.sh b/tests/df/total-verify.sh
|
|
|
dd59ef |
index a045ccf..f05a91e 100755
|
|
|
dd59ef |
--- a/tests/df/total-verify.sh
|
|
|
dd59ef |
+++ b/tests/df/total-verify.sh
|
|
|
dd59ef |
@@ -20,7 +20,8 @@
|
|
|
dd59ef |
print_ver_ df
|
|
|
dd59ef |
require_perl_
|
|
|
dd59ef |
|
|
|
dd59ef |
-df || skip_ "df fails"
|
|
|
dd59ef |
+# Protect against inaccessible remote mounts etc.
|
|
|
dd59ef |
+timeout 10 df || skip_ "df fails"
|
|
|
dd59ef |
|
|
|
dd59ef |
cat <<\EOF > check-df || framework_failure_
|
|
|
dd59ef |
my ($total, $used, $avail) = (0, 0, 0);
|
|
|
dd59ef |
--
|
|
|
dd59ef |
2.17.2
|
|
|
dd59ef |
|
|
|
dd59ef |
|
|
|
dd59ef |
From 9a52ebdc70071076a1b7263b64b118972d203778 Mon Sep 17 00:00:00 2001
|
|
|
dd59ef |
From: Dave Chiluk <chiluk@canonical.com>
|
|
|
dd59ef |
Date: Mon, 21 Sep 2015 15:04:11 -0500
|
|
|
dd59ef |
Subject: [PATCH 9/9] df: prioritize mounts nearer the device root
|
|
|
dd59ef |
|
|
|
dd59ef |
In the presence of bind mounts of a device, the 4th "mount root" field
|
|
|
dd59ef |
from /proc/self/mountinfo is now considered, so as to prefer mount
|
|
|
dd59ef |
points closer to the root of the device. Note on older systems with
|
|
|
dd59ef |
an /etc/mtab file, the source device was listed as the originating
|
|
|
dd59ef |
directory, and so this was not an issue.
|
|
|
dd59ef |
Details at http://pad.lv/1432871
|
|
|
dd59ef |
|
|
|
dd59ef |
* src/df.c (filter_mount_list): When deduplicating mount entries,
|
|
|
dd59ef |
only prefer sources nearer or at the root of the device, when the
|
|
|
dd59ef |
target is nearer the root of the device.
|
|
|
dd59ef |
* NEWS: Mention the change in behavior.
|
|
|
dd59ef |
|
|
|
dd59ef |
Upstream-commit: 3babaf83875ceac896c8dd3a64248e955dfecef9
|
|
|
dd59ef |
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
|
|
|
dd59ef |
---
|
|
|
dd59ef |
src/df.c | 12 +++++++++---
|
|
|
dd59ef |
1 file changed, 9 insertions(+), 3 deletions(-)
|
|
|
dd59ef |
|
|
|
dd59ef |
diff --git a/src/df.c b/src/df.c
|
|
|
dd59ef |
index 5ffd0a5..c50aa80 100644
|
|
|
dd59ef |
--- a/src/df.c
|
|
|
dd59ef |
+++ b/src/df.c
|
|
|
dd59ef |
@@ -649,6 +649,13 @@ filter_mount_list (bool devices_only)
|
|
|
dd59ef |
|
|
|
dd59ef |
if (devlist)
|
|
|
dd59ef |
{
|
|
|
dd59ef |
+ bool target_nearer_root = strlen (devlist->me->me_mountdir)
|
|
|
dd59ef |
+ > strlen (me->me_mountdir);
|
|
|
dd59ef |
+ /* With bind mounts, prefer items nearer the root of the source */
|
|
|
dd59ef |
+ bool source_below_root = devlist->me->me_mntroot != NULL
|
|
|
dd59ef |
+ && me->me_mntroot != NULL
|
|
|
dd59ef |
+ && (strlen (devlist->me->me_mntroot)
|
|
|
dd59ef |
+ < strlen (me->me_mntroot));
|
|
|
dd59ef |
if (! print_grand_total && me->me_remote && devlist->me->me_remote
|
|
|
dd59ef |
&& ! STREQ (devlist->me->me_devname, me->me_devname))
|
|
|
dd59ef |
{
|
|
|
dd59ef |
@@ -660,9 +667,8 @@ filter_mount_list (bool devices_only)
|
|
|
dd59ef |
else if ((strchr (me->me_devname, '/')
|
|
|
dd59ef |
/* let "real" devices with '/' in the name win. */
|
|
|
dd59ef |
&& ! strchr (devlist->me->me_devname, '/'))
|
|
|
dd59ef |
- /* let a shorter mountdir win. */
|
|
|
dd59ef |
- || (strlen (devlist->me->me_mountdir)
|
|
|
dd59ef |
- > strlen (me->me_mountdir))
|
|
|
dd59ef |
+ /* let points towards the root of the device win. */
|
|
|
dd59ef |
+ || (target_nearer_root && ! source_below_root)
|
|
|
dd59ef |
/* let an entry overmounted on a new device win... */
|
|
|
dd59ef |
|| (! STREQ (devlist->me->me_devname, me->me_devname)
|
|
|
dd59ef |
/* ... but only when matching an existing mnt point,
|
|
|
dd59ef |
--
|
|
|
dd59ef |
2.17.2
|
|
|
dd59ef |
|