summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2016-01-26 16:39:00 +0000
committerkrw <krw@openbsd.org>2016-01-26 16:39:00 +0000
commita8b53b4c8489e07bc55a8bdfcbfda88b7ca8d1a3 (patch)
treeaea003ac2be4cbc88a12fb45ffb59e8a3a694fc6
parentRewrite tx path to use flat transmit ring without fragment chains (diff)
downloadwireguard-openbsd-a8b53b4c8489e07bc55a8bdfcbfda88b7ca8d1a3.tar.xz
wireguard-openbsd-a8b53b4c8489e07bc55a8bdfcbfda88b7ca8d1a3.zip
Whitespace, line wrapping fixes. Nuke many superfluous '{}' around single
statements. 0 -> NULL for pointer checks.
-rw-r--r--sbin/pdisk/dump.c32
-rw-r--r--sbin/pdisk/io.c29
-rw-r--r--sbin/pdisk/partition_map.c115
-rw-r--r--sbin/pdisk/pdisk.c14
-rw-r--r--sbin/pdisk/validate.c42
5 files changed, 94 insertions, 138 deletions
diff --git a/sbin/pdisk/dump.c b/sbin/pdisk/dump.c
index d31ae34c6ab..0212f6751de 100644
--- a/sbin/pdisk/dump.c
+++ b/sbin/pdisk/dump.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dump.c,v 1.54 2016/01/26 16:13:09 krw Exp $ */
+/* $OpenBSD: dump.c,v 1.55 2016/01/26 16:39:00 krw Exp $ */
/*
* dump.c - dumping partition maps
@@ -53,9 +53,9 @@ dump_block_zero(struct partition_map_header *map)
int i, prefix;
p = map->block0;
- if (p->sbSig != BLOCK0_SIGNATURE) {
+ if (p->sbSig != BLOCK0_SIGNATURE)
return;
- }
+
value = ((double) p->sbBlkCount) * p->sbBlkSize;
adjust_value_and_compute_prefix(&value, &prefix);
printf("\nDevice block size=%u, Number of Blocks=%u (%1.1f%c)\n",
@@ -93,17 +93,14 @@ dump_partition_map(struct partition_map_header *map)
map->logical_block, map->name);
digits = number_of_digits(get_max_base_or_length(map));
- if (digits < 6) {
+ if (digits < 6)
digits = 6;
- }
max_type_length = get_max_type_string_length(map);
- if (max_type_length < 4) {
+ if (max_type_length < 4)
max_type_length = 4;
- }
max_name_length = get_max_name_string_length(map);
- if (max_name_length < 6) {
+ if (max_name_length < 6)
max_name_length = 6;
- }
printf(" #: %*s %-*s %*s %-*s ( size )\n", max_type_length, "type",
max_name_length, "name", digits, "length", digits, "base");
@@ -185,11 +182,10 @@ show_data_structures(struct partition_map_header *map)
printf("Block0:\n");
printf("signature 0x%x", zp->sbSig);
- if (zp->sbSig == BLOCK0_SIGNATURE) {
+ if (zp->sbSig == BLOCK0_SIGNATURE)
printf("\n");
- } else {
+ else
printf(" should be 0x%x\n", BLOCK0_SIGNATURE);
- }
printf("Block size=%u, Number of Blocks=%u\n", zp->sbBlkSize,
zp->sbBlkCount);
printf("DeviceType=0x%x, DeviceId=0x%x, sbData=0x%x\n", zp->sbDevType,
@@ -436,18 +432,14 @@ get_max_base_or_length(struct partition_map_header *map)
for (entry = map->disk_order; entry != NULL;
entry = entry->next_on_disk) {
- if (entry->dpme->dpme_pblock_start > max) {
+ if (entry->dpme->dpme_pblock_start > max)
max = entry->dpme->dpme_pblock_start;
- }
- if (entry->dpme->dpme_pblocks > max) {
+ if (entry->dpme->dpme_pblocks > max)
max = entry->dpme->dpme_pblocks;
- }
- if (entry->dpme->dpme_lblock_start > max) {
+ if (entry->dpme->dpme_lblock_start > max)
max = entry->dpme->dpme_lblock_start;
- }
- if (entry->dpme->dpme_lblocks > max) {
+ if (entry->dpme->dpme_lblocks > max)
max = entry->dpme->dpme_lblocks;
- }
}
return max;
diff --git a/sbin/pdisk/io.c b/sbin/pdisk/io.c
index c12a7707165..63571ce203c 100644
--- a/sbin/pdisk/io.c
+++ b/sbin/pdisk/io.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: io.c,v 1.22 2016/01/24 01:38:32 krw Exp $ */
+/* $OpenBSD: io.c,v 1.23 2016/01/26 16:39:00 krw Exp $ */
/*
* io.c - simple io and input parsing routines
@@ -49,11 +49,10 @@ int my_getch (void);
int
my_getch()
{
- if (unget_count > 0) {
+ if (unget_count > 0)
return (unget_buf[--unget_count]);
- } else {
+ else
return (getc(stdin));
- }
}
@@ -64,12 +63,10 @@ my_ungetch(int c)
* In practice there is never more than one character in
* the unget_buf, but what's a little overkill among friends?
*/
-
- if (unget_count < UNGET_MAX_COUNT) {
+ if (unget_count < UNGET_MAX_COUNT)
unget_buf[unget_count++] = c;
- } else {
+ else
errx(1, "Programmer error in my_ungetch().");
- }
}
void
@@ -130,9 +127,9 @@ get_command(const char *prompt, int promptBeforeGet, int *command)
{
int c;
- if (promptBeforeGet) {
+ if (promptBeforeGet)
printf(prompt);
- }
+
for (;;) {
c = my_getch();
@@ -237,8 +234,8 @@ get_string_argument(const char *prompt, char **string)
*string = get_string(c);
result = 1;
break;
- } else if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')
- || (c == '-' || c == '/' || c == '.' || c == ':')) {
+ } else if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') ||
+ (c == '-' || c == '/' || c == '.' || c == ':')) {
my_ungetch(c);
*string = get_string(' ');
result = 1;
@@ -253,7 +250,7 @@ get_string_argument(const char *prompt, char **string)
}
-char *
+char *
get_string(int eos)
{
char *s, *ret_value, *limit;
@@ -351,11 +348,11 @@ get_partition_modifier(void)
c = my_getch();
- if (c == 'p' || c == 'P') {
+ if (c == 'p' || c == 'P')
result = 1;
- } else if (c > 0) {
+ else if (c > 0)
my_ungetch(c);
- }
+
return result;
}
diff --git a/sbin/pdisk/partition_map.c b/sbin/pdisk/partition_map.c
index d0384b1caea..4493efcc4b3 100644
--- a/sbin/pdisk/partition_map.c
+++ b/sbin/pdisk/partition_map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: partition_map.c,v 1.66 2016/01/26 16:13:09 krw Exp $ */
+/* $OpenBSD: partition_map.c,v 1.67 2016/01/26 16:39:00 krw Exp $ */
/*
* partition_map.c - partition map routines
@@ -420,19 +420,18 @@ add_partition_to_map(const char *name, const char *dptype, uint32_t base,
}
}
/* if the map will overflow then punt */
- if (map->maximum_in_map < 0) {
+ if (map->maximum_in_map < 0)
limit = map->media_size;
- } else {
+ else
limit = map->maximum_in_map;
- }
if (map->blocks_in_map + act > limit) {
printf("the map is not big enough\n");
return 0;
}
dpme = create_dpme(name, dptype, base, length);
- if (dpme == NULL) {
+ if (dpme == NULL)
return 0;
- }
+
if (act == kReplace) {
free(cur->dpme);
cur->dpme = dpme;
@@ -453,9 +452,8 @@ add_partition_to_map(const char *name, const char *dptype, uint32_t base,
* this one
*/
if (add_data_to_map(dpme, cur->disk_address,
- map) == 0) {
+ map) == 0)
free(dpme);
- }
}
}
}
@@ -491,13 +489,12 @@ create_dpme(const char *name, const char *dptype, uint32_t base,
void
dpme_init_flags(struct dpme *dpme)
{
- if (strncasecmp(dpme->dpme_type, kHFSType, DPISTRLEN) == 0) {
- /* XXX this is gross, fix it! */
+ /* XXX this is gross, fix it! */
+ if (strncasecmp(dpme->dpme_type, kHFSType, DPISTRLEN) == 0)
dpme->dpme_flags = APPLE_HFS_FLAGS_VALUE;
- } else {
+ else
dpme->dpme_flags = DPME_WRITABLE | DPME_READABLE |
DPME_ALLOCATED | DPME_VALID;
- }
}
void
@@ -549,12 +546,10 @@ delete_partition_from_map(struct partition_map *entry)
}
dpme = create_dpme(kFreeName, kFreeType,
entry->dpme->dpme_pblock_start, entry->dpme->dpme_pblocks);
- if (dpme == NULL) {
+ if (dpme == NULL)
return;
- }
- if (entry->contains_driver) {
+ if (entry->contains_driver)
remove_driver(entry); /* update block0 if necessary */
- }
free(entry->dpme);
entry->dpme = dpme;
combine_entry(entry);
@@ -575,14 +570,12 @@ contains_driver(struct partition_map *entry)
map = entry->the_map;
p = map->block0;
- if (p->sbSig != BLOCK0_SIGNATURE) {
+ if (p->sbSig != BLOCK0_SIGNATURE)
return 0;
- }
- if (map->logical_block > p->sbBlkSize) {
+ if (map->logical_block > p->sbBlkSize)
return 0;
- } else {
- f = p->sbBlkSize / map->logical_block;
- }
+
+ f = p->sbBlkSize / map->logical_block;
if (p->sbDrvrCount > 0) {
m = p->sbDDMap;
for (i = 0; i < p->sbDrvrCount; i++) {
@@ -590,9 +583,8 @@ contains_driver(struct partition_map *entry)
if (entry->dpme->dpme_pblock_start <= f * start &&
f * (start + m[i].ddSize) <=
(entry->dpme->dpme_pblock_start +
- entry->dpme->dpme_pblocks)) {
+ entry->dpme->dpme_pblocks))
return 1;
- }
}
}
return 0;
@@ -605,10 +597,10 @@ combine_entry(struct partition_map *entry)
struct partition_map *p;
uint32_t end;
- if (entry == NULL
- || strncasecmp(entry->dpme->dpme_type, kFreeType, DPISTRLEN) != 0) {
+ if (entry == NULL ||
+ strncasecmp(entry->dpme->dpme_type, kFreeType, DPISTRLEN) != 0)
return;
- }
+
if (entry->next_by_base != NULL) {
p = entry->next_by_base;
if (strncasecmp(p->dpme->dpme_type, kFreeType, DPISTRLEN) !=
@@ -683,15 +675,13 @@ delete_entry(struct partition_map *entry)
remove_from_disk_order(entry);
p = entry->next_by_base;
- if (map->base_order == entry) {
+ if (map->base_order == entry)
map->base_order = p;
- }
- if (p != NULL) {
+ if (p != NULL)
p->prev_by_base = entry->prev_by_base;
- }
- if (entry->prev_by_base != NULL) {
+ if (entry->prev_by_base != NULL)
entry->prev_by_base->next_by_base = p;
- }
+
free(entry->dpme);
free(entry);
}
@@ -704,9 +694,8 @@ find_entry_by_disk_address(long ix, struct partition_map_header *map)
cur = map->disk_order;
while (cur != NULL) {
- if (cur->disk_address == ix) {
+ if (cur->disk_address == ix)
break;
- }
cur = cur->next_on_disk;
}
return cur;
@@ -721,9 +710,8 @@ find_entry_by_type(const char *type_name, struct partition_map_header *map)
cur = map->base_order;
while (cur != NULL) {
if (strncasecmp(cur->dpme->dpme_type, type_name, DPISTRLEN) ==
- 0) {
+ 0)
break;
- }
cur = cur->next_by_base;
}
return cur;
@@ -736,9 +724,8 @@ find_entry_by_base(uint32_t base, struct partition_map_header *map)
cur = map->base_order;
while (cur != NULL) {
- if (cur->dpme->dpme_pblock_start == base) {
+ if (cur->dpme->dpme_pblock_start == base)
break;
- }
cur = cur->next_by_base;
}
return cur;
@@ -771,15 +758,13 @@ remove_from_disk_order(struct partition_map *entry)
map = entry->the_map;
p = entry->next_on_disk;
- if (map->disk_order == entry) {
+ if (map->disk_order == entry)
map->disk_order = p;
- }
- if (p != NULL) {
+ if (p != NULL)
p->prev_on_disk = entry->prev_on_disk;
- }
- if (entry->prev_on_disk != NULL) {
+ if (entry->prev_on_disk != NULL)
entry->prev_on_disk->next_on_disk = p;
- }
+
entry->next_on_disk = NULL;
entry->prev_on_disk = NULL;
}
@@ -797,9 +782,8 @@ insert_in_disk_order(struct partition_map *entry)
if (cur == NULL || entry->disk_address <= cur->disk_address) {
map->disk_order = entry;
entry->next_on_disk = cur;
- if (cur != NULL) {
+ if (cur != NULL)
cur->prev_on_disk = entry;
- }
entry->prev_on_disk = NULL;
} else {
for (cur = map->disk_order; cur != NULL;
@@ -811,10 +795,9 @@ insert_in_disk_order(struct partition_map *entry)
entry->next_on_disk = cur->next_on_disk;
cur->next_on_disk = entry;
entry->prev_on_disk = cur;
- if (entry->next_on_disk != NULL) {
+ if (entry->next_on_disk != NULL)
entry->next_on_disk->prev_on_disk =
entry;
- }
break;
}
}
@@ -835,9 +818,8 @@ insert_in_base_order(struct partition_map *entry)
|| entry->dpme->dpme_pblock_start <= cur->dpme->dpme_pblock_start) {
map->base_order = entry;
entry->next_by_base = cur;
- if (cur != NULL) {
+ if (cur != NULL)
cur->prev_by_base = entry;
- }
entry->prev_by_base = NULL;
} else {
for (cur = map->base_order; cur != NULL;
@@ -850,10 +832,9 @@ insert_in_base_order(struct partition_map *entry)
entry->next_by_base = cur->next_by_base;
cur->next_by_base = entry;
entry->prev_by_base = cur;
- if (entry->next_by_base != NULL) {
+ if (entry->next_by_base != NULL)
entry->next_by_base->prev_by_base =
entry;
- }
break;
}
}
@@ -876,18 +857,17 @@ resize_map(long new_size, struct partition_map_header *map)
}
next = entry->next_by_base;
- if (new_size == entry->dpme->dpme_pblocks) {
+ if (new_size == entry->dpme->dpme_pblocks)
return;
- }
+
/* make it smaller */
if (new_size < entry->dpme->dpme_pblocks) {
if (next == NULL ||
strncasecmp(next->dpme->dpme_type, kFreeType, DPISTRLEN) !=
- 0) {
+ 0)
incr = 1;
- } else {
+ else
incr = 0;
- }
if (new_size < map->blocks_in_map + incr) {
printf("New size would be too small\n");
return;
@@ -928,19 +908,16 @@ remove_driver(struct partition_map *entry)
map = entry->the_map;
p = map->block0;
- if (p->sbSig != BLOCK0_SIGNATURE) {
+ if (p->sbSig != BLOCK0_SIGNATURE)
return;
- }
- if (map->logical_block > p->sbBlkSize) {
- /* this is not supposed to happen, but let's just ignore it. */
+ if (map->logical_block > p->sbBlkSize)
return;
- } else {
- /*
- * compute the factor to convert the block numbers in block0
- * into partition map block numbers.
- */
- f = p->sbBlkSize / map->logical_block;
- }
+
+ /*
+ * compute the factor to convert the block numbers in block0
+ * into partition map block numbers.
+ */
+ f = p->sbBlkSize / map->logical_block;
if (p->sbDrvrCount > 0) {
m = p->sbDDMap;
for (i = 0; i < p->sbDrvrCount; i++) {
diff --git a/sbin/pdisk/pdisk.c b/sbin/pdisk/pdisk.c
index c3b68293c34..a82f1f96d5b 100644
--- a/sbin/pdisk/pdisk.c
+++ b/sbin/pdisk/pdisk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pdisk.c,v 1.69 2016/01/25 23:43:20 krw Exp $ */
+/* $OpenBSD: pdisk.c,v 1.70 2016/01/26 16:39:00 krw Exp $ */
/*
* pdisk - an editor for Apple format partition tables
@@ -405,13 +405,12 @@ do_delete_partition(struct partition_map_header *map)
bad_input("Bad partition number");
return;
}
- /* find partition and delete it */
+
cur = find_entry_by_disk_address(ix, map);
- if (cur == NULL) {
+ if (cur == NULL)
printf("No such partition\n");
- } else {
+ else
delete_partition_from_map(cur);
- }
}
@@ -475,11 +474,10 @@ do_display_entry(struct partition_map_header *map)
bad_input("Bad partition number");
return;
}
- if (number == 0) {
+ if (number == 0)
full_dump_block_zero(map);
- } else {
+ else
full_dump_partition_entry(map, number);
- }
}
diff --git a/sbin/pdisk/validate.c b/sbin/pdisk/validate.c
index d3349b36756..430d16a8a9f 100644
--- a/sbin/pdisk/validate.c
+++ b/sbin/pdisk/validate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: validate.c,v 1.40 2016/01/26 16:13:09 krw Exp $ */
+/* $OpenBSD: validate.c,v 1.41 2016/01/26 16:39:00 krw Exp $ */
/*
* validate.c -
@@ -91,29 +91,25 @@ add_range(struct range_list **list, uint32_t base, uint32_t len, int allocate)
struct range_list *item, *cur;
uint32_t low, high;
- if (list == 0 || *list == 0) {
- /* XXX initialized list will always have one element */
+ /* XXX initialized list will always have one element */
+ if (list == NULL || *list == NULL)
return;
- }
low = base;
high = base + len - 1;
- if (len == 0 || high < len - 1) {
- /* XXX wrapped around */
+ /* XXX wrapped around */
+ if (len == 0 || high < len - 1)
return;
- }
cur = *list;
while (low <= high) {
- if (cur == 0) {
- /* XXX should never occur */
+ if (cur == NULL)
break;
- }
if (low <= cur->end) {
if (cur->start < low) {
item = new_range_list_item(cur->state,
cur->valid, cur->start, low - 1);
/* insert before here */
- if (cur->prev == 0) {
- item->prev = 0;
+ if (cur->prev == NULL) {
+ item->prev = NULL;
*list = item;
} else {
item->prev = cur->prev;
@@ -127,8 +123,8 @@ add_range(struct range_list **list, uint32_t base, uint32_t len, int allocate)
item = new_range_list_item(cur->state,
cur->valid, high + 1, cur->end);
/* insert after here */
- if (cur->next == 0) {
- item->next = 0;
+ if (cur->next == NULL) {
+ item->next = NULL;
} else {
item->next = cur->next;
item->next->prev = item;
@@ -163,18 +159,16 @@ coalesce_list(struct range_list *list)
{
struct range_list *cur, *item;
- for (cur = list; cur != 0;) {
+ for (cur = list; cur != NULL;) {
item = cur->next;
- if (item == 0) {
+ if (item == NULL)
break;
- }
if (cur->valid == item->valid &&
cur->state == item->state) {
cur->end = item->end;
cur->next = item->next;
- if (item->next != 0) {
+ if (item->next != NULL)
item->next->prev = cur;
- }
free(item);
} else {
cur = cur->next;
@@ -196,7 +190,7 @@ print_range_list(struct range_list *list)
}
printf("Range list:\n");
printed = 0;
- for (cur = list; cur != 0; cur = cur->next) {
+ for (cur = list; cur != NULL; cur = cur->next) {
if (cur->valid) {
switch (cur->state) {
case kUnallocated:
@@ -226,9 +220,8 @@ print_range_list(struct range_list *list)
cur->end, s);
}
}
- if (printed == 0) {
+ if (printed == 0)
printf("\tokay\n");
- }
}
@@ -267,7 +260,7 @@ validate_map(struct partition_map_header *map)
/* get entry */
entry = find_entry_by_disk_address(i, map);
- if (entry != 0)
+ if (entry != NULL)
dpme = entry->dpme;
else {
printf("\tunable to get\n");
@@ -309,9 +302,8 @@ validate_map(struct partition_map_header *map)
* XXX processor id is known value?
* XXX no data in reserved3
*/
- if (printed == 0) {
+ if (printed == 0)
printf("\tokay\n");
- }
}
post_processing: