Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/fstyp fstyp: Cleanup hammer.c (sync with recent Dra...



details:   https://anonhg.NetBSD.org/src/rev/81bd74b01435
branches:  trunk
changeset: 466838:81bd74b01435
user:      tkusumi <tkusumi%NetBSD.org@localhost>
date:      Fri Jan 03 08:19:14 2020 +0000

description:
fstyp: Cleanup hammer.c (sync with recent DragonFly commit)

taken-from DragonFlyBSD 8ca6d8ec5f97032765692d368db80159c97adea0

diffstat:

 usr.sbin/fstyp/hammer.c |  34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)

diffs (117 lines):

diff -r 5959de532fe7 -r 81bd74b01435 usr.sbin/fstyp/hammer.c
--- a/usr.sbin/fstyp/hammer.c   Fri Jan 03 07:50:58 2020 +0000
+++ b/usr.sbin/fstyp/hammer.c   Fri Jan 03 08:19:14 2020 +0000
@@ -1,4 +1,4 @@
-/*        $NetBSD: hammer.c,v 1.1 2020/01/01 08:56:41 tkusumi Exp $      */
+/*        $NetBSD: hammer.c,v 1.2 2020/01/03 08:19:14 tkusumi Exp $      */
 
 /*-
  * Copyright (c) 2016-2019 The DragonFly Project
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hammer.c,v 1.1 2020/01/01 08:56:41 tkusumi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hammer.c,v 1.2 2020/01/03 08:19:14 tkusumi Exp $");
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -97,11 +97,11 @@
 #endif
        ondisk = read_ondisk(fp);
        if (ondisk->vol_no != HAMMER_ROOT_VOLNO)
-               goto done;
+               goto fail;
        if (ondisk->vol_count != 1)
-               goto done;
+               goto fail;
        if (test_ondisk(ondisk))
-               goto done;
+               goto fail;
 
        /*
         * fstyp_function in DragonFly takes an additional devpath argument
@@ -122,7 +122,7 @@
        strlcpy(label, ondisk->vol_label, size);
 #endif
        error = 0;
-done:
+fail:
        free(ondisk);
        return (error);
 }
@@ -140,10 +140,10 @@
        ondisk = read_ondisk(fp);
        fclose(fp);
        if (test_ondisk(ondisk))
-               goto done;
+               goto fail;
 
        volno = ondisk->vol_no;
-done:
+fail:
        free(ondisk);
        return (volno);
 }
@@ -151,22 +151,28 @@
 static int
 __fsvtyp_hammer(const char *blkdevs, char *label, size_t size, int partial)
 {
-       hammer_volume_ondisk_t ondisk;
+       hammer_volume_ondisk_t ondisk = NULL;
        FILE *fp;
        char *dup, *p, *volpath, x[HAMMER_MAX_VOLUMES];
        int i, volno, error = 1;
 
+       if (!blkdevs)
+               goto fail;
+
        memset(x, 0, sizeof(x));
        dup = strdup(blkdevs);
        p = dup;
 
        volpath = NULL;
+       volno = -1;
        while (p) {
                volpath = p;
                if ((p = strchr(p, ':')) != NULL)
                        *p++ = '\0';
                if ((volno = test_volume(volpath)) == -1)
                        break;
+               assert(volno >= 0);
+               assert(volno < HAMMER_MAX_VOLUMES);
                x[volno]++;
        }
 
@@ -180,26 +186,26 @@
        free(dup);
 
        if (volno == -1)
-               goto done;
+               goto fail;
        if (partial)
                goto success;
 
        for (i = 0; i < HAMMER_MAX_VOLUMES; i++)
                if (x[i] > 1)
-                       goto done;
+                       goto fail;
        for (i = 0; i < HAMMER_MAX_VOLUMES; i++)
                if (x[i] == 0)
                        break;
        if (ondisk->vol_count != i)
-               goto done;
+               goto fail;
        for (; i < HAMMER_MAX_VOLUMES; i++)
                if (x[i] != 0)
-                       goto done;
+                       goto fail;
 success:
        /* XXX autofs -media mount can't handle multiple mounts */
        strlcpy(label, ondisk->vol_label, size);
        error = 0;
-done:
+fail:
        free(ondisk);
        return (error);
 }



Home | Main Index | Thread Index | Old Index