From 8b591f5954708423917c1cc234302e5463229eeb Mon Sep 17 00:00:00 2001
From: chrfranke <chrfranke@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Tue, 30 May 2023 12:36:57 +0000
Subject: [PATCH] nvmecmds.cpp, nvmprint.cpp: Also suppress NVMe Namespace IEEE
 EUI-64 info if '-q noserial' is specified. smartctl.8.in: Update '-q
 noserial' documentation.

git-svn-id: https://svn.code.sf.net/p/smartmontools/code/trunk@5473 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 smartmontools/ChangeLog     |  4 ++++
 smartmontools/nvmecmds.cpp  | 16 +++++++++++-----
 smartmontools/nvmeprint.cpp |  2 +-
 smartmontools/smartctl.8.in |  7 +++++++
 4 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/smartmontools/ChangeLog b/smartmontools/ChangeLog
index 0232014ed..10ee1fe34 100644
--- a/smartmontools/ChangeLog
+++ b/smartmontools/ChangeLog
@@ -2,6 +2,10 @@ $Id$
 
 2023-05-30  Christian Franke  <franke@computer.org>
 
+	nvmecmds.cpp, nvmprint.cpp: Also suppress NVMe Namespace IEEE EUI-64
+	info if '-q noserial' is specified.
+	smartctl.8.in: Update '-q noserial' documentation.
+
 	smartd.cpp: Don't report new non-device related errors as critical
 	(#1222).
 	smartd.conf.5.in: Document new functionality.
diff --git a/smartmontools/nvmecmds.cpp b/smartmontools/nvmecmds.cpp
index ee45a61ef..ead99518c 100644
--- a/smartmontools/nvmecmds.cpp
+++ b/smartmontools/nvmecmds.cpp
@@ -72,11 +72,17 @@ static bool nvme_pass_through(nvme_device * device, const nvme_cmd_in & in,
       pout(" [Duration: %.6fs]\n", duration_usec / 1000000.0);
   }
 
-  if (   dont_print_serial_number && ok
-      && in.opcode == nvme_admin_identify && in.cdw10 == 0x01) {
-        // Invalidate serial number
-        nvme_id_ctrl & id_ctrl = *reinterpret_cast<nvme_id_ctrl *>(in.buffer);
-        memset(id_ctrl.sn, 'X', sizeof(id_ctrl.sn));
+  if (dont_print_serial_number && ok && in.opcode == nvme_admin_identify) {
+    if (in.cdw10 == 0x01 && in.size >= sizeof(nvme_id_ctrl)) {
+      // Identify controller: Invalidate serial number
+      nvme_id_ctrl & id_ctrl = *reinterpret_cast<nvme_id_ctrl *>(in.buffer);
+      memset(id_ctrl.sn, 'X', sizeof(id_ctrl.sn));
+    }
+    else if (in.cdw10 == 0x00 && in.size >= sizeof(nvme_id_ns)) {
+      // Identify namespace: Invalidate IEEE EUI-64
+      nvme_id_ns & id_ns = *reinterpret_cast<nvme_id_ns *>(in.buffer);
+      memset(id_ns.eui64, 0x00, sizeof(id_ns.eui64));
+    }
   }
 
   if (nvme_debugmode) {
diff --git a/smartmontools/nvmeprint.cpp b/smartmontools/nvmeprint.cpp
index 13307895c..4a35254d3 100644
--- a/smartmontools/nvmeprint.cpp
+++ b/smartmontools/nvmeprint.cpp
@@ -192,7 +192,7 @@ static void print_drive_info(const nvme_id_ctrl & id_ctrl, const nvme_id_ns & id
     jrns["formatted_lba_size"] = (1U << fmt_lba_bits);
     jglb["logical_block_size"] = (1U << fmt_lba_bits);
 
-    if (show_all || nonempty(id_ns.eui64, sizeof(id_ns.eui64))) {
+    if (!dont_print_serial_number && (show_all || nonempty(id_ns.eui64, sizeof(id_ns.eui64)))) {
       jout("Namespace %u IEEE EUI-64:          %s%02x%02x%02x %02x%02x%02x%02x%02x\n",
            nsid, align, id_ns.eui64[0], id_ns.eui64[1], id_ns.eui64[2], id_ns.eui64[3],
            id_ns.eui64[4], id_ns.eui64[5], id_ns.eui64[6], id_ns.eui64[7]);
diff --git a/smartmontools/smartctl.8.in b/smartmontools/smartctl.8.in
index c17fc5932..cc2d9aef4 100644
--- a/smartmontools/smartctl.8.in
+++ b/smartmontools/smartctl.8.in
@@ -382,6 +382,13 @@ use the exit status of \fBsmartctl\fP (see EXIT STATUS below).
 .Sp
 .I noserial
 \- Do not print the serial number of the device.
+This also suppresses the LU WWN Device Id (ATA) and the SAS addresses (SCSI).
+The related fields are also invalidated in the ATA and NVMe debug outputs.
+.br
+Note: This is not the case in SCSI debug output.
+.br
+[NEW EXPERIMENTAL SMARTCTL FEATURE]
+The Namespace IEEE EUI-64 (NVMe) is also suppressed.
 .TP
 .B \-d TYPE, \-\-device=TYPE
 Specifies the type of the device.
-- 
GitLab