aboutsummaryrefslogtreecommitdiff
path: root/sbin/camcontrol
diff options
context:
space:
mode:
authorScott Long <scottl@FreeBSD.org>2018-01-10 05:52:24 +0000
committerScott Long <scottl@FreeBSD.org>2018-01-10 05:52:24 +0000
commitf2592b12e904d9a97a37a8f571bd1ba770aebd16 (patch)
tree98ae0c3a4e29ce75dd8efd6ae282580dd1535a78 /sbin/camcontrol
parentc371df4f47720a35d188e93b0f9c489592c32232 (diff)
downloadsrc-f2592b12e904d9a97a37a8f571bd1ba770aebd16.tar.gz
src-f2592b12e904d9a97a37a8f571bd1ba770aebd16.zip
Refactor code related to 'camcontrol devlist'
Obtained from: Netflix
Notes
Notes: svn path=/head/; revision=327762
Diffstat (limited to 'sbin/camcontrol')
-rw-r--r--sbin/camcontrol/camcontrol.c139
1 files changed, 90 insertions, 49 deletions
diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c
index c484d4375e00..f35dfa453fd4 100644
--- a/sbin/camcontrol/camcontrol.c
+++ b/sbin/camcontrol/camcontrol.c
@@ -275,6 +275,11 @@ camcontrol_optret getoption(struct camcontrol_opts *table, char *arg,
static int getdevlist(struct cam_device *device);
#endif /* MINIMALISTIC */
static int getdevtree(int argc, char **argv, char *combinedopt);
+static int print_dev_scsi(struct device_match_result *dev_result, char *tmpstr);
+static int print_dev_ata(struct device_match_result *dev_result, char *tmpstr);
+static int print_dev_semb(struct device_match_result *dev_result, char *tmpstr);
+static int print_dev_mmcsd(struct device_match_result *dev_result,
+ char *tmpstr);
static int print_dev_nvme(struct device_match_result *dev_result, char *tmpstr);
#ifndef MINIMALISTIC
static int testunitready(struct cam_device *device, int task_attr,
@@ -555,8 +560,7 @@ getdevtree(int argc, char **argv, char *combinedopt)
}
case DEV_MATCH_DEVICE: {
struct device_match_result *dev_result;
- char vendor[16], product[48], revision[16];
- char fw[5], tmpstr[256];
+ char tmpstr[256];
if (busonly == 1)
break;
@@ -573,57 +577,30 @@ getdevtree(int argc, char **argv, char *combinedopt)
skip_device = 0;
if (dev_result->protocol == PROTO_SCSI) {
- cam_strvis(vendor, dev_result->inq_data.vendor,
- sizeof(dev_result->inq_data.vendor),
- sizeof(vendor));
- cam_strvis(product,
- dev_result->inq_data.product,
- sizeof(dev_result->inq_data.product),
- sizeof(product));
- cam_strvis(revision,
- dev_result->inq_data.revision,
- sizeof(dev_result->inq_data.revision),
- sizeof(revision));
- sprintf(tmpstr, "<%s %s %s>", vendor, product,
- revision);
+ if (print_dev_scsi(dev_result,
+ &tmpstr[0]) != 0) {
+ skip_device = 1;
+ break;
+ }
} else if (dev_result->protocol == PROTO_ATA ||
dev_result->protocol == PROTO_SATAPM) {
- cam_strvis(product,
- dev_result->ident_data.model,
- sizeof(dev_result->ident_data.model),
- sizeof(product));
- cam_strvis(revision,
- dev_result->ident_data.revision,
- sizeof(dev_result->ident_data.revision),
- sizeof(revision));
- sprintf(tmpstr, "<%s %s>", product,
- revision);
- } else if (dev_result->protocol == PROTO_MMCSD) {
- if (strlen(dev_result->mmc_ident_data.model) > 0) {
- sprintf(tmpstr, "<%s>", dev_result->mmc_ident_data.model);
- } else {
- sprintf(tmpstr, "<%s card>",
- dev_result->mmc_ident_data.card_features & CARD_FEATURE_SDIO ? "SDIO" : "unknown");
+ if (print_dev_ata(dev_result,
+ &tmpstr[0]) != 0) {
+ skip_device = 1;
+ break;
+ }
+ } else if (dev_result->protocol == PROTO_MMCSD){
+ if (print_dev_mmcsd(dev_result,
+ &tmpstr[0]) != 0) {
+ skip_device = 1;
+ break;
}
} else if (dev_result->protocol == PROTO_SEMB) {
- struct sep_identify_data *sid;
-
- sid = (struct sep_identify_data *)
- &dev_result->ident_data;
- cam_strvis(vendor, sid->vendor_id,
- sizeof(sid->vendor_id),
- sizeof(vendor));
- cam_strvis(product, sid->product_id,
- sizeof(sid->product_id),
- sizeof(product));
- cam_strvis(revision, sid->product_rev,
- sizeof(sid->product_rev),
- sizeof(revision));
- cam_strvis(fw, sid->firmware_rev,
- sizeof(sid->firmware_rev),
- sizeof(fw));
- sprintf(tmpstr, "<%s %s %s %s>",
- vendor, product, revision, fw);
+ if (print_dev_semb(dev_result,
+ &tmpstr[0]) != 0) {
+ skip_device = 1;
+ break;
+ }
} else if (dev_result->protocol == PROTO_NVME) {
if (print_dev_nvme(dev_result,
&tmpstr[0]) != 0) {
@@ -686,6 +663,70 @@ getdevtree(int argc, char **argv, char *combinedopt)
}
static int
+print_dev_scsi(struct device_match_result *dev_result, char *tmpstr)
+{
+ char vendor[16], product[48], revision[16];
+
+ cam_strvis(vendor, dev_result->inq_data.vendor,
+ sizeof(dev_result->inq_data.vendor), sizeof(vendor));
+ cam_strvis(product, dev_result->inq_data.product,
+ sizeof(dev_result->inq_data.product), sizeof(product));
+ cam_strvis(revision, dev_result->inq_data.revision,
+ sizeof(dev_result->inq_data.revision), sizeof(revision));
+ sprintf(tmpstr, "<%s %s %s>", vendor, product, revision);
+
+ return (0);
+}
+
+static int
+print_dev_ata(struct device_match_result *dev_result, char *tmpstr)
+{
+ char product[48], revision[16];
+
+ cam_strvis(product, dev_result->ident_data.model,
+ sizeof(dev_result->ident_data.model), sizeof(product));
+ cam_strvis(revision, dev_result->ident_data.revision,
+ sizeof(dev_result->ident_data.revision), sizeof(revision));
+ sprintf(tmpstr, "<%s %s>", product, revision);
+
+ return (0);
+}
+
+static int
+print_dev_semb(struct device_match_result *dev_result, char *tmpstr)
+{
+ struct sep_identify_data *sid;
+ char vendor[16], product[48], revision[16], fw[5];
+
+ sid = (struct sep_identify_data *)&dev_result->ident_data;
+ cam_strvis(vendor, sid->vendor_id,
+ sizeof(sid->vendor_id), sizeof(vendor));
+ cam_strvis(product, sid->product_id,
+ sizeof(sid->product_id), sizeof(product));
+ cam_strvis(revision, sid->product_rev,
+ sizeof(sid->product_rev), sizeof(revision));
+ cam_strvis(fw, sid->firmware_rev,
+ sizeof(sid->firmware_rev), sizeof(fw));
+ sprintf(tmpstr, "<%s %s %s %s>", vendor, product, revision, fw);
+
+ return (0);
+}
+
+static int
+print_dev_mmcsd(struct device_match_result *dev_result, char *tmpstr)
+{
+
+ if (strlen(dev_result->mmc_ident_data.model) > 0) {
+ sprintf(tmpstr, "<%s>", dev_result->mmc_ident_data.model);
+ } else {
+ sprintf(tmpstr, "<%s card>",
+ dev_result->mmc_ident_data.card_features &
+ CARD_FEATURE_SDIO ? "SDIO" : "unknown");
+ }
+ return (0);
+}
+
+static int
print_dev_nvme(struct device_match_result *dev_result, char *tmpstr)
{
union ccb *ccb;