]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-models.c - search for pci.ids
authorEyal Ben David <eyalbe@il.ibm.com>
Sat, 4 Aug 2018 21:15:51 +0000 (00:15 +0300)
committerEyal Ben David <eyalbe@il.ibm.com>
Sun, 12 Aug 2018 12:03:39 +0000 (15:03 +0300)
Take from PCI_IDS_PATH or look at some default locations
Updated docs for the envrironment in nvme-list.txt
Regenerated man and html pages.

Documentation/nvme-list.1
Documentation/nvme-list.html
Documentation/nvme-list.txt
nvme-models.c

index ca4a7087475f39a36387fdb6a1067ea0a4b02b7b..077c2b53ac0272eb9bbbeca1680f5c9475b128ed 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: nvme-list
 .\"    Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
-.\"      Date: 06/05/2018
+.\"      Date: 08/05/2018
 .\"    Manual: NVMe Manual
 .\"    Source: NVMe
 .\"  Language: English
 .\"
-.TH "NVME\-LIST" "1" "06/05/2018" "NVMe" "NVMe Manual"
+.TH "NVME\-LIST" "1" "08/05/2018" "NVMe" "NVMe Manual"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
@@ -46,6 +46,9 @@ Set the reporting format to
 or
 \fIjson\fR\&. Only one output format can be used at a time\&.
 .RE
+.SH "ENVIRONMENT"
+.sp
+PCI_IDS_PATH \- Full path of pci\&.ids file in case nvme could not find it in common locations\&.
 .SH "EXAMPLES"
 .sp
 No examples yet\&.
index ef2c626bc80c8e188de45c0a966f681b747a4958..91105201fcf9fc502fb7b0ef3030ee952112e06d 100644 (file)
@@ -778,6 +778,12 @@ for those devices as well as some pertinent information about them.</p></div>
 </div>\r
 </div>\r
 <div class="sect1">\r
+<h2 id="_environment">ENVIRONMENT</h2>\r
+<div class="sectionbody">\r
+<div class="paragraph"><p>PCI_IDS_PATH - Full path of pci.ids file in case nvme could not find it in common locations.</p></div>\r
+</div>\r
+</div>\r
+<div class="sect1">\r
 <h2 id="_examples">EXAMPLES</h2>\r
 <div class="sectionbody">\r
 <div class="paragraph"><p>No examples yet.</p></div>\r
@@ -793,7 +799,7 @@ for those devices as well as some pertinent information about them.</p></div>
 <div id="footnotes"><hr /></div>\r
 <div id="footer">\r
 <div id="footer-text">\r
-Last updated 2017-02-27 10:11:58 EST\r
+Last updated 2018-08-05 00:13:13 IDT\r
 </div>\r
 </div>\r
 </body>\r
index a0326f5ebdb0f0a3cc38d39238e80735ffb17033..a52e14b3e6ff5f4cd460103815c13daa8a641898 100644 (file)
@@ -22,6 +22,11 @@ OPTIONS
        Set the reporting format to 'normal' or 'json'. Only one output
        format can be used at a time.
 
+ENVIRONMENT
+-----------
+PCI_IDS_PATH - Full path of pci.ids file in case nvme could not find it in common locations.
+
+
 EXAMPLES
 --------
 No examples yet.
index c2b16c336a03e7228355393b066a7d596fe6739a..43ab50acf7f134043ee16917135fb338e12c2127 100644 (file)
@@ -242,11 +242,45 @@ static int read_sys_node(char *where, char *save, size_t savesz)
        return ret;
 }
 
+static FILE *open_pci_ids(void)
+{
+       int i;
+       char *pci_ids_path;
+       FILE *fp;
+
+       const char* pci_ids[] = {
+               "/usr/share/hwdata/pci.ids",  /* RHEL */
+               "/usr/share/pci.ids",             /* SLES */
+               "/usr/share/misc/pci.ids",        /* Ubuntu */
+               NULL
+       };
+
+       /* First check if user gave pci ids in environment */
+       if ((pci_ids_path = getenv("PCI_IDS_PATH")) != NULL) {
+               if ((fp = fopen(pci_ids_path, "r")) != NULL) {
+                       return fp;
+               }
+               else {
+                       /* fail if user provided environment variable but could not open */
+                       perror(pci_ids_path);
+                       return NULL;
+               }
+       }
+
+       /* NO environment, check in predefined places */
+       for (i = 0; pci_ids[i] != NULL; i++) {
+               if ((fp = fopen(pci_ids[i], "r")) != NULL)
+                       return fp;
+       }
+
+       fprintf(stderr, "Could not find pci.ids file\n");
+       return NULL;
+}
+
 char *nvme_product_name(int id)
 {
        char *line;
        ssize_t amnt;
-       FILE *file = fopen("/usr/share/hwdata/pci.ids", "r");
        char vendor[7] = { 0 };
        char device[7] = { 0 };
        char sub_device[7] = { 0 };
@@ -254,6 +288,7 @@ char *nvme_product_name(int id)
        char class[13] = { 0 };
        size_t size = 1024;
        char ret;
+       FILE *file = open_pci_ids();
 
        if (!file)
                goto error1;
@@ -270,12 +305,11 @@ char *nvme_product_name(int id)
        ret |= read_sys_node(fmt4, device, 7);
        ret |= read_sys_node(fmt5, class, 13);
        if (ret)
-               goto error1;
-
+               goto error0;
 
        line = malloc(1024);
        if (!line)
-               goto error1;
+               goto error0;
 
        while ((amnt = getline(&line, &size, file)) != -1) {
                if (is_comment(line) && !is_class_info(line))
@@ -284,16 +318,19 @@ char *nvme_product_name(int id)
                        line[amnt - 1] = '\0';
                        device_top = strdup(line);
                        parse_vendor_device(&line, file,
-                                           device,
-                                           sub_device,
-                                           sub_vendor);
+                                               device,
+                                               sub_device,
+                                               sub_vendor);
                }
                if (is_class_info(line))
                        pull_class_info(&line, file, class);
        }
+       fclose(file);
        format_all(line, vendor, device);
        free_all();
        return line;
- error1:
+error0:
+       fclose(file);
+error1:
        return strdup("Unknown Device");
 }