]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: move iswritable "fatal" decision to caller
authorEric Sandeen <sandeen@sandeen.net>
Mon, 19 Sep 2016 05:53:52 +0000 (15:53 +1000)
committerDave Chinner <david@fromorbit.com>
Mon, 19 Sep 2016 05:53:52 +0000 (15:53 +1000)
Simplify platform_check_iswritable by moving the
"fatal" decision up to the (one) caller.  In other words,
simply return whether mounted+writable is true, and
return 1 if so.  Caller decides what to do with that info
based on /its/ "fatal" argument.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
libxfs/darwin.c
libxfs/freebsd.c
libxfs/init.c
libxfs/init.h
libxfs/irix.c
libxfs/linux.c

index 017e190f159ca1e922dd6baeb9ee229769fbc1a5..19d2ab6e86baf85e531d216a217867742909730f 100644 (file)
@@ -33,7 +33,7 @@ platform_check_ismounted(char *name, char *block, struct stat64 *s, int verbose)
 }
 
 int
-platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal)
+platform_check_iswritable(char *name, char *block, struct stat64 *s)
 {
        int     fd, writable;
 
index 6c9f089d7408d35241c0acdfafa9715b57db28cc..9e221831c5827fbfa44bc999917765391fbe61a6 100644 (file)
@@ -66,7 +66,7 @@ platform_check_ismounted(char *name, char *block, struct stat64 *s, int verbose)
 }
 
 int
-platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal)
+platform_check_iswritable(char *name, char *block, struct stat64 *s)
 {
         int cnt, i;
         struct statfs *fsinfo;
@@ -74,7 +74,7 @@ platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal)
         if ((cnt = getmntinfo(&fsinfo, MNT_NOWAIT)) == 0) {
                fprintf(stderr, _("%s: %s contains a possibly writable, "
                                "mounted filesystem\n"), progname, name);
-                       return fatal;
+                       return 1;
        }
 
         for (i = 0; i < cnt; i++) {
@@ -88,7 +88,7 @@ platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal)
         if (i == cnt) {
                fprintf(stderr, _("%s: %s contains a mounted and writable "
                                "filesystem\n"), progname, name);
-               return fatal;
+               return 1;
        }
        return 0;
 }
index c13b12396ea484bae320e77566e8d4bcc207e0b9..828ae3ec742b13a75d87f7b556b7eb5e508871f7 100644 (file)
@@ -75,7 +75,9 @@ check_isactive(char *name, char *block, int fatal)
                return 0;
        if (platform_check_ismounted(name, block, &st, 0) == 0)
                return 0;
-       return platform_check_iswritable(name, block, &st, fatal);
+       if (platform_check_iswritable(name, block, &st))
+               return fatal ? 1 : 0;
+       return 0;
 }
 
 /* libxfs_device_to_fd:
index 112febbe1838048bc074ec4960030c386367dbdb..4dda3ee37cd7c3758c0c0b02656daa4b00fb54a0 100644 (file)
@@ -22,8 +22,7 @@ struct stat64;
 
 extern int platform_check_ismounted (char *path, char *block,
                                        struct stat64 *sptr, int verbose);
-extern int platform_check_iswritable (char *path, char *block,
-                                       struct stat64 *sptr, int fatal);
+extern int platform_check_iswritable (char *path, char *block, struct stat64 *sptr);
 extern int platform_set_blocksize (int fd, char *path, dev_t device, int bsz, int fatal);
 extern void platform_flush_device (int fd, dev_t device);
 extern char *platform_findrawpath(char *path);
index 65aaa7ef066a376e8eddc256b0b9770a874c2d4c..c23ebe08d6c0d0ee8122e74f1b6225e90b98f7dc 100644 (file)
@@ -31,7 +31,7 @@ platform_check_ismounted(char *name, char *block, struct stat64 *s, int verbose)
 }
 
 int
-platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal)
+platform_check_iswritable(char *name, char *block, struct stat64 *s)
 {
        return 1;
 }
index 44bc1f9015e19bc334f91efa5fea02b7560c45e2..2b67d1a8e25fefe8ad0092c0939af3de8848c631 100644 (file)
@@ -85,9 +85,8 @@ platform_check_ismounted(char *name, char *block, struct stat64 *s, int verbose)
 }
 
 int
-platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal)
+platform_check_iswritable(char *name, char *block, struct stat64 *s)
 {
-       int             sts = 0;
        FILE            *f;
        struct stat64   mst;
        struct mntent   *mnt;
@@ -97,7 +96,7 @@ platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal)
        if ((f = setmntent(mounts, "r")) == NULL) {
                fprintf(stderr, _("%s: %s contains a possibly writable, "
                                "mounted filesystem\n"), progname, name);
-                       return fatal;
+                       return 1;
        }
        while ((mnt = getmntent(f)) != NULL) {
                if (stat64(mnt->mnt_fsname, &mst) < 0)
@@ -108,13 +107,14 @@ platform_check_iswritable(char *name, char *block, struct stat64 *s, int fatal)
                    && hasmntopt(mnt, MNTOPT_RO) != NULL)
                        break;
        }
+       endmntent(f);
+
        if (mnt == NULL) {
                fprintf(stderr, _("%s: %s contains a mounted and writable "
                                "filesystem\n"), progname, name);
-               sts = fatal;
+               return 1;
        }
-       endmntent(f);
-       return sts;
+       return 0;
 }
 
 int