summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2021-07-16 13:26:05 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2021-07-16 13:26:05 +0000
commitc6e1fb972c8191566d0ff956628f83963de6bad4 (patch)
treebe290e115d8359ebc9a22db9b554cd43c22198d6 /sbin
parent3f1a73b7fb58c183b7e57932a8e64a36119ec329 (diff)
Be consistent and always return -1 to indicate failure.
DISK_printgeometry() return value was always 0 and never checked so just make it void. No functional change.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/fdisk/disk.c6
-rw-r--r--sbin/fdisk/disk.h4
-rw-r--r--sbin/fdisk/gpt.c36
-rw-r--r--sbin/fdisk/misc.c4
-rw-r--r--sbin/fdisk/part.c8
5 files changed, 28 insertions, 30 deletions
diff --git a/sbin/fdisk/disk.c b/sbin/fdisk/disk.c
index 1f8d175b7ff..5f7a296cc19 100644
--- a/sbin/fdisk/disk.c
+++ b/sbin/fdisk/disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disk.c,v 1.65 2021/07/15 21:58:02 krw Exp $ */
+/* $OpenBSD: disk.c,v 1.66 2021/07/16 13:26:04 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -100,7 +100,7 @@ DISK_open(const char *name, const int oflags)
* Print the disk geometry information. Take an optional modifier
* to indicate the units that should be used for display.
*/
-int
+void
DISK_printgeometry(const char *units)
{
const int secsize = unit_types[SECTORS].ut_conversion;
@@ -118,8 +118,6 @@ DISK_printgeometry(const char *units)
printf("%s]\n", unit_types[i].ut_lname);
} else
printf("geometry: <none>\n");
-
- return 0;
}
/*
diff --git a/sbin/fdisk/disk.h b/sbin/fdisk/disk.h
index bc1e11b9a9f..bd2eaeca9ce 100644
--- a/sbin/fdisk/disk.h
+++ b/sbin/fdisk/disk.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: disk.h,v 1.29 2021/07/15 21:58:02 krw Exp $ */
+/* $OpenBSD: disk.h,v 1.30 2021/07/16 13:26:04 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -33,7 +33,7 @@ struct disk {
#define BLOCKALIGNMENT 64
void DISK_open(const char *, const int);
-int DISK_printgeometry(const char *);
+void DISK_printgeometry(const char *);
char *DISK_readsector(const uint64_t);
int DISK_writesector(const char *, const uint64_t);
diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c
index 97a61aec220..3ef8548d98c 100644
--- a/sbin/fdisk/gpt.c
+++ b/sbin/fdisk/gpt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gpt.c,v 1.43 2021/07/15 21:58:02 krw Exp $ */
+/* $OpenBSD: gpt.c,v 1.44 2021/07/16 13:26:04 krw Exp $ */
/*
* Copyright (c) 2015 Markus Muller <mmu@grummel.net>
* Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org>
@@ -62,7 +62,7 @@ get_header(const uint64_t sector)
secbuf = DISK_readsector(sector);
if (secbuf == 0)
- return 1;
+ return -1;
memcpy(&gh, secbuf, sizeof(struct gpt_header));
free(secbuf);
@@ -70,37 +70,37 @@ get_header(const uint64_t sector)
if (letoh64(gh.gh_sig) != GPTSIGNATURE) {
DPRINTF("gpt signature: expected 0x%llx, got 0x%llx\n",
GPTSIGNATURE, letoh64(gh.gh_sig));
- return 1;
+ return -1;
}
if (letoh32(gh.gh_rev) != GPTREVISION) {
DPRINTF("gpt revision: expected 0x%x, got 0x%x\n",
GPTREVISION, letoh32(gh.gh_rev));
- return 1;
+ return -1;
}
if (letoh64(gh.gh_lba_self) != sector) {
DPRINTF("gpt self lba: expected %llu, got %llu\n",
sector, letoh64(gh.gh_lba_self));
- return 1;
+ return -1;
}
if (letoh32(gh.gh_size) != GPTMINHDRSIZE) {
DPRINTF("gpt header size: expected %u, got %u\n",
GPTMINHDRSIZE, letoh32(gh.gh_size));
- return 1;
+ return -1;
}
if (letoh32(gh.gh_part_size) != GPTMINPARTSIZE) {
DPRINTF("gpt partition size: expected %u, got %u\n",
GPTMINPARTSIZE, letoh32(gh.gh_part_size));
- return 1;
+ return -1;
}
if (letoh32(gh.gh_part_num) > NGPTPARTITIONS) {
DPRINTF("gpt partition count: expected <= %u, got %u\n",
NGPTPARTITIONS, letoh32(gh.gh_part_num));
- return 1;
+ return -1;
}
orig_gh_csum = gh.gh_csum;
@@ -110,7 +110,7 @@ get_header(const uint64_t sector)
if (letoh32(orig_gh_csum) != new_gh_csum) {
DPRINTF("gpt header checksum: expected 0x%x, got 0x%x\n",
orig_gh_csum, new_gh_csum);
- return 1;
+ return -1;
}
/* XXX Assume part_num * part_size is multiple of secsize. */
@@ -126,7 +126,7 @@ get_header(const uint64_t sector)
if (letoh64(gh.gh_lba_start) >= letoh64(gh.gh_lba_end)) {
DPRINTF("gpt first usable LBA: expected < %llu, got %llu\n",
letoh64(gh.gh_lba_end), letoh64(gh.gh_lba_start));
- return 1;
+ return -1;
}
if (letoh64(gh.gh_part_lba) <= letoh64(gh.gh_lba_end) &&
@@ -134,7 +134,7 @@ get_header(const uint64_t sector)
DPRINTF("gpt partition table start lba: expected < %llu or "
"> %llu, got %llu\n", letoh64(gh.gh_lba_start),
letoh64(gh.gh_lba_end), letoh64(gh.gh_part_lba));
- return 1;
+ return -1;
}
partspersec = dl.d_secsize / letoh32(gh.gh_part_size);
@@ -145,7 +145,7 @@ get_header(const uint64_t sector)
DPRINTF("gpt partition table last LBA: expected < %llu or "
"> %llu, got %llu\n", letoh64(gh.gh_lba_start),
letoh64(gh.gh_lba_end), partlastlba);
- return 1;
+ return -1;
}
/*
@@ -172,7 +172,7 @@ get_partition_table(void)
if (partspersec * letoh32(gh.gh_part_size) != dl.d_secsize) {
DPRINTF("gpt partition table entry invalid size. %u\n",
letoh32(gh.gh_part_size));
- return 1;
+ return -1;
}
secs = (letoh32(gh.gh_part_num) + partspersec - 1) / partspersec;
@@ -183,12 +183,12 @@ get_partition_table(void)
if (off == -1) {
DPRINTF("seek to gpt partition table @ sector %llu failed\n",
(unsigned long long)where / dl.d_secsize);
- return 1;
+ return -1;
}
len = read(disk.dk_fd, &gp, secs * dl.d_secsize);
if (len == -1 || len != secs * dl.d_secsize) {
DPRINTF("gpt partition table read failed.\n");
- return 1;
+ return -1;
}
checksum = crc32((unsigned char *)&gp, letoh32(gh.gh_part_num) *
@@ -196,7 +196,7 @@ get_partition_table(void)
if (checksum != letoh32(gh.gh_part_csum)) {
DPRINTF("gpt partition table checksum: expected %x, got %x\n",
checksum, letoh32(gh.gh_part_csum));
- return 1;
+ return -1;
}
return 0;
@@ -370,7 +370,7 @@ add_partition(const uint8_t *beuuid, const char *name, uint64_t sectors)
if (pn != pncnt)
memset(&gp[pn], 0, sizeof(gp[pn]));
printf("unable to add %s\n", name);
- return 1;
+ return -1;
}
int
@@ -406,7 +406,7 @@ init_gh(void)
uuid_create(&guid, &status);
if (status != uuid_s_ok) {
memcpy(&gh, &oldgh, sizeof(gh));
- return 1;
+ return -1;
}
uuid_enc_le(&gh.gh_guid, &guid);
diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c
index 9558142ff1a..997ce44f683 100644
--- a/sbin/fdisk/misc.c
+++ b/sbin/fdisk/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.76 2021/07/15 21:58:02 krw Exp $ */
+/* $OpenBSD: misc.c,v 1.77 2021/07/16 13:26:04 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -71,7 +71,7 @@ string_from_line(char *buf, const size_t buflen)
len = getline(&line, &sz, stdin);
if (len == -1)
- return 1;
+ return -1;
if (line[len - 1] == '\n')
line[len - 1] = '\0';
diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c
index 4323cce9444..eb4434dd98e 100644
--- a/sbin/fdisk/part.c
+++ b/sbin/fdisk/part.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: part.c,v 1.97 2021/07/15 21:58:02 krw Exp $ */
+/* $OpenBSD: part.c,v 1.98 2021/07/16 13:26:04 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -271,9 +271,9 @@ check_chs(const struct prt *prt)
(prt->prt_esect >63) ||
(prt->prt_ecyl > 1023) )
{
- return 0;
+ return -1;
}
- return 1;
+ return 0;
}
void
@@ -296,7 +296,7 @@ PRT_make(struct prt *prt, const uint64_t lba_self, const uint64_t lba_firstembr,
else
off = lba_self;
- if (check_chs(prt)) {
+ if (check_chs(prt) == 0) {
dp->dp_shd = prt->prt_shead & 0xFF;
dp->dp_ssect = (prt->prt_ssect & 0x3F) |
((prt->prt_scyl & 0x300) >> 2);