2 * libefiboot - library for the manipulation of EFI boot variables
3 * Copyright 2012-2015 Red Hat, Inc.
4 * Copyright (C) 2001 Dell Computer Corporation <Matt_Domsch@dell.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see
18 * <http://www.gnu.org/licenses/>.
26 #include <linux/ethtool.h>
27 #include <linux/version.h>
28 #include <linux/sockios.h>
30 #include <scsi/scsi.h>
32 #include <sys/ioctl.h>
33 #include <sys/socket.h>
34 #include <sys/sysmacros.h>
35 #include <sys/types.h>
36 #include <sys/param.h>
40 #include <efivar/efivar.h>
41 #include <efivar/efiboot.h>
48 __attribute__((__visibility__ ("hidden")))
49 set_disk_and_part_name(struct disk_info *info)
54 rc = sysfs_readlink(&linkbuf, "/sys/dev/block/%"PRIu64":%"PRIu32,
55 info->major, info->minor);
56 if (rc < 0 || !linkbuf)
60 ultimate = strrchr(linkbuf, '/');
69 penultimate = strrchr(linkbuf, '/');
77 * If there's a better way to figure this out, it'd be good, because
78 * I don't want to have to change this for every new disk type...
80 if (!strncmp(ultimate, "pmem", 4)) {
81 if (!info->disk_name) {
82 info->disk_name = strdup(ultimate);
86 } else if (!strcmp(penultimate, "block")) {
87 if (!info->disk_name) {
88 info->disk_name = strdup(ultimate);
92 if (!info->part_name) {
93 rc = asprintf(&info->part_name, "%s%d", info->disk_name,
98 } else if (!strncmp(penultimate, "nvme", 4)) {
99 if (!info->disk_name) {
100 info->disk_name = strdup(ultimate);
101 if (!info->disk_name)
104 if (!info->part_name) {
105 rc = asprintf(&info->part_name, "%sp%d",
106 info->disk_name, info->part);
111 if (!info->disk_name) {
112 info->disk_name = strdup(penultimate);
113 if (!info->disk_name)
116 if (!info->part_name) {
117 info->part_name = strdup(ultimate);
118 if (!info->part_name)
127 __attribute__((__visibility__ ("hidden")))
128 get_partition_number(const char *devpath)
130 struct stat statbuf = { 0, };
132 unsigned int maj, min;
137 rc = stat(devpath, &statbuf);
139 efi_error("couldn't stat %s\n", devpath);
143 if (!S_ISBLK(statbuf.st_mode)) {
144 efi_error("%s is not a block device\n", devpath);
149 maj = major(statbuf.st_rdev);
150 min = minor(statbuf.st_rdev);
152 rc = sysfs_readlink(&linkbuf, "/sys/dev/block/%u:%u", maj, min);
153 if (rc < 0 || !linkbuf) {
154 efi_error("couldn't get partition number for %u:%u", maj, min);
158 rc = read_sysfs_file(&partbuf, "/sys/dev/block/%s/partition", linkbuf);
160 efi_error("couldn't get partition number for %s", linkbuf);
161 /* This isn't strictly an error for e.g. nvdimm pmem devices */
165 rc = sscanf((char *)partbuf, "%d\n", &ret);
167 efi_error("couldn't get partition number for %s", partbuf);
174 __attribute__((__visibility__ ("hidden")))
175 find_parent_devpath(const char * const child, char **parent)
181 /* strip leading /dev/ */
182 node = strrchr(child, '/');
187 /* look up full path symlink */
188 ret = sysfs_readlink(&linkbuf, "/sys/class/block/%s", node);
189 if (ret < 0 || !linkbuf)
193 node = strrchr(linkbuf, '/');
199 node = strrchr(linkbuf, '/');
205 /* write out new path */
206 ret = asprintf(parent, "/dev/%s", node);
215 sysfs_test_pmem(const char *buf)
217 char *driverbuf = NULL;
220 rc = sysfs_readlink(&driverbuf,
221 "/sys/dev/block/%s/device/driver", buf);
222 if (rc < 0 || !driverbuf)
225 char *driver = strrchr(driverbuf, '/');
226 if (!driver || !*driver)
229 if (!strcmp(driver, "nd_pmem"))
235 sysfs_test_nvme(const char *buf, ssize_t size)
237 if (!strncmp(buf, "nvme/", MIN(size, 5)))
243 sysfs_test_sata(const char *buf, ssize_t size)
245 if (!strncmp(buf, "ata", MIN(size, 3)))
251 sysfs_test_sas(const char *buf, ssize_t size)
255 struct stat statbuf = { 0, };
261 newbuf = strndupa(buf, size+1);
267 rc = sscanf(newbuf, "host%d/%n", &host, &sz);
269 return (errno == 0) ? 0 : -1;
271 rc = asprintfa(&path, "/sys/class/scsi_host/host%d/host_sas_address",
276 rc = stat(path, &statbuf);
283 sysfs_sata_get_port_info(uint32_t print_id, struct disk_info *info)
290 d = opendir("/sys/class/ata_device/");
292 efi_error("opendir failed on /sys/class/ata_device/");
296 while ((de = readdir(d)) != NULL) {
297 uint32_t found_print_id;
299 uint32_t found_devno = 0;
301 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
305 rc = sscanf(de->d_name, "dev%d.%d.%d", &found_print_id,
306 &found_pmp, &found_devno);
307 if (rc < 2 || rc > 3) {
311 } else if (found_print_id != print_id) {
313 } else if (rc == 3) {
315 * the kernel doesn't't ever tell us the SATA PMPN
316 * sentinal value, it'll give us devM.N instead of
317 * devM.N.O in that case instead.
319 if (found_pmp > 0x7fff) {
324 info->sata_info.ata_devno = 0;
325 info->sata_info.ata_pmp = found_pmp;
327 } else if (rc == 2) {
328 info->sata_info.ata_devno = 0;
329 info->sata_info.ata_pmp = 0xffff;
335 rc = read_sysfs_file(&buf, "/sys/class/ata_port/ata%d/port_no",
337 if (rc <= 0 || buf == NULL)
340 rc = sscanf((char *)buf, "%d", &info->sata_info.ata_port);
345 * ata_port numbers are 1-indexed from libata in the kernel, but
346 * they're 0-indexed in the spec. For maximal confusion.
348 if (info->sata_info.ata_port == 0) {
352 info->sata_info.ata_port -= 1;
358 /* pmem12s -> ../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.1/block/pmem12s
360 * device -> ../../../btt12.1
361 * device/uuid: 0cee166e-dd56-4bc2-99d2-2544b69025b8
362 * 259:0 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.1/block/pmem12s
364 * pmem12.1s -> ../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.2/block/pmem12.1s
366 * device -> ../../../btt12.2
367 * device/uuid: 78d94521-91f7-47db-b3a7-51b764281940
368 * 259:1 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.2/block/pmem12.1s
370 * pmem12.2 -> ../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/pfn12.1/block/pmem12.2
372 * device -> ../../../pfn12.1
373 * device/uuid: 829c5205-89a5-4581-9819-df7d7754c622
374 * 259:2 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/pfn12.1/block/pmem12.2
377 sysfs_parse_pmem(uint8_t *buf, ssize_t size, ssize_t *off,
378 const char *pbuf, ssize_t psize __attribute__((__unused__)),
379 ssize_t *poff __attribute__((__unused__)),
380 struct disk_info *info)
382 uint8_t *filebuf = NULL;
385 rc = read_sysfs_file(&filebuf,
386 "/sys/class/block/%s/device/uuid", pbuf);
387 if ((rc < 0 && errno == ENOENT) || filebuf == NULL)
390 rc = efi_str_to_guid((char *)filebuf, &info->nvdimm_label);
394 /* UUIDs are stored opposite Endian from GUIDs, so our normal GUID
395 * parser is giving us the wrong thing; swizzle those bytes around.
397 swizzle_guid_to_uuid(&info->nvdimm_label);
399 *off = efidp_make_nvdimm(buf, size, &info->nvdimm_label);
404 sysfs_parse_nvme(uint8_t *buf, ssize_t size, ssize_t *off,
405 const char *pbuf, ssize_t psize, ssize_t *poff,
406 struct disk_info *info)
410 uint8_t *filebuf = NULL;
417 newpbuf = strndupa(pbuf, psize+1);
420 newpbuf[psize] = '\0';
429 rc = sscanf(newpbuf, "nvme/nvme%d/nvme%dn%d%n", &tosser0,
430 &ctrl_id, &ns_id, &psz);
435 info->nvme_info.ctrl_id = ctrl_id;
436 info->nvme_info.ns_id = ns_id;
437 info->nvme_info.has_eui = 0;
438 info->interface_type = nvme;
441 * now fish the eui out of sysfs is there is one...
443 rc = read_sysfs_file(&filebuf,
444 "/sys/class/block/nvme%dn%d/eui",
446 if ((rc < 0 && errno == ENOENT) || filebuf == NULL) {
447 rc = read_sysfs_file(&filebuf,
448 "/sys/class/block/nvme%dn%d/device/eui",
451 if (rc >= 0 && filebuf != NULL) {
457 rc = sscanf((char *)filebuf,
458 "%02hhx %02hhx %02hhx %02hhx "
459 "%02hhx %02hhx %02hhx %02hhx",
460 &eui[0], &eui[1], &eui[2], &eui[3],
461 &eui[4], &eui[5], &eui[6], &eui[7]);
466 info->nvme_info.has_eui = 1;
467 memcpy(info->nvme_info.eui, eui, sizeof(eui));
470 *off = efidp_make_nvme(buf, size,
471 info->nvme_info.ns_id,
472 info->nvme_info.has_eui ? info->nvme_info.eui
479 sysfs_parse_sata(uint8_t *buf, ssize_t size, ssize_t *off,
480 const char *pbuf, ssize_t psize, ssize_t *poff,
481 struct disk_info *info)
492 uint32_t scsi_device;
493 uint32_t scsi_target;
498 newpbuf = strndupa(pbuf, psize+1);
501 newpbuf[psize] = '\0';
503 /* find the ata info:
504 * ata1/host0/target0:0:0/
507 rc = sscanf(newpbuf, "ata%d/host%d/target%d:%d:%d/%n",
508 &print_id, &scsi_bus, &scsi_device, &scsi_target, &scsi_lun,
514 /* find the emulated scsi bits (and ignore them)
517 uint32_t dummy0, dummy1, dummy2;
519 rc = sscanf(newpbuf+*poff, "%d:%d:%d:%"PRIu64"/%n", &dummy0, &dummy1,
520 &dummy2, &dummy3, &psz);
528 char *disk_name = NULL;
529 char *part_name = NULL;
531 rc = sscanf(newpbuf+*poff, "block/%m[^/]%n/%m[^/]%n", &disk_name, &psz,
534 rc = asprintf(&part_name, "%s%d", disk_name, info->part);
541 } else if (rc != 2) {
548 info->sata_info.scsi_bus = scsi_bus;
549 info->sata_info.scsi_device = scsi_device;
550 info->sata_info.scsi_target = scsi_target;
551 info->sata_info.scsi_lun = scsi_lun;
553 rc = sysfs_sata_get_port_info(print_id, info);
560 /* check the original of this; it's guaranteed in our copy */
561 if (pbuf[*poff] != '\0') {
568 info->disk_name = disk_name;
569 info->part_name = part_name;
570 if (info->interface_type == interface_type_unknown)
571 info->interface_type = sata;
573 if (info->interface_type == ata) {
574 *off = efidp_make_atapi(buf, size, info->sata_info.ata_port,
575 info->sata_info.ata_pmp,
576 info->sata_info.ata_devno);
578 *off = efidp_make_sata(buf, size, info->sata_info.ata_port,
579 info->sata_info.ata_pmp,
580 info->sata_info.ata_devno);
586 sysfs_parse_sas(uint8_t *buf, ssize_t size, ssize_t *off,
587 const char *pbuf, ssize_t psize, ssize_t *poff,
588 struct disk_info *info)
592 uint8_t *filebuf = NULL;
593 uint64_t sas_address;
597 newpbuf = strndupa(pbuf, psize+1);
600 newpbuf[psize] = '\0';
606 * host4/port-4:0/end_device-4:0/target4:0:0/4:0:0:0/block/sdc/sdc1
608 uint32_t tosser0, tosser1, tosser2;
610 /* ignore a bunch of stuff
612 * or host4/port-4:0:0
614 rc = sscanf(newpbuf+*poff, "host%d/port-%d:%d%n", &tosser0, &tosser1,
621 rc = sscanf(pbuf+*poff, ":%d%n", &tosser0, &psz);
622 if (rc != 0 && rc != 1)
628 * or /end_device-4:0:0
629 * awesomely these are the exact same fields that go into port-blah,
630 * but we don't care for now about any of them anyway.
632 rc = sscanf(newpbuf+*poff, "/end_device-%d:%d%n", &tosser0, &tosser1,
639 rc = sscanf(newpbuf+*poff, ":%d%n", &tosser0, &psz);
640 if (rc != 0 && rc != 1)
648 rc = sscanf(newpbuf+*poff, "/target%d:%d:%"PRIu64"/%n", &tosser0,
649 &tosser1, &tosser3, &psz);
657 rc = sscanf(newpbuf+*poff, "%d:%d:%d:%"PRIu64"/%n",
658 &info->sas_info.scsi_bus,
659 &info->sas_info.scsi_device,
660 &info->sas_info.scsi_target,
661 &info->sas_info.scsi_lun, &psz);
669 char *disk_name = NULL;
670 char *part_name = NULL;
671 rc = sscanf(newpbuf+*poff, "block/%m[^/]/%m[^/]%n", &disk_name,
677 /* check the original of this; it's guaranteed in our copy */
678 if (pbuf[*poff] != '\0') {
686 * we also need to get the actual sas_address from someplace...
688 rc = read_sysfs_file(&filebuf,
689 "/sys/class/block/%s/device/sas_address",
691 if (rc < 0 || filebuf == NULL)
694 rc = sscanf((char *)filebuf, "%"PRIx64, &sas_address);
698 info->sas_info.sas_address = sas_address;
699 info->disk_name = disk_name;
700 info->part_name = part_name;
701 info->interface_type = sas;
703 *off = efidp_make_sas(buf, size, sas_address);
708 make_pci_path(uint8_t *buf, ssize_t size, char *pathstr, ssize_t *pathoff)
715 if (pathstr == NULL || pathoff == NULL || pathstr[0] == '\0') {
722 uint16_t root_domain;
724 uint32_t acpi_hid = 0;
725 uint64_t acpi_uid_int = 0;
727 * find the pci root domain and port; they basically look like:
731 rc = sscanf(pathstr+poff, "pci%hx:%hhx/%n", &root_domain,
737 uint8_t *fbuf = NULL;
738 rc = read_sysfs_file(&fbuf,
739 "/sys/devices/pci%04hx:%02hhx/firmware_node/hid",
740 root_domain, root_bus);
741 if (rc < 0 || fbuf == NULL)
745 rc = sscanf((char *)fbuf, "PNP%hx", &tmp16);
748 acpi_hid = EFIDP_EFI_PNP_ID(tmp16);
750 /* Apparently basically nothing can look up a PcieRoot() node,
751 * because they just check _CID. So since _CID for the root pretty
752 * much always has to be PNP0A03 anyway, just use that no matter
755 if (acpi_hid == EFIDP_ACPI_PCIE_ROOT_HID)
756 acpi_hid = EFIDP_ACPI_PCI_ROOT_HID;
761 rc = read_sysfs_file(&fbuf,
762 "/sys/devices/pci%04hx:%02hhx/firmware_node/uid",
763 root_domain, root_bus);
764 if ((rc <= 0 && errno != ENOENT) || fbuf == NULL)
767 rc = sscanf((char *)fbuf, "%"PRIu64"\n", &acpi_uid_int);
769 /* kernel uses "%s\n" to print it, so there
770 * should always be some value and a newline... */
771 int l = strlen((char *)buf);
781 sz = efidp_make_acpi_hid_ex(buf+off, size?size-off:0,
782 acpi_hid, 0, 0, "", (char *)fbuf,
785 sz = efidp_make_acpi_hid(buf+off, size?size-off:0,
786 acpi_hid, acpi_uid_int);
792 /* find the pci domain/bus/device/function:
793 * 0000:00:01.0/0000:01:00.0/
794 * ^d ^b ^d ^f (of the last one in the series)
799 uint8_t bus, device, function;
800 rc = sscanf(pathstr+poff, "%hx:%hhx:%hhx.%hhx/%n",
801 &domain, &bus, &device, &function, &psz);
807 sz = efidp_make_pci(buf+off, size?size-off:0, device, function);
820 __attribute__((__visibility__ ("hidden")))
821 make_blockdev_path(uint8_t *buf, ssize_t size, struct disk_info *info)
823 char *linkbuf = NULL;
824 char *driverbuf = NULL;
825 ssize_t off=0, sz=0, loff=0;
830 rc = sysfs_readlink(&linkbuf, "/sys/dev/block/%"PRIu64":%u",
831 info->major, info->minor);
832 if (rc < 0 || !linkbuf) {
833 efi_error("couldn't read link for /sys/dev/block/%"PRIu64":%u",
834 info->major, info->minor);
839 * the sysfs path basically looks like one of:
840 * ../../devices/pci$PCI_STUFF/$BLOCKDEV_STUFF/block/$DISK/$PART
841 * ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.1/block/pmem12s
843 rc = sysfs_test_pmem(linkbuf+loff);
845 efi_error("sysfs_test_pmem(\"%s\") failed", linkbuf+loff);
849 info->interface_type = nd_pmem;
850 rc = sysfs_parse_pmem(buf+off, size?size-off:0, &sz,
851 linkbuf+loff, PATH_MAX-off,
861 rc = sscanf(linkbuf+loff, "../../devices/%n", &lsz);
863 efi_error("scanf(\"%s\", %s, &lz) failed",
864 linkbuf+loff, "../../devices/%n");
870 sz = make_pci_path(buf, size, linkbuf+loff, &tmplsz);
877 tmppath = strdupa(linkbuf);
880 tmppath[loff] = '\0';
881 rc = sysfs_readlink(&driverbuf, "/sys/dev/block/%s/driver",
883 if (rc < 0 || !driverbuf)
886 char *driver = strrchr(driverbuf, '/');
887 if (!driver || !*driver)
891 if (!strncmp(driver, "pata_", 5) ||
892 !(strcmp(driver, "ata_piix")))
893 info->interface_type = ata;
897 (info->interface_type == interface_type_unknown ||
898 info->interface_type == atapi ||
899 info->interface_type == usb ||
900 info->interface_type == i1394 ||
901 info->interface_type == fibre ||
902 info->interface_type == i2o ||
903 info->interface_type == md)) {
907 rc = sscanf(linkbuf+loff, "virtio%x/%n", &tosser, &tmpoff);
910 } else if (rc == 1) {
911 info->interface_type = virtblk;
917 /* /dev/nvme0n1 looks like:
918 * /sys/dev/block/259:0 -> ../../devices/pci0000:00/0000:00:1d.0/0000:05:00.0/nvme/nvme0/nvme0n1
921 rc = sysfs_test_nvme(linkbuf+loff, PATH_MAX-off);
926 rc = sysfs_parse_nvme(buf+off, size?size-off:0, &sz,
927 linkbuf+loff, PATH_MAX-off,
937 /* /dev/sda as SATA looks like:
938 * /sys/dev/block/8:0 -> ../../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda
941 rc = sysfs_test_sata(linkbuf+loff, PATH_MAX-off);
946 rc = sysfs_parse_sata(buf+off, size?size-off:0, &sz,
947 linkbuf+loff, PATH_MAX-off,
957 /* /dev/sdc as SAS looks like:
958 * /sys/dev/block/8:32 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/host4/port-4:0/end_device-4:0/target4:0:0/4:0:0:0/block/sdc
961 rc = sysfs_test_sas(linkbuf+loff, PATH_MAX-off);
966 rc = sysfs_parse_sas(buf+off, size?size-off:0, &sz,
967 linkbuf+loff, PATH_MAX-off,
977 if (!found && info->interface_type == scsi) {
980 rc = sysfs_readlink(&linkbuf, "/sys/class/block/%s/device",
982 if (rc < 0 || !linkbuf)
985 rc = sscanf(linkbuf, "../../../%d:%d:%d:%"PRIu64,
986 &info->scsi_info.scsi_bus,
987 &info->scsi_info.scsi_device,
988 &info->scsi_info.scsi_target,
989 &info->scsi_info.scsi_lun);
993 sz = efidp_make_scsi(buf+off, size?size-off:0,
994 info->scsi_info.scsi_target,
995 info->scsi_info.scsi_lun);
1011 __attribute__((__visibility__ ("hidden")))
1012 eb_disk_info_from_fd(int fd, struct disk_info *info)
1018 memset(info, 0, sizeof *info);
1020 info->pci_root.root_pci_domain = 0xffff;
1021 info->pci_root.root_pci_bus = 0xff;
1023 memset(&buf, 0, sizeof(struct stat));
1024 rc = fstat(fd, &buf);
1026 efi_error("fstat() failed: %m");
1029 if (S_ISBLK(buf.st_mode)) {
1030 info->major = major(buf.st_rdev);
1031 info->minor = minor(buf.st_rdev);
1032 } else if (S_ISREG(buf.st_mode)) {
1033 info->major = major(buf.st_dev);
1034 info->minor = minor(buf.st_dev);
1036 efi_error("Cannot stat non-block or non-regular file");
1040 /* IDE disks can have up to 64 partitions, or 6 bits worth,
1041 * and have one bit for the disk number.
1042 * This leaves an extra bit at the top.
1044 if (info->major == 3) {
1045 info->disknum = (info->minor >> 6) & 1;
1046 info->controllernum = (info->major - 3 + 0) + info->disknum;
1047 info->interface_type = ata;
1048 info->part = info->minor & 0x3F;
1050 } else if (info->major == 22) {
1051 info->disknum = (info->minor >> 6) & 1;
1052 info->controllernum = (info->major - 22 + 2) + info->disknum;
1053 info->interface_type = ata;
1054 info->part = info->minor & 0x3F;
1056 } else if (info->major >= 33 && info->major <= 34) {
1057 info->disknum = (info->minor >> 6) & 1;
1058 info->controllernum = (info->major - 33 + 4) + info->disknum;
1059 info->interface_type = ata;
1060 info->part = info->minor & 0x3F;
1062 } else if (info->major >= 56 && info->major <= 57) {
1063 info->disknum = (info->minor >> 6) & 1;
1064 info->controllernum = (info->major - 56 + 8) + info->disknum;
1065 info->interface_type = ata;
1066 info->part = info->minor & 0x3F;
1068 } else if (info->major >= 88 && info->major <= 91) {
1069 info->disknum = (info->minor >> 6) & 1;
1070 info->controllernum = (info->major - 88 + 12) + info->disknum;
1071 info->interface_type = ata;
1072 info->part = info->minor & 0x3F;
1076 /* I2O disks can have up to 16 partitions, or 4 bits worth. */
1077 if (info->major >= 80 && info->major <= 87) {
1078 info->interface_type = i2o;
1079 info->disknum = 16*(info->major-80) + (info->minor >> 4);
1080 info->part = (info->minor & 0xF);
1084 /* SCSI disks can have up to 16 partitions, or 4 bits worth
1085 * and have one bit for the disk number.
1087 if (info->major == 8) {
1088 info->interface_type = scsi;
1089 info->disknum = (info->minor >> 4);
1090 info->part = (info->minor & 0xF);
1092 } else if (info->major >= 65 && info->major <= 71) {
1093 info->interface_type = scsi;
1094 info->disknum = 16*(info->major-64) + (info->minor >> 4);
1095 info->part = (info->minor & 0xF);
1097 } else if (info->major >= 128 && info->major <= 135) {
1098 info->interface_type = scsi;
1099 info->disknum = 16*(info->major-128) + (info->minor >> 4);
1100 info->part = (info->minor & 0xF);
1104 rc = sysfs_readlink(&driver, "/sys/dev/block/%"PRIu64":%"PRIu32"/device/driver",
1105 info->major, info->minor);
1107 char *last = strrchr(driver, '/');
1109 if (!strcmp(last+1, "nd_pmem")) {
1110 info->interface_type = nd_pmem;
1113 } else if (!strcmp(last+1, "nd_blk")) {
1115 info->inteface_type = scsi;
1126 make_net_pci_path(uint8_t *buf, ssize_t size, const char * const ifname)
1128 char *linkbuf = NULL;
1129 ssize_t off=0, sz=0, loff=0;
1133 rc = sysfs_readlink(&linkbuf, "/sys/class/net/%s", ifname);
1134 if (rc < 0 || !linkbuf)
1138 * the sysfs path basically looks like:
1139 * ../../devices/$PCI_STUFF/net/$IFACE
1141 rc = sscanf(linkbuf, "../../devices/%n", &lsz);
1147 sz = make_pci_path(buf, size, linkbuf+loff, &tmplsz);
1157 __attribute__((__visibility__ ("hidden")))
1158 make_mac_path(uint8_t *buf, ssize_t size, const char * const ifname)
1161 struct ethtool_drvinfo drvinfo = { 0, };
1163 ssize_t ret = -1, sz, off=0;
1164 char busname[PATH_MAX+1] = "";
1166 memset(&ifr, 0, sizeof (ifr));
1167 strncpy(ifr.ifr_name, ifname, IF_NAMESIZE);
1168 ifr.ifr_name[IF_NAMESIZE-1] = '\0';
1169 drvinfo.cmd = ETHTOOL_GDRVINFO;
1170 ifr.ifr_data = (caddr_t)&drvinfo;
1172 fd = socket(AF_INET, SOCK_DGRAM, 0);
1176 rc = ioctl(fd, SIOCETHTOOL, &ifr);
1180 strncpy(busname, drvinfo.bus_info, PATH_MAX);
1182 rc = ioctl(fd, SIOCGIFHWADDR, &ifr);
1186 sz = make_net_pci_path(buf, size, ifname);
1191 sz = efidp_make_mac_addr(buf+off, size?size-off:0,
1192 ifr.ifr_ifru.ifru_hwaddr.sa_family,
1193 (uint8_t *)ifr.ifr_ifru.ifru_hwaddr.sa_data,
1194 sizeof(ifr.ifr_ifru.ifru_hwaddr.sa_data));