Refactor code related to 'camcontrol devlist'
Obtained from: Netflix
This commit is contained in:
parent
dc7eb92b78
commit
81d32f5bc2
@ -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) {
|
||||
@ -685,6 +662,70 @@ getdevtree(int argc, char **argv, char *combinedopt)
|
||||
return (error);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user