]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/udev/ata_id/ata_id.c
tree-wide: beautify remaining copyright statements
[thirdparty/systemd.git] / src / udev / ata_id / ata_id.c
index 7ba0b7fc8f2048e171feaf8eb46f1617424fe6c0..c1367a34f369eb996444da19c088e2bf4fee1aa8 100644 (file)
@@ -1,9 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
 /*
  * ata_id - reads product/serial number from ATA drives
  *
- * Copyright (C) 2005-2008 Kay Sievers <kay@vrfy.org>
- * Copyright (C) 2009 Lennart Poettering <lennart@poettering.net>
- * Copyright (C) 2009-2010 David Zeuthen <zeuthen@gmail.com>
+ * Copyright © 2005-2008 Kay Sievers <kay@vrfy.org>
+ * Copyright © 2009-2010 David Zeuthen <zeuthen@gmail.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <fcntl.h>
 #include <ctype.h>
-#include <string.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <getopt.h>
+#include <linux/bsg.h>
+#include <linux/hdreg.h>
 #include <scsi/scsi.h>
-#include <scsi/sg.h>
 #include <scsi/scsi_ioctl.h>
+#include <scsi/sg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <sys/ioctl.h>
-#include <sys/types.h>
 #include <sys/stat.h>
-#include <linux/hdreg.h>
-#include <linux/bsg.h>
+#include <sys/types.h>
+#include <unistd.h>
 
 #include "libudev.h"
+
+#include "fd-util.h"
 #include "libudev-private.h"
-#include "udev-util.h"
 #include "log.h"
+#include "udev-util.h"
 
 #define COMMAND_TIMEOUT_MSEC (30 * 1000)
 
@@ -315,7 +317,7 @@ static void disk_identify_fixup_uint16 (uint8_t identify[512], unsigned int offs
  * device represented by @fd. If successful, then the result will be
  * copied into @out_identify and @out_is_packet_device.
  *
- * This routine is based on code from libatasmart, Copyright 2008
+ * This routine is based on code from libatasmart, Copyright © 2008
  * Lennart Poettering, LGPL v2.1.
  *
  * Returns: 0 if the data was successfully obtained, otherwise
@@ -402,14 +404,12 @@ out:
         return ret;
 }
 
-int main(int argc, char *argv[])
-{
-        _cleanup_udev_unref_ struct udev *udev = NULL;
+int main(int argc, char *argv[]) {
+        _cleanup_(udev_unrefp) struct udev *udev = NULL;
         struct hd_driveid id;
         union {
                 uint8_t  byte[512];
                 uint16_t wyde[256];
-                uint64_t octa[64];
         } identify;
         char model[41];
         char model_enc[256];
@@ -426,6 +426,8 @@ int main(int argc, char *argv[])
                 {}
         };
 
+        log_set_target(LOG_TARGET_AUTO);
+        udev_parse_config();
         log_parse_environment();
         log_open();
 
@@ -433,7 +435,7 @@ int main(int argc, char *argv[])
         if (udev == NULL)
                 return 0;
 
-        while (1) {
+        for (;;) {
                 int option;
 
                 option = getopt_long(argc, argv, "xh", options, NULL);
@@ -474,7 +476,7 @@ int main(int argc, char *argv[])
                 disk_identify_fixup_string(identify.byte,  27, 40); /* model */
                 disk_identify_fixup_uint16(identify.byte,  0);      /* configuration */
                 disk_identify_fixup_uint16(identify.byte,  75);     /* queue depth */
-                disk_identify_fixup_uint16(identify.byte,  75);     /* SATA capabilities */
+                disk_identify_fixup_uint16(identify.byte,  76);     /* SATA capabilities */
                 disk_identify_fixup_uint16(identify.byte,  82);     /* command set supported */
                 disk_identify_fixup_uint16(identify.byte,  83);     /* command set supported */
                 disk_identify_fixup_uint16(identify.byte,  84);     /* command set supported */
@@ -485,6 +487,10 @@ int main(int argc, char *argv[])
                 disk_identify_fixup_uint16(identify.byte,  90);     /* time required for enhanced SECURITY ERASE UNIT */
                 disk_identify_fixup_uint16(identify.byte,  91);     /* current APM values */
                 disk_identify_fixup_uint16(identify.byte,  94);     /* current AAM value */
+                disk_identify_fixup_uint16(identify.byte, 108);     /* WWN */
+                disk_identify_fixup_uint16(identify.byte, 109);     /* WWN */
+                disk_identify_fixup_uint16(identify.byte, 110);     /* WWN */
+                disk_identify_fixup_uint16(identify.byte, 111);     /* WWN */
                 disk_identify_fixup_uint16(identify.byte, 128);     /* device lock function */
                 disk_identify_fixup_uint16(identify.byte, 217);     /* nominal media rotation rate */
                 memcpy(&id, identify.byte, sizeof id);
@@ -610,7 +616,7 @@ int main(int argc, char *argv[])
                  */
 
                 word = identify.wyde[76];
-                if (word != 0x0000 && word != 0xffff) {
+                if (!IN_SET(word, 0x0000, 0xffff)) {
                         printf("ID_ATA_SATA=1\n");
                         /*
                          * If bit 2 of word 76 is set to one, then the device supports the Gen2
@@ -638,14 +644,23 @@ int main(int argc, char *argv[])
                  * All other values are reserved.
                  */
                 word = identify.wyde[108];
-                if ((word & 0xf000) == 0x5000)
+                if ((word & 0xf000) == 0x5000) {
+                        uint64_t wwwn;
+
+                        wwwn   = identify.wyde[108];
+                        wwwn <<= 16;
+                        wwwn  |= identify.wyde[109];
+                        wwwn <<= 16;
+                        wwwn  |= identify.wyde[110];
+                        wwwn <<= 16;
+                        wwwn  |= identify.wyde[111];
                         printf("ID_WWN=0x%1$" PRIx64 "\n"
                                "ID_WWN_WITH_EXTENSION=0x%1$" PRIx64 "\n",
-                               identify.octa[108/4]);
+                               wwwn);
+                }
 
                 /* from Linux's include/linux/ata.h */
-                if (identify.wyde[0] == 0x848a ||
-                    identify.wyde[0] == 0x844a ||
+                if (IN_SET(identify.wyde[0], 0x848a, 0x844a) ||
                     (identify.wyde[83] & 0xc004) == 0x4004)
                         printf("ID_ATA_CFA=1\n");
         } else {