Module Name: src
Committed By: tkusumi
Date: Fri Jan 3 08:19:14 UTC 2020
Modified Files:
src/usr.sbin/fstyp: hammer.c
Log Message:
fstyp: Cleanup hammer.c (sync with recent DragonFly commit)
taken-from DragonFlyBSD 8ca6d8ec5f97032765692d368db80159c97adea0
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/fstyp/hammer.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/fstyp/hammer.c
diff -u src/usr.sbin/fstyp/hammer.c:1.1 src/usr.sbin/fstyp/hammer.c:1.2
--- src/usr.sbin/fstyp/hammer.c:1.1 Wed Jan 1 08:56:41 2020
+++ src/usr.sbin/fstyp/hammer.c Fri Jan 3 08:19:14 2020
@@ -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 @@ fstyp_hammer(FILE *fp, char *label, size
#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 @@ fstyp_hammer(FILE *fp, char *label, size
strlcpy(label, ondisk->vol_label, size);
#endif
error = 0;
-done:
+fail:
free(ondisk);
return (error);
}
@@ -140,10 +140,10 @@ test_volume(const char *volpath)
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 @@ done:
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 @@ __fsvtyp_hammer(const char *blkdevs, cha
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);
}