aboutsummaryrefslogtreecommitdiff
path: root/sbin/camcontrol
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2023-06-19 20:42:57 +0000
committerWarner Losh <imp@FreeBSD.org>2023-06-19 20:45:43 +0000
commitfc78fd9dae66b90da70cd6c62c4d95f8e6da03f1 (patch)
treecab37e6a02913f4c1262ed94f07ed610e3b7ef9c /sbin/camcontrol
parent8259fc46ac37e56eb819760b611be9564793dc00 (diff)
downloadsrc-fc78fd9dae66b90da70cd6c62c4d95f8e6da03f1.tar.gz
src-fc78fd9dae66b90da70cd6c62c4d95f8e6da03f1.zip
Diffstat (limited to 'sbin/camcontrol')
-rw-r--r--sbin/camcontrol/camcontrol.c77
1 files changed, 37 insertions, 40 deletions
diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c
index 49786dae9ffe..0a1245e9cc48 100644
--- a/sbin/camcontrol/camcontrol.c
+++ b/sbin/camcontrol/camcontrol.c
@@ -3827,11 +3827,8 @@ readdefects(struct cam_device *device, int argc, char **argv,
struct scsi_read_defect_data_hdr_10 *hdr10 = NULL;
struct scsi_read_defect_data_hdr_12 *hdr12 = NULL;
size_t hdr_size = 0, entry_size = 0;
- int use_12byte = 0;
- int hex_format = 0;
u_int8_t *defect_list = NULL;
u_int8_t list_format = 0;
- int list_type_set = 0;
u_int32_t dlist_length = 0;
u_int32_t returned_length = 0, valid_len = 0;
u_int32_t num_returned = 0, num_valid = 0;
@@ -3839,11 +3836,11 @@ readdefects(struct cam_device *device, int argc, char **argv,
u_int32_t starting_offset = 0;
u_int8_t returned_format, returned_type;
unsigned int i;
- int summary = 0, quiet = 0;
int c, error = 0;
- int lists_specified = 0;
- int get_length = 1, first_pass = 1;
- int mads = 0;
+ int mads = 0, lists_specified = 0;
+ bool summary = false, quiet = false, list_type_set = false;
+ bool get_length = true, use_12byte = false, first_pass = true;
+ bool hex_format = false;
while ((c = getopt(argc, argv, combinedopt)) != -1) {
switch(c){
@@ -3860,7 +3857,7 @@ readdefects(struct cam_device *device, int argc, char **argv,
if (status == SCSI_NV_FOUND) {
list_format = defect_list_type_map[
entry_num].value;
- list_type_set = 1;
+ list_type_set = true;
} else {
warnx("%s: %s %s option %s", __func__,
(status == SCSI_NV_AMBIGUOUS) ?
@@ -3878,10 +3875,10 @@ readdefects(struct cam_device *device, int argc, char **argv,
arglist |= CAM_ARG_PLIST;
break;
case 'q':
- quiet = 1;
+ quiet = true;
break;
case 's':
- summary = 1;
+ summary = true;
break;
case 'S': {
char *endptr;
@@ -3895,14 +3892,14 @@ readdefects(struct cam_device *device, int argc, char **argv,
break;
}
case 'X':
- hex_format = 1;
+ hex_format = true;
break;
default:
break;
}
}
- if (list_type_set == 0) {
+ if (!list_type_set) {
error = 1;
warnx("no defect list format specified");
goto defect_bailout;
@@ -3922,7 +3919,7 @@ readdefects(struct cam_device *device, int argc, char **argv,
* This implies a summary, and was the previous behavior.
*/
if (lists_specified == 0)
- summary = 1;
+ summary = true;
ccb = cam_getccb(device);
@@ -3934,7 +3931,7 @@ retry_12byte:
* if you ask for more data than the drive has. Once we know the
* length, we retry the command with the returned length.
*/
- if (use_12byte == 0)
+ if (!use_12byte)
dlist_length = sizeof(*hdr10);
else
dlist_length = sizeof(*hdr12);
@@ -3983,7 +3980,7 @@ next_batch:
valid_len = ccb->csio.dxfer_len - ccb->csio.resid;
- if (use_12byte == 0) {
+ if (!use_12byte) {
hdr10 = (struct scsi_read_defect_data_hdr_10 *)defect_list;
hdr_size = sizeof(*hdr10);
hdr_max = SRDDH10_MAX_LENGTH;
@@ -4037,8 +4034,8 @@ next_batch:
num_valid = min(returned_length, valid_len - hdr_size);
num_valid /= entry_size;
- if (get_length != 0) {
- get_length = 0;
+ if (get_length) {
+ get_length = false;
if ((ccb->ccb_h.status & CAM_STATUS_MASK) ==
CAM_SCSI_STATUS_ERROR) {
@@ -4059,10 +4056,10 @@ next_batch:
if ((sense_key == SSD_KEY_RECOVERED_ERROR)
&& (asc == 0x1c) && (ascq == 0x00)
&& (returned_length > 0)) {
- if ((use_12byte == 0)
+ if (!use_12byte
&& (returned_length >= max_possible_size)) {
- get_length = 1;
- use_12byte = 1;
+ get_length = true;
+ use_12byte = true;
goto retry_12byte;
}
dlist_length = returned_length + hdr_size;
@@ -4077,9 +4074,9 @@ next_batch:
* command can support. Retry with the 12
* byte command.
*/
- if (use_12byte == 0) {
- get_length = 1;
- use_12byte = 1;
+ if (!use_12byte) {
+ get_length = true;
+ use_12byte = true;
goto retry_12byte;
}
dlist_length = returned_length + hdr_size;
@@ -4093,9 +4090,9 @@ next_batch:
* error and no data. Retry with the 12
* byte command.
*/
- if (use_12byte == 0) {
- get_length = 1;
- use_12byte = 1;
+ if (!use_12byte) {
+ get_length = true;
+ use_12byte = true;
goto retry_12byte;
}
dlist_length = returned_length + hdr_size;
@@ -4108,11 +4105,11 @@ next_batch:
if (returned_length == 0)
dlist_length = SRDD10_MAX_LENGTH;
else {
- if ((use_12byte == 0)
+ if (!use_12byte
&& (returned_length >=
max_possible_size)) {
- get_length = 1;
- use_12byte = 1;
+ get_length = true;
+ use_12byte = true;
goto retry_12byte;
}
dlist_length = returned_length +
@@ -4128,17 +4125,17 @@ next_batch:
CAM_EPF_ALL, stderr);
goto defect_bailout;
} else {
- if ((use_12byte == 0)
+ if (!use_12byte
&& (returned_length >= max_possible_size)) {
- get_length = 1;
- use_12byte = 1;
+ get_length = true;
+ use_12byte = true;
goto retry_12byte;
}
dlist_length = returned_length + hdr_size;
}
- if (summary != 0) {
+ if (summary) {
fprintf(stdout, "%u", num_returned);
- if (quiet == 0) {
+ if (!quiet) {
fprintf(stdout, " defect%s",
(num_returned != 1) ? "s" : "");
}
@@ -4222,7 +4219,7 @@ next_batch:
goto defect_bailout;
}
- if (first_pass != 0) {
+ if (first_pass) {
fprintf(stderr, "Got %d defect", num_returned);
if ((lists_specified == 0) || (num_returned == 0)) {
@@ -4233,7 +4230,7 @@ next_batch:
else
fprintf(stderr, "s:\n");
- first_pass = 0;
+ first_pass = false;
}
/*
@@ -4258,7 +4255,7 @@ next_batch:
0 : 1;
sector &= ~SDD_EXT_PHYS_FLAG_MASK;
}
- if (hex_format == 0)
+ if (!hex_format)
fprintf(stdout, "%d:%d:%d%s",
scsi_3btoul(dlist[i].cylinder),
dlist[i].head,
@@ -4294,7 +4291,7 @@ next_batch:
mads = (bfi & SDD_EXT_BFI_MADS) ? 1 : 0;
bfi &= ~SDD_EXT_BFI_FLAG_MASK;
}
- if (hex_format == 0)
+ if (!hex_format)
fprintf(stdout, "%d:%d:%d%s",
scsi_3btoul(dlist[i].cylinder),
dlist[i].head,
@@ -4323,7 +4320,7 @@ next_batch:
(defect_list + hdr_size);
for (i = 0; i < num_valid; i++) {
- if (hex_format == 0)
+ if (!hex_format)
fprintf(stdout, "%u\n",
scsi_4btoul(dlist[i].address));
else
@@ -4346,7 +4343,7 @@ next_batch:
(defect_list + hdr_size);
for (i = 0; i < num_valid; i++) {
- if (hex_format == 0)
+ if (!hex_format)
fprintf(stdout, "%ju\n",
(uintmax_t)scsi_8btou64(
dlist[i].address));