xfs
[Top] [All Lists]

[PATCH 3/3] xfsprogs: misc uClibc patches: use statfs() instead of ustat

To: xfs@xxxxxxxxxxx
Subject: [PATCH 3/3] xfsprogs: misc uClibc patches: use statfs() instead of ustat()
From: Joshua Kinard <kumba@xxxxxxxxxx>
Date: Mon, 18 Jan 2016 05:29:45 -0500
Delivered-to: xfs@xxxxxxxxxxx
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1453113011; bh=f5hL9KVe3JDMFLk/fBB8oBFR40M4691qoPMZ9qBneuw=; h=Received:Received:From:Subject:To:Message-ID:Date:MIME-Version: Content-Type; b=UxzM8oRK+6U9beoYpfy1TDmC8xw4vnxT4k3KaTbhXZbbuIBFW9AGyRnTVrIkfoScU jokUmhOc7ly6Enps6gILeB8B7coxTvih+VQttcYzhPq43t9se5eWss7MemhvZXJf+s ByF68hjAp1WdIMB8vesPov6eCSDwEX2YoODa+Z4/Kez3YfoxIEwXIdj2iUWZdxY2qs cAQ+VsFOsS0bFmXR2DAECNzPczg9FS3U3dOYDTh9jbMuDfwVv9kk7obOyrMbwNeFss Et850q60lkAj3xRy7MlQQTjYeyZYq9Tsnlp0EPklTKFx0YiKH6tqvTauygIN5ketyn /woBb58Lr4sig==
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Thunderbird/42.0
From: Joshua Kinard <kumba@xxxxxxxxxx>

uClibc doesn't provide the ustat() call and statfs() should be used instead.
Patch was previously sent upstream, but rejected because ustat() checks for the
block device being mounted anywhere.  This version of the patch takes care of
that check, as well as replacing ustat() with statfs().

Refer to Gentoo Bug #477758:
https://bugs.gentoo.org/show_bug.cgi?id=477758

Signed-off-by: Joshua Kinard <kumba@xxxxxxxxxx>
Suggested-by: Renà RhÃaume <rene.rheaume@xxxxxxxxx>
---
 libxfs/linux.c |   35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff -Naurp xfsprogs-4.3.0.orig/libxfs/linux.c xfsprogs-4.3.0/libxfs/linux.c
--- xfsprogs-4.3.0.orig/libxfs/linux.c  2015-08-03 00:39:42.000000000 +0000
+++ xfsprogs-4.3.0/libxfs/linux.c       2016-01-01 10:49:06.272229000 +0000
@@ -20,7 +20,7 @@
 #include <mntent.h>
 #include <sys/stat.h>
 #undef ustat
-#include <sys/ustat.h>
+#include <sys/statvfs.h>
 #include <sys/mount.h>
 #include <sys/ioctl.h>
 #include <sys/sysinfo.h>
@@ -51,9 +51,11 @@ static int max_block_alignment;
 int
 platform_check_ismounted(char *name, char *block, struct stat64 *s, int 
verbose)
 {
-       /* Pad ust; pre-2.6.28 linux copies out too much in 32bit compat mode */
-       struct ustat    ust[2];
+       struct statfs   ust;
        struct stat64   st;
+       char            mounts[MAXPATHLEN];
+       FILE*           mtab;
+       struct mntent*  mnt;
 
        if (!s) {
                if (stat64(block, &st) < 0)
@@ -63,7 +65,32 @@ platform_check_ismounted(char *name, cha
                s = &st;
        }
 
-       if (ustat(s->st_rdev, ust) >= 0) {
+       if (strcmp(name, block) == 0) {
+               /* Device node was passed as parameter. Find its mount point */
+               strcpy(mounts, (!access(PROC_MOUNTED, R_OK)) ? PROC_MOUNTED : 
MOUNTED);
+               mtab = setmntent(mounts, "r");
+               if (mtab == NULL) {
+                       if (verbose) {
+                               fprintf(stderr, _("%s: %s contains a possibly 
mounted filesystem\n"), progname, name);
+                       }
+                       return 1;
+               }
+               else {
+                       mnt = getmntent(mtab);
+                       while (mnt != NULL) {
+                               if (strcmp(block, mnt->mnt_fsname) == 0) {
+                                       if (verbose) {
+                                                fprintf(stderr, _("%s: %s 
contains a mounted filesystem\n"), progname, name);
+                                       }
+                                       endmntent(mtab);
+                                       return 1;
+                               }
+                               mnt = getmntent(mtab);
+                       }
+                       endmntent(mtab);
+               }
+       }
+       else if (statfs(name, &ust) >= 0) {
                if (verbose)
                        fprintf(stderr,
                                _("%s: %s contains a mounted filesystem\n"),


<Prev in Thread] Current Thread [Next in Thread>