e59f31
commit 4e7a824f6b34dbe0dd2e2a3870891130b937f327
e59f31
Author: Felix Janda <felix.janda@posteo.de>
e59f31
Date:   Thu Sep 8 10:22:28 2016 +1000
e59f31
e59f31
    libxfs/linux.c: Replace use of ustat by stat
e59f31
    
e59f31
    ustat has been used to check whether a device file is mounted.
e59f31
    The function is deprecated and not supported by uclibc and musl.
e59f31
    Now do the check using the *mntent functions.
e59f31
    
e59f31
    Based on patch by Natanael Copa <ncopa@alpinelinux.org>.
e59f31
    
e59f31
    Signed-off-by: Felix Janda <felix.janda@posteo.de>
e59f31
    Reviewed-by: Eric Sandeen <sandeen@redhat.com>
e59f31
    Signed-off-by: Dave Chinner <david@fromorbit.com>
e59f31
e59f31
diff --git a/libxfs/linux.c b/libxfs/linux.c
e59f31
index c9f2baf..44bc1f9 100644
e59f31
--- a/libxfs/linux.c
e59f31
+++ b/libxfs/linux.c
e59f31
@@ -16,11 +16,8 @@
e59f31
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
e59f31
  */
e59f31
 
e59f31
-#define ustat __kernel_ustat
e59f31
 #include <mntent.h>
e59f31
 #include <sys/stat.h>
e59f31
-#undef ustat
e59f31
-#include <sys/ustat.h>
e59f31
 #include <sys/mount.h>
e59f31
 #include <sys/ioctl.h>
e59f31
 #include <sys/sysinfo.h>
e59f31
@@ -51,9 +48,10 @@ static int max_block_alignment;
e59f31
 int
e59f31
 platform_check_ismounted(char *name, char *block, struct stat64 *s, int verbose)
e59f31
 {
e59f31
-	/* Pad ust; pre-2.6.28 linux copies out too much in 32bit compat mode */
e59f31
-	struct ustat	ust[2];
e59f31
-	struct stat64	st;
e59f31
+	FILE		*f;
e59f31
+	struct stat64	st, mst;
e59f31
+	struct mntent	*mnt;
e59f31
+	char		mounts[MAXPATHLEN];
e59f31
 
e59f31
 	if (!s) {
e59f31
 		if (stat64(block, &st) < 0)
e59f31
@@ -63,14 +61,27 @@ platform_check_ismounted(char *name, char *block, struct stat64 *s, int verbose)
e59f31
 		s = &st;
e59f31
 	}
e59f31
 
e59f31
-	if (ustat(s->st_rdev, ust) >= 0) {
e59f31
+	strcpy(mounts, (!access(PROC_MOUNTED, R_OK)) ? PROC_MOUNTED : MOUNTED);
e59f31
+	if ((f = setmntent(mounts, "r")) == NULL) {
e59f31
+		fprintf(stderr,
e59f31
+		    _("%s: %s possibly contains a mounted filesystem\n"),
e59f31
+		    progname, name);
e59f31
+		return 1;
e59f31
+	}
e59f31
+	while ((mnt = getmntent(f)) != NULL) {
e59f31
+		if (stat64(mnt->mnt_dir, &mst) < 0)
e59f31
+			continue;
e59f31
+		if (mst.st_dev != s->st_rdev)
e59f31
+			continue;
e59f31
+
e59f31
 		if (verbose)
e59f31
 			fprintf(stderr,
e59f31
 				_("%s: %s contains a mounted filesystem\n"),
e59f31
 				progname, name);
e59f31
-		return 1;
e59f31
+		break;
e59f31
 	}
e59f31
-	return 0;
e59f31
+	endmntent(f);
e59f31
+	return mnt != NULL;
e59f31
 }
e59f31
 
e59f31
 int