[PATCH v2] lsscsi: Fix truncation of 128-bit wwn

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently with '--wwn' flag, 128-bit wwns gets truncated and their
last 3 hex-digits missing. Below is a comparison of wwn reported by
lsscsi compared to wwn info at /dev/disk/by-id directory.

% lsscsi -w 0:0:5:0
[0:0:5:0]    disk    0x60050764008181941000000000000  /dev/sdad

% ls -l /dev/disk/by-id/wwn-*
lrwxrwxrwx. 1 root root 10 Oct 19 01:08 /dev/disk/by-id/wwn-0x600507640081819410000000000001b1 -> ../../sdad

To fix this, the patch increases the size of member wwn of struct
disk_wwn_node_entry to 35 chars to accommodate the extra '0x' prefix and
null terminator. Also the size of the buffer wwn_str thats used to
output wwn to the std-out is increased to match the corresponding
member of disk_wwn_node_entry.

Link: https://bugs.launchpad.net/ubuntu/+source/lsscsi/+bug/1636467
Link: https://bugzilla.redhat.com/show_bug.cgi?id=1387263

Cc: Jon Grimm <jon.grimm@xxxxxxxxxxxxx>
Cc: Vipin K Parashar <vipin@xxxxxxxxxxxxxxxxxx>
Cc: Ping Tian Han <pthan@xxxxxxxxxx>
Cc: Gris Ge <fge@xxxxxxxxxx>
Reported-by: Ping Tian Han <pthan@xxxxxxxxxx>
Signed-off-by: Vaibhav Jain <vaibhav@xxxxxxxxxxxxxxxxxx>
---
Change-log:

v2..v1
- Introduces macro DISK_WWN_MAX_LEN that defines the maximum length of
  wwn read from devfs. (Gris Ge)
- Fix the indentation using space instead of '\t' (Gris Ge)
---
 src/lsscsi.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/lsscsi.c b/src/lsscsi.c
index 974b3f1..5d3c602 100644
--- a/src/lsscsi.c
+++ b/src/lsscsi.c
@@ -209,8 +209,17 @@ struct dev_node_list {
 };
 static struct dev_node_list* dev_node_listhead = NULL;
 
+/* WWN here is extracted from /dev/disk/by-id/wwn-<WWN> which is
+ * created by udev 60-persistent-storage.rules using ID_WWN_WITH_EXTENSION.
+ * The udev ID_WWN_WITH_EXTENSION is the combination of char wwn[17] and
+ * char wwn_vendor_extension[17] from struct scsi_id_device. This macro
+ * defines the maximum length of char-array needed to store this wwn including
+ * the null-terminator.
+ */
+#define DISK_WWN_MAX_LEN 35
+
 struct disk_wwn_node_entry {
-       char wwn[32];
+       char wwn[DISK_WWN_MAX_LEN]; /* '0x' + wwn<128-bit> + <null-terminator> */
        char disk_bname[12];
 };
 
@@ -2939,14 +2948,15 @@ one_sdev_entry(const char * dir_name, const char * devname,
                 }
                 if (wd[0]) {
                         char dev_node[LMAX_NAME] = "";
-                        char wwn_str[34];
+                        char wwn_str[DISK_WWN_MAX_LEN];
                         enum dev_type typ;
 
                         typ = (FT_BLOCK == non_sg.ft) ? BLK_DEV : CHR_DEV;
                         if (get_wwn) {
                                 if ((BLK_DEV == typ) &&
                                     get_disk_wwn(wd, wwn_str, sizeof(wwn_str)))
-                                        printf("%-30s  ", wwn_str);
+                                        printf("%-*s  ", DISK_WWN_MAX_LEN - 1,
+                                               wwn_str);
                                 else
                                         printf("                          "
                                                "      ");
-- 
2.9.3




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux