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

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