]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev/scsi: use the scsi device type number directly
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 25 Jun 2021 06:04:12 +0000 (15:04 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 25 Jun 2021 11:31:19 +0000 (13:31 +0200)
Previously, the value is once stringified, and later again parsed,
that is completely redundant.

Follow-up for 1001167ca5e4cfdc6230562e4fb9029e5f624d53.

Replaces #20013.

src/udev/scsi_id/scsi_id.c
src/udev/scsi_id/scsi_id.h
src/udev/scsi_id/scsi_serial.c

index 943262d4363f821c3e1e742e88ea0302881447c0..b2d8154d86cbf0e8ed2fecba3d4670b638e602e3 100644 (file)
@@ -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";
-
-        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;
-                }
+static void set_type(unsigned type_num, char *to, size_t len) {
+        const char *type;
+
+        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);
 }
index 2fe64f45f255d91514865e293bfe7c3f9c2beb90..9ab33418559390cdd71d043811f9d0b926182a71 100644 (file)
@@ -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 */
index 4fe725477f53f48387cba87c7d14cb1f5bbd7c77..489f5ad16a6cdb95a1a879cf2a6b0c36af56849c 100644 (file)
@@ -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);