Blame SOURCES/xfsprogs-4.8.0-replace-ustat.patch

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