mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
udev/scsi: use the scsi device type number directly
Previously, the value is once stringified, and later again parsed,
that is completely redundant.
Follow-up for 1001167ca5
.
Replaces #20013.
This commit is contained in:
parent
7875170f01
commit
4dce1b9f05
@ -57,36 +57,34 @@ static char model_enc_str[256];
|
||||
static char revision_str[16];
|
||||
static char type_str[16];
|
||||
|
||||
static void set_type(const char *from, char *to, size_t len) {
|
||||
unsigned type_num;
|
||||
const char *type = "generic";
|
||||
static void set_type(unsigned type_num, char *to, size_t len) {
|
||||
const char *type;
|
||||
|
||||
if (safe_atou_full(from, 16, &type_num) >= 0) {
|
||||
switch (type_num) {
|
||||
case 0:
|
||||
type = "disk";
|
||||
break;
|
||||
case 1:
|
||||
type = "tape";
|
||||
break;
|
||||
case 4:
|
||||
type = "optical";
|
||||
break;
|
||||
case 5:
|
||||
type = "cd";
|
||||
break;
|
||||
case 7:
|
||||
type = "optical";
|
||||
break;
|
||||
case 0xe:
|
||||
type = "disk";
|
||||
break;
|
||||
case 0xf:
|
||||
type = "optical";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (type_num) {
|
||||
case 0:
|
||||
type = "disk";
|
||||
break;
|
||||
case 1:
|
||||
type = "tape";
|
||||
break;
|
||||
case 4:
|
||||
type = "optical";
|
||||
break;
|
||||
case 5:
|
||||
type = "cd";
|
||||
break;
|
||||
case 7:
|
||||
type = "optical";
|
||||
break;
|
||||
case 0xe:
|
||||
type = "disk";
|
||||
break;
|
||||
case 0xf:
|
||||
type = "optical";
|
||||
break;
|
||||
default:
|
||||
type = "generic";
|
||||
break;
|
||||
}
|
||||
strscpy(to, len, type);
|
||||
}
|
||||
|
@ -29,10 +29,10 @@ struct scsi_id_device {
|
||||
char vendor[9];
|
||||
char model[17];
|
||||
char revision[5];
|
||||
char type[33];
|
||||
char kernel[64];
|
||||
char serial[MAX_SERIAL_LEN];
|
||||
char serial_short[MAX_SERIAL_LEN];
|
||||
unsigned type;
|
||||
int use_sg;
|
||||
|
||||
/* Always from page 0x80 e.g. 'B3G1P8500RWT' - may not be unique */
|
||||
|
@ -773,7 +773,7 @@ int scsi_std_inquiry(struct scsi_id_device *dev_scsi, const char *devname) {
|
||||
dev_scsi->model[16] = '\0';
|
||||
memcpy(dev_scsi->revision, buf + 32, 4);
|
||||
dev_scsi->revision[4] = '\0';
|
||||
sprintf(dev_scsi->type,"%x", buf[0] & 0x1f);
|
||||
dev_scsi->type = buf[0] & 0x1f;
|
||||
|
||||
out:
|
||||
close(fd);
|
||||
|
Loading…
Reference in New Issue
Block a user