]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
Fix the bug of Model Number and display the info of Serial Number
authorseehearfeel <seehearfeel@126.com>
Sat, 26 Mar 2016 13:14:43 +0000 (21:14 +0800)
committerseehearfeel <seehearfeel@126.com>
Sat, 26 Mar 2016 13:14:43 +0000 (21:14 +0800)
OK, I see, thanks for your suggestion.

I have modified the related code of Serial Number, Model Number and Firmware Revision,
other fields are not be changed because the length can not be properly figured out by
the print format specifier, (int)sizeof(field) is too big and (int)strlen(field) is random.
In addition, fix a minor spelling mistake "Namepace" to "Namespace".

Please review, thanks!

nvme-print.c
nvme.c

index 5722111affa941ffeeb1efdc6af83149aeb0202a..bfe94462d6bdea72a39dafd1d217227f90181e74 100644 (file)
@@ -578,9 +578,9 @@ void show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode)
 
        printf("vid     : %#x\n", le16toh(ctrl->vid));
        printf("ssvid   : %#x\n", le16toh(ctrl->ssvid));
-       printf("sn      : %-20.20s\n", ctrl->sn);
-       printf("mn      : %-40.40s\n", ctrl->mn);
-       printf("fr      : %-.8s\n", ctrl->fr);
+       printf("sn      : %-.*s\n", (int)sizeof(ctrl->sn), ctrl->sn);
+       printf("mn      : %-.*s\n", (int)sizeof(ctrl->mn), ctrl->mn);
+       printf("fr      : %-.*s\n", (int)sizeof(ctrl->fr), ctrl->fr);
        printf("rab     : %d\n", ctrl->rab);
        printf("ieee    : %02x%02x%02x\n",
                ctrl->ieee[2], ctrl->ieee[1], ctrl->ieee[0]);
diff --git a/nvme.c b/nvme.c
index 4f4307af3676072790e660843d3fe35682b86f5c..08875db59806d8fdc810a466dcff36b15dafa13f 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -758,19 +758,21 @@ static void print_list_item(struct list_item list_item)
        sprintf(version,"%d.%d", (list_item.ver >> 16),
                (list_item.ver >> 8) & 0xff);
 
-       printf("%-16s %-20.20s %-40.40s %-8s %-8d %-26s %-16s %-.8s\n", list_item.node,
-           list_item.ctrl.sn, list_item.ctrl.mn, version, list_item.nsid, usage, format, list_item.ctrl.fr);
+       printf("%-16s %-*.*s %-*.*s %-8s %-9d %-26s %-16s %-.*s\n", list_item.node,
+            (int)sizeof(list_item.ctrl.sn), (int)sizeof(list_item.ctrl.sn), list_item.ctrl.sn,
+            (int)sizeof(list_item.ctrl.mn), (int)sizeof(list_item.ctrl.mn), list_item.ctrl.mn,
+            version, list_item.nsid, usage, format, (int)sizeof(list_item.ctrl.fr), list_item.ctrl.fr);
 }
 
 static void print_list_items(struct list_item *list_items, unsigned len)
 {
        unsigned i;
 
-       printf("%-16s %-20s %-40s %-8s %-8s %-26s %-16s %-8s\n",
-           "Node", "SN", "Model", "Version", "Namepace", "Usage", "Format", "FW Rev");
-       printf("%-16s %-20s %-40s %-8s %-8s %-26s %-16s %-8s\n",
+       printf("%-16s %-20s %-40s %-8s %-9s %-26s %-16s %-8s\n",
+           "Node", "SN", "Model", "Version", "Namespace", "Usage", "Format", "FW Rev");
+       printf("%-16s %-20s %-40s %-8s %-9s %-26s %-16s %-8s\n",
             "----------------", "--------------------", "----------------------------------------",
-            "--------", "--------", "--------------------------", "----------------", "--------");
+            "--------", "---------", "--------------------------", "----------------", "--------");
        for (i = 0 ; i < len ; i++)
                print_list_item(list_items[i]);