.\" 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
.\" -----------------------------------------------------------------
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\&.
</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
<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
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 };
char class[13] = { 0 };
size_t size = 1024;
char ret;
+ FILE *file = open_pci_ids();
if (!file)
goto error1;
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))
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");
}