#include <errno.h>
#include <inttypes.h>
+#include <stdarg.h>
#include <stddef.h>
#include <efivar.h>
static ssize_t
_format_acpi_adr(char *buf, size_t size, const_efidp dp)
{
- ssize_t o = 0;
- o += format(buf, size, o, "AcpiAdr(");
- o += format_array(buf, size, o, "0x%"PRIx32,
- typeof(dp->acpi_adr.adr[0]),
- dp->acpi_adr.adr,
- (efidp_node_size(dp)-4)/sizeof (dp->acpi_adr.adr[0]));
- o += format(buf, size, o, ")");
- return o;
+ ssize_t off = 0;
+ format(buf, size, off, "AcpiAdr", "AcpiAdr(");
+ format_array(buf, size, off, "AcpiAdr", "0x%"PRIx32,
+ typeof(dp->acpi_adr.adr[0]), dp->acpi_adr.adr,
+ (efidp_node_size(dp)-4) / sizeof (dp->acpi_adr.adr[0]));
+ format(buf, size, off, "AcpiAdr", ")");
+ return off;
}
+
#define format_acpi_adr(buf, size, off, dp) \
_format_acpi_adr(((buf)+(off)), ((size)?((size)-(off)):0), (dp))
-
ssize_t
_format_acpi_dn(char *buf, size_t size, const_efidp dp)
{
const char *cidstr = NULL;
size_t cidlen = 0;
- if (dp->subtype == EFIDP_ACPI_ADR)
- return format_acpi_adr(buf, size, off, dp);
-
- if (dp->subtype != EFIDP_ACPI_HID_EX && dp->subtype != EFIDP_ACPI_HID) {
- off += format(buf, size, off, "AcpiPath(%d,", dp->subtype);
- off += format_hex(buf, size, off, (uint8_t *)dp+4,
- (efidp_node_size(dp)-4) / 2);
- off += format(buf, size, off, ")");
+ if (dp->subtype == EFIDP_ACPI_ADR) {
+ format_acpi_adr(buf, size, off, dp);
return off;
- }
-
- if (dp->subtype == EFIDP_ACPI_HID_EX) {
+ } else if (dp->subtype != EFIDP_ACPI_HID_EX &&
+ dp->subtype != EFIDP_ACPI_HID) {
+ format(buf, size, off, "AcpiPath", "AcpiPath(%d,", dp->subtype);
+ format_hex(buf, size, off, "AcpiPath", (uint8_t *)dp+4,
+ (efidp_node_size(dp)-4) / 2);
+ format(buf, size, off, "AcpiPath", ")");
+ return off;
+ } else if (dp->subtype == EFIDP_ACPI_HID_EX) {
ssize_t limit = efidp_node_size(dp)
- offsetof(efidp_acpi_hid_ex, hidstr);
if (uidstr) {
switch (dp->acpi_hid.hid) {
case EFIDP_ACPI_PCI_ROOT_HID:
- off += format(buf, size, off, "PciRoot(%s)",
- uidstr);
+ format(buf, size, off, "PciRoot",
+ "PciRoot(%s)", uidstr);
return off;
case EFIDP_ACPI_PCIE_ROOT_HID:
- off += format(buf, size, off, "PcieRoot(%s)",
- uidstr);
+ format(buf, size, off, "PcieRoot",
+ "PcieRoot(%s)", uidstr);
return off;
}
}
switch (dp->acpi_hid.hid) {
case EFIDP_ACPI_PCI_ROOT_HID:
- off += format(buf, size, off, "PciRoot(0x%"PRIx32")",
- dp->acpi_hid.uid);
- return off;
+ format(buf, size, off, "PciRoot", "PciRoot(0x%"PRIx32")",
+ dp->acpi_hid.uid);
+ break;
case EFIDP_ACPI_PCIE_ROOT_HID:
- off += format(buf, size, off, "PcieRoot(0x%"PRIx32")",
- dp->acpi_hid.uid);
- return off;
+ format(buf, size, off, "PcieRoot", "PcieRoot(0x%"PRIx32")",
+ dp->acpi_hid.uid);
+ break;
case EFIDP_ACPI_FLOPPY_HID:
- off += format(buf, size, off, "Floppy(0x%"PRIx32")",
- dp->acpi_hid.uid);
- return off;
+ format(buf, size, off, "Floppy", "Floppy(0x%"PRIx32")",
+ dp->acpi_hid.uid);
+ break;
case EFIDP_ACPI_KEYBOARD_HID:
- off += format(buf, size, off, "Keyboard(0x%"PRIx32")",
- dp->acpi_hid.uid);
- return off;
+ format(buf, size, off, "Keyboard", "Keyboard(0x%"PRIx32")",
+ dp->acpi_hid.uid);
+ break;
case EFIDP_ACPI_SERIAL_HID:
- off += format(buf, size, off, "Serial(0x%"PRIx32")",
- dp->acpi_hid.uid);
- return off;
+ format(buf, size, off, "Keyboard", "Serial(0x%"PRIx32")",
+ dp->acpi_hid.uid);
+ break;
default:
switch (dp->subtype) {
case EFIDP_ACPI_HID_EX:
if (!hidstr && !cidstr &&
(uidstr || dp->acpi_hid_ex.uid)){
- off += format(buf, size, off,
- "AcpiExp(0x%"PRIx32",0x%"PRIx32",",
- dp->acpi_hid_ex.hid,
- dp->acpi_hid_ex.cid);
- if (uidstr)
- off += format(buf, size, off, "%s)",
- uidstr);
- else
- off += format(buf, size, off,
- "0x%"PRIx32")",
- dp->acpi_hid.uid);
- return off;
+ format(buf, size, off, "AcpiExp",
+ "AcpiExp(0x%"PRIx32",0x%"PRIx32",",
+ dp->acpi_hid_ex.hid,
+ dp->acpi_hid_ex.cid);
+ if (uidstr) {
+ format(buf, size, off, "AcpiExp",
+ "%s)", uidstr);
+ } else {
+ format(buf, size, off, "AcpiExp",
+ "0x%"PRIx32")",
+ dp->acpi_hid.uid);
+ }
+ break;
}
- off += format(buf, size, off, "AcpiEx(");
- if (hidstr)
- off += format(buf, size, off, "%s,", hidstr);
- else
- off += format(buf, size, off, "0x%"PRIx32",",
+ format(buf, size, off, "AcpiEx", "AcpiEx(");
+ if (hidstr) {
+ format(buf, size, off, "AcpiEx", "%s,", hidstr);
+ } else {
+ format(buf, size, off, "AcpiEx", "0x%"PRIx32",",
dp->acpi_hid.hid);
- if (cidstr)
- off += format(buf, size, off, "%s,", cidstr);
- else
- off += format(buf, size, off, "0x%"PRIx32",",
- dp->acpi_hid_ex.cid);
-
- if (uidstr)
- off += format(buf, size, off, "%s)", uidstr);
- else
- off += format(buf, size, off, "0x%"PRIx32")",
- dp->acpi_hid.uid);
- return off;
+ }
+
+ if (cidstr) {
+ format(buf, size, off, "AcpiEx", "%s,", cidstr);
+ } else {
+ format(buf, size, off, "AcpiEx", "0x%"PRIx32",",
+ dp->acpi_hid_ex.cid);
+ }
+
+ if (uidstr) {
+ format(buf, size, off, "AcpiEx", "%s)", uidstr);
+ } else {
+ format(buf, size, off, "AcpiEx", "0x%"PRIx32")",
+ dp->acpi_hid.uid);
+ }
+ break;
case EFIDP_ACPI_HID:
- off += format(buf, size, off,
- "Acpi(0x%"PRIx32",0x%"PRIx32")",
- dp->acpi_hid.hid, dp->acpi_hid.uid);
- return off;
+ format(buf, size, off, "Acpi",
+ "Acpi(0x%"PRIx32",0x%"PRIx32")",
+ dp->acpi_hid.hid, dp->acpi_hid.uid);
+ break;
}
}
#include "dp.h"
ssize_t
-format_edd10_guid(char *buf, size_t size, const_efidp dp)
+format_edd10_guid(char *buf, size_t size, const char *dp_type, const_efidp dp)
{
ssize_t off = 0;
efidp_edd10 const *edd_dp = (efidp_edd10 *)dp;
- off = format(buf, size, off, "EDD10(0x%"PRIx32")",
- edd_dp->hardware_device);
+ format(buf, size, off, dp_type, "EDD10(0x%"PRIx32")",
+ edd_dp->hardware_device);
return off;
}
ssize_t off = 0;
switch (dp->subtype) {
case EFIDP_HW_PCI:
- off += format(buf, size, off, "Pci(0x%"PRIx32",0x%"PRIx32")",
- dp->pci.device, dp->pci.function);
+ format(buf, size, off, "Pci", "Pci(0x%"PRIx32",0x%"PRIx32")",
+ dp->pci.device, dp->pci.function);
break;
case EFIDP_HW_PCCARD:
- off += format(buf, size, off, "PcCard(0x%"PRIx32")",
- dp->pccard.function);
+ format(buf, size, off, "PcCard", "PcCard(0x%"PRIx32")",
+ dp->pccard.function);
break;
case EFIDP_HW_MMIO:
- off += format(buf, size, off,
- "MemoryMapped(%"PRIu32",0x%"PRIx64",0x%"PRIx64")",
- dp->mmio.memory_type, dp->mmio.starting_address,
- dp->mmio.ending_address);
+ format(buf, size, off, "MemoryMapped",
+ "MemoryMapped(%"PRIu32",0x%"PRIx64",0x%"PRIx64")",
+ dp->mmio.memory_type, dp->mmio.starting_address,
+ dp->mmio.ending_address);
break;
case EFIDP_HW_VENDOR:
if (!efi_guid_cmp(&dp->hw_vendor.vendor_guid, &edd10_guid)) {
- off += format_helper(format_edd10_guid, buf, size,
- off, dp);
+ format_helper(format_edd10_guid, buf, size, off,
+ "EDD 1.0", dp);
} else {
- off += format_vendor(buf, size, off, "VenHw", dp);
+ format_vendor(buf, size, off, "VenHw", dp);
}
break;
case EFIDP_HW_CONTROLLER:
- off += format(buf, size, off, "Ctrl(0x%"PRIx32")",
- dp->controller.controller);
+ format(buf, size, off, "Ctrl", "Ctrl(0x%"PRIx32")",
+ dp->controller.controller);
break;
case EFIDP_HW_BMC:
- off += format(buf, size, off, "BMC(%d,0x%"PRIx64")",
- dp->bmc.interface_type, dp->bmc.base_addr);
+ format(buf, size, off, "BMC", "BMC(%d,0x%"PRIx64")",
+ dp->bmc.interface_type, dp->bmc.base_addr);
break;
default:
- off += format(buf, size, off, "HardwarePath(%d,", dp->subtype);
- off += format_hex(buf, size, off, (uint8_t *)dp+4,
- efidp_node_size(dp)-4);
- off += format(buf,size,off,")");
+ format(buf, size, off, "Hardware",
+ "HardwarePath(%d,", dp->subtype);
+ format_hex(buf, size, off, "Hardware", (uint8_t *)dp+4,
+ efidp_node_size(dp)-4);
+ format(buf, size, off, "Hardware", ")");
break;
}
return off;
#include <errno.h>
#include <inttypes.h>
+#include <stdarg.h>
#include <stddef.h>
#include <efivar.h>
ssize_t off = 0;
switch (dp->subtype) {
case EFIDP_MEDIA_HD:
- off += format(buf, size, off, "HD(%d,",
- dp->hd.partition_number);
+ format(buf, size, off, "HD", "HD(%d,", dp->hd.partition_number);
switch (dp->hd.signature_type) {
case EFIDP_HD_SIGNATURE_MBR:
- off += format(buf, size, off,
- "MBR,0x%"PRIu32",0x%"PRIx64",0x%"PRIx64")",
- *(char *)dp->hd.signature,
- dp->hd.start, dp->hd.size);
+ format(buf, size, off, "HD",
+ "MBR,0x%"PRIu32",0x%"PRIx64",0x%"PRIx64")",
+ *(char *)dp->hd.signature,
+ dp->hd.start, dp->hd.size);
break;
case EFIDP_HD_SIGNATURE_GUID:
- off += format(buf, size, off, "GPT,");
- off += format_guid(buf, size, off,
- (efi_guid_t *)dp->hd.signature);
- off += format(buf, size, off,
- ",0x%"PRIx64",0x%"PRIx64")",
- dp->hd.start, dp->hd.size);
+ format(buf, size, off, "HD", "GPT,");
+ format_guid(buf, size, off, "HD",
+ (efi_guid_t *)dp->hd.signature);
+ format(buf, size, off, "HD",
+ ",0x%"PRIx64",0x%"PRIx64")",
+ dp->hd.start, dp->hd.size);
break;
default:
- off += format(buf, size, off, "%d,",
- dp->hd.signature_type);
- off += format_hex(buf, size, off,
- dp->hd.signature,
- sizeof(dp->hd.signature));
- off += format(buf, size, off,
- ",0x%"PRIx64",0x%"PRIx64")",
- dp->hd.start, dp->hd.size);
+ format(buf, size, off, "HD", "%d,",
+ dp->hd.signature_type);
+ format_hex(buf, size, off, "HD", dp->hd.signature,
+ sizeof(dp->hd.signature));
+ format(buf, size, off, "HD",
+ ",0x%"PRIx64",0x%"PRIx64")",
+ dp->hd.start, dp->hd.size);
break;
}
break;
case EFIDP_MEDIA_CDROM:
- off += format(buf, size, off,
- "CDROM(%d,0x%"PRIx64",0x%"PRIx64")",
- dp->cdrom.boot_catalog_entry,
- dp->cdrom.partition_rba, dp->cdrom.sectors);
+ format(buf, size, off, "CDROM",
+ "CDROM(%d,0x%"PRIx64",0x%"PRIx64")",
+ dp->cdrom.boot_catalog_entry,
+ dp->cdrom.partition_rba, dp->cdrom.sectors);
break;
case EFIDP_MEDIA_VENDOR:
- off += format_vendor(buf, size, off, "VenMedia", dp);
+ format_vendor(buf, size, off, "VenMedia", dp);
break;
case EFIDP_MEDIA_FILE:
- off += format(buf, size, off, "File(");
- off += format_ucs2(buf, size, off, dp->file.name,
- (efidp_node_size(dp)
- - offsetof(efidp_file, name)) / 2);
- off += format(buf, size, off, ")");
+ format(buf, size, off, "File", "File(");
+ format_ucs2(buf, size, off, "File", dp->file.name,
+ (efidp_node_size(dp)
+ - offsetof(efidp_file, name)) / 2);
+ format(buf, size, off, "File", ")");
break;
case EFIDP_MEDIA_PROTOCOL:
- off += format(buf, size, off, "Media(");
- off += format_guid(buf, size, off, &dp->protocol.protocol_guid);
- off += format(buf, size, off, ")");
+ format(buf, size, off, "Media", "Media(");
+ format_guid(buf, size, off, "Media",
+ &dp->protocol.protocol_guid);
+ format(buf, size, off, "Media", ")");
break;
case EFIDP_MEDIA_FIRMWARE_FILE:
- off += format(buf, size, off, "FvFile(");
- off += format_guid(buf, size, off, &dp->protocol.protocol_guid);
- off += format(buf, size, off, ")");
+ format(buf, size, off, "FvFile", "FvFile(");
+ format_guid(buf, size, off, "FvFile",
+ &dp->protocol.protocol_guid);
+ format(buf, size, off, "FvFile", ")");
break;
case EFIDP_MEDIA_FIRMWARE_VOLUME:
- off += format(buf, size, off, "FvVol(");
- off += format_guid(buf, size, off, &dp->protocol.protocol_guid);
- off += format(buf, size, off, ")");
+ format(buf, size, off, "FvVol", "FvVol(");
+ format_guid(buf, size, off, "FvVol",
+ &dp->protocol.protocol_guid);
+ format(buf, size, off, "FvVol", ")");
break;
case EFIDP_MEDIA_RELATIVE_OFFSET:
- off = format(buf, size, off, "Offset(0x%"PRIx64",0x%"PRIx64")",
- dp->relative_offset.first_byte,
- dp->relative_offset.last_byte);
+ format(buf, size, off, "Offset",
+ "Offset(0x%"PRIx64",0x%"PRIx64")",
+ dp->relative_offset.first_byte,
+ dp->relative_offset.last_byte);
break;
case EFIDP_MEDIA_RAMDISK: {
struct {
}
if (label) {
- off += format(buf, size, off,
- "%s(0x%"PRIx64",0x%"PRIx64",%d)", label,
- dp->ramdisk.start_addr,
- dp->ramdisk.end_addr,
- dp->ramdisk.instance_number);
+ format(buf, size, off, label,
+ "%s(0x%"PRIx64",0x%"PRIx64",%d)", label,
+ dp->ramdisk.start_addr,
+ dp->ramdisk.end_addr,
+ dp->ramdisk.instance_number);
break;
}
- off += format(buf, size, off,
- "Ramdisk(0x%"PRIx64",0x%"PRIx64",%d,",
- dp->ramdisk.start_addr, dp->ramdisk.end_addr,
- dp->ramdisk.instance_number);
- off += format_guid(buf, size, off, &dp->ramdisk.disk_type_guid);
- off += format(buf, size, off, ")");
+ format(buf, size, off, "Ramdisk",
+ "Ramdisk(0x%"PRIx64",0x%"PRIx64",%d,",
+ dp->ramdisk.start_addr, dp->ramdisk.end_addr,
+ dp->ramdisk.instance_number);
+ format_guid(buf, size, off, "Ramdisk",
+ &dp->ramdisk.disk_type_guid);
+ format(buf, size, off, "Ramdisk", ")");
break;
}
default:
- off += format(buf, size, off, "MediaPath(%d,", dp->subtype);
- off += format_hex(buf, size, off,
- (uint8_t *)dp+4,
- (efidp_node_size(dp)-4) / 2);
- off += format(buf,size,off,")");
+ format(buf, size, off, "Media", "MediaPath(%d,", dp->subtype);
+ format_hex(buf, size, off, "Media", (uint8_t *)dp+4,
+ (efidp_node_size(dp)-4) / 2);
+ format(buf,size,off, "Media",")");
break;
}
return off;
{
uint16_t *ip = (uint16_t *)ipaddr;
ssize_t off = 0;
- ssize_t sz;
- sz = format(buf, size, off, "[");
- if (sz < 0)
- return -1;
- off += sz;
+ format(buf, size, off, "IPv6", "[");
// deciding how to print an ipv6 ip requires 2 passes, because
// RFC5952 says we have to use :: a) only once and b) to maximum effect.
for (i = 0; i < 8; i++) {
if (largest_zero_block_offset == i) {
- sz = format(buf, size, off, "::");
- if (sz < 0)
- return sz;
- off += sz;
+ format(buf, size, off, "IPv6", "::");
i += largest_zero_block_size -1;
continue;
} else if (i > 0) {
- sz = format(buf, size, off, ":");
- if (sz < 0)
- return -1;
- off += sz;
+ format(buf, size, off, "IPv6", ":");
}
- sz = format(buf, size, off, "%x", ip[i]);
- if (sz < 0)
- return -1;
- off += sz;
+ format(buf, size, off, "IPv6", "%x", ip[i]);
}
- sz = format(buf, size, off, "]:%d", port);
- if (sz < 0)
- return -1;
- off += sz;
+ format(buf, size, off, "IPv6", "]:%d", port);
return off;
}
format_helper(format_ipv6_port_helper, buf, size, off, ipaddr, port)
static ssize_t
-format_uart(char *buf, size_t size, const_efidp dp)
+format_uart(char *buf, size_t size,
+ const char *dp_type __attribute__((__unused__)),
+ const_efidp dp)
{
uint32_t value;
ssize_t off = 0;
value = dp->uart_flow_control.flow_control_map;
if (value > 2) {
- return format(buf, size, off, "UartFlowcontrol(%d)", value);
+ format(buf, size, off, "UartFlowControl",
+ "UartFlowControl(%d)", value);
+ return off;
}
- return format(buf, size, off, "UartFlowControl(%s)", labels[value]);
+ format(buf, size, off, "UartFlowControl", "UartFlowControl(%s)",
+ labels[value]);
+ return off;
}
static ssize_t
-format_sas(char *buf, size_t size, const_efidp dp)
+format_sas(char *buf, size_t size,
+ const char *dp_type __attribute__((__unused__)),
+ const_efidp dp)
{
ssize_t off = 0;
const efidp_sas * const s = &dp->sas;
drive_bay = s->drive_bay_id + 1;
}
- off += format(buf, size, off, "SAS(%"PRIx64",%"PRIx64",%"PRIx16",%s",
- dp->subtype == EFIDP_MSG_SAS_EX ?
+ format(buf, size, off, "SAS", "SAS(%"PRIx64",%"PRIx64",%"PRIx16",%s",
+ dp->subtype == EFIDP_MSG_SAS_EX ?
be64_to_cpu(s->sas_address) :
le64_to_cpu(s->sas_address),
- dp->subtype == EFIDP_MSG_SAS_EX ?
+ dp->subtype == EFIDP_MSG_SAS_EX ?
be64_to_cpu(s->lun) :
le64_to_cpu(s->lun),
- s->rtp, sassata_label[sassata]);
+ s->rtp, sassata_label[sassata]);
- if (more_info)
- off += format(buf, size, off, ",%s,%s",
- location_label[location], connect_label[connect]);
+ if (more_info) {
+ format(buf, size, off, "SAS", ",%s,%s",
+ location_label[location], connect_label[connect]);
+ }
- if (more_info == 2 && drive_bay >= 0)
- off += format(buf, size, off, ",%d", drive_bay);
+ if (more_info == 2 && drive_bay >= 0) {
+ format(buf, size, off, "SAS", ",%d", drive_bay);
+ }
- off += format(buf, size, off, ")");
+ format(buf, size, off, "SAS", ")");
return off;
}
-#define class_helper(buf, size, off, label, dp) ({ \
- off += format(buf, size, off, \
- "%s(0x%"PRIx16",0x%"PRIx16",%d,%d)", \
- label, \
- dp->usb_class.vendor_id, \
- dp->usb_class.product_id, \
- dp->usb_class.device_subclass, \
- dp->usb_class.device_protocol); \
- off; \
- })
+#define class_helper(buf, size, off, label, dp) \
+ format(buf, size, off, label, \
+ "%s(0x%"PRIx16",0x%"PRIx16",%d,%d)", \
+ label, \
+ dp->usb_class.vendor_id, \
+ dp->usb_class.product_id, \
+ dp->usb_class.device_subclass, \
+ dp->usb_class.device_protocol)
static ssize_t
-format_usb_class(char *buf, size_t size, const_efidp dp)
+format_usb_class(char *buf, size_t size,
+ const char *dp_type __attribute__((__unused__)),
+ const_efidp dp)
{
ssize_t off = 0;
switch (dp->usb_class.device_class) {
case EFIDP_USB_CLASS_AUDIO:
- off += class_helper(buf, size, off, "UsbAudio", dp);
+ class_helper(buf, size, off, "UsbAudio", dp);
break;
case EFIDP_USB_CLASS_CDC_CONTROL:
- off += class_helper(buf, size, off, "UsbCDCControl", dp);
+ class_helper(buf, size, off, "UsbCDCControl", dp);
break;
case EFIDP_USB_CLASS_HID:
- off += class_helper(buf, size, off, "UsbHID", dp);
+ class_helper(buf, size, off, "UsbHID", dp);
break;
case EFIDP_USB_CLASS_IMAGE:
- off += class_helper(buf, size, off, "UsbImage", dp);
+ class_helper(buf, size, off, "UsbImage", dp);
break;
case EFIDP_USB_CLASS_PRINTER:
- off += class_helper(buf, size, off, "UsbPrinter", dp);
+ class_helper(buf, size, off, "UsbPrinter", dp);
break;
case EFIDP_USB_CLASS_MASS_STORAGE:
- off += class_helper(buf, size, off, "UsbMassStorage", dp);
+ class_helper(buf, size, off, "UsbMassStorage", dp);
break;
case EFIDP_USB_CLASS_HUB:
- off += class_helper(buf, size, off, "UsbHub", dp);
+ class_helper(buf, size, off, "UsbHub", dp);
break;
case EFIDP_USB_CLASS_CDC_DATA:
- off += class_helper(buf, size, off, "UsbCDCData", dp);
+ class_helper(buf, size, off, "UsbCDCData", dp);
break;
case EFIDP_USB_CLASS_SMARTCARD:
- off += class_helper(buf, size, off, "UsbSmartCard", dp);
+ class_helper(buf, size, off, "UsbSmartCard", dp);
break;
case EFIDP_USB_CLASS_VIDEO:
- off += class_helper(buf, size, off, "UsbVideo", dp);
+ class_helper(buf, size, off, "UsbVideo", dp);
break;
case EFIDP_USB_CLASS_DIAGNOSTIC:
- off += class_helper(buf, size, off, "UsbDiagnostic", dp);
+ class_helper(buf, size, off, "UsbDiagnostic", dp);
break;
case EFIDP_USB_CLASS_WIRELESS:
- off += class_helper(buf, size, off, "UsbWireless", dp);
+ class_helper(buf, size, off, "UsbWireless", dp);
break;
case EFIDP_USB_CLASS_254:
switch (dp->usb_class.device_subclass) {
case EFIDP_USB_SUBCLASS_FW_UPDATE:
- off += format(buf, size, off,
- "UsbDeviceFirmwareUpdate(0x%"PRIx16",0x%"PRIx16",%d)",
- dp->usb_class.vendor_id,
- dp->usb_class.product_id,
- dp->usb_class.device_protocol);
+ format(buf, size, off, "UsbDeviceFirmwareUpdate",
+ "UsbDeviceFirmwareUpdate(0x%"PRIx16",0x%"PRIx16",%d)",
+ dp->usb_class.vendor_id,
+ dp->usb_class.product_id,
+ dp->usb_class.device_protocol);
break;
case EFIDP_USB_SUBCLASS_IRDA_BRIDGE:
- off += format(buf, size, off,
- "UsbIrdaBridge(0x%"PRIx16",0x%"PRIx16",%d)",
- dp->usb_class.vendor_id,
- dp->usb_class.product_id,
- dp->usb_class.device_protocol);
+ format(buf, size, off, "UsbIrdaBridge",
+ "UsbIrdaBridge(0x%"PRIx16",0x%"PRIx16",%d)",
+ dp->usb_class.vendor_id,
+ dp->usb_class.product_id,
+ dp->usb_class.device_protocol);
break;
case EFIDP_USB_SUBCLASS_TEST_AND_MEASURE:
- off += format(buf, size, off,
- "UsbTestAndMeasurement(0x%"PRIx16",0x%"PRIx16",%d)",
- dp->usb_class.vendor_id,
- dp->usb_class.product_id,
- dp->usb_class.device_protocol);
+ format(buf, size, off, "UsbTestAndMeasurement",
+ "UsbTestAndMeasurement(0x%"PRIx16",0x%"PRIx16",%d)",
+ dp->usb_class.vendor_id,
+ dp->usb_class.product_id,
+ dp->usb_class.device_protocol);
break;
}
break;
default:
- off += format(buf, size, off,
- "UsbClass(%"PRIx16",%"PRIx16",%d,%d)",
- dp->usb_class.vendor_id,
- dp->usb_class.product_id,
- dp->usb_class.device_subclass,
- dp->usb_class.device_protocol);
+ format(buf, size, off, "UsbClass",
+ "UsbClass(%"PRIx16",%"PRIx16",%d,%d)",
+ dp->usb_class.vendor_id,
+ dp->usb_class.product_id,
+ dp->usb_class.device_subclass,
+ dp->usb_class.device_protocol);
break;
}
return off;
_format_message_dn(char *buf, size_t size, const_efidp dp)
{
ssize_t off = 0;
- ssize_t sz;
switch (dp->subtype) {
case EFIDP_MSG_ATAPI:
- off += format(buf, size, off, "Ata(%d,%d,%d)",
+ format(buf, size, off, "Ata", "Ata(%d,%d,%d)",
dp->atapi.primary, dp->atapi.slave,
dp->atapi.lun);
break;
case EFIDP_MSG_SCSI:
- off += format(buf, size, off, "SCSI(%d,%d)",
+ format(buf, size, off, "SCSI", "SCSI(%d,%d)",
dp->scsi.target, dp->scsi.lun);
break;
case EFIDP_MSG_FIBRECHANNEL:
- off += format(buf, size, off, "Fibre(%"PRIx64",%"PRIx64")",
+ format(buf, size, off, "Fibre", "Fibre(%"PRIx64",%"PRIx64")",
le64_to_cpu(dp->fc.wwn),
le64_to_cpu(dp->fc.lun));
break;
case EFIDP_MSG_FIBRECHANNELEX:
- off += format(buf, size, off, "Fibre(%"PRIx64",%"PRIx64")",
+ format(buf, size, off, "Fibre", "Fibre(%"PRIx64",%"PRIx64")",
be64_to_cpu(dp->fc.wwn),
be64_to_cpu(dp->fc.lun));
break;
case EFIDP_MSG_1394:
- off += format(buf, size, off, "I1394(0x%"PRIx64")",
+ format(buf, size, off, "I1394", "I1394(0x%"PRIx64")",
dp->firewire.guid);
break;
case EFIDP_MSG_USB:
- off += format(buf, size, off, "USB(%d,%d)",
+ format(buf, size, off, "USB", "USB(%d,%d)",
dp->usb.parent_port, dp->usb.interface);
break;
case EFIDP_MSG_I2O:
- off += format(buf, size, off, "I2O(%d)", dp->i2o.target);
+ format(buf, size, off, "I2O", "I2O(%d)", dp->i2o.target);
break;
case EFIDP_MSG_INFINIBAND:
if (dp->infiniband.resource_flags &
EFIDP_INFINIBAND_RESOURCE_IOC_SERVICE) {
- off += format(buf, size, off,
- "Infiniband(%08x,%"PRIx64"%"PRIx64",%"PRIx64",%"PRIu64",%"PRIu64")",
- dp->infiniband.resource_flags,
- dp->infiniband.port_gid[1],
- dp->infiniband.port_gid[0],
- dp->infiniband.service_id,
- dp->infiniband.target_port_id,
- dp->infiniband.device_id);
+ format(buf, size, off, "Infiniband",
+ "Infiniband(%08x,%"PRIx64"%"PRIx64",%"PRIx64",%"PRIu64",%"PRIu64")",
+ dp->infiniband.resource_flags,
+ dp->infiniband.port_gid[1],
+ dp->infiniband.port_gid[0],
+ dp->infiniband.service_id,
+ dp->infiniband.target_port_id,
+ dp->infiniband.device_id);
} else {
- off += format(buf, size, off,
- "Infiniband(%08x,%"PRIx64"%"PRIx64",",
- dp->infiniband.resource_flags,
- dp->infiniband.port_gid[1],
- dp->infiniband.port_gid[0]);
- off += format_guid(buf, size, off, (efi_guid_t *)
- &dp->infiniband.ioc_guid);
- off += format(buf, size, off, ",%"PRIu64",%"PRIu64")",
- dp->infiniband.target_port_id,
- dp->infiniband.device_id);
+ format(buf, size, off, "Infiniband",
+ "Infiniband(%08x,%"PRIx64"%"PRIx64",",
+ dp->infiniband.resource_flags,
+ dp->infiniband.port_gid[1],
+ dp->infiniband.port_gid[0]);
+ format_guid(buf, size, off, "Infiniband",
+ (efi_guid_t *)&dp->infiniband.ioc_guid);
+ format(buf, size, off, "Infiniband",
+ ",%"PRIu64",%"PRIu64")",
+ dp->infiniband.target_port_id,
+ dp->infiniband.device_id);
}
break;
case EFIDP_MSG_MAC_ADDR:
- off += format(buf, size, off, "MAC(");
- off += format_hex(buf, size, off, dp->mac_addr.mac_addr,
+ format(buf, size, off, "MAC", "MAC(");
+ format_hex(buf, size, off, "MAC", dp->mac_addr.mac_addr,
dp->mac_addr.if_type < 2 ? 6
: sizeof(dp->mac_addr.mac_addr));
- off += format(buf, size, off, ",%d)", dp->mac_addr.if_type);
+ format(buf, size, off, "MAC", ",%d)", dp->mac_addr.if_type);
break;
case EFIDP_MSG_IPv4: {
efidp_ipv4_addr const *a = &dp->ipv4_addr;
- off += format(buf, size, off,
- "IPv4(%hhu.%hhu.%hhu.%hhu:%hu<->%hhu.%hhu.%hhu.%hhu:%hu,%hx,%hhx)",
- a->local_ipv4_addr[0], a->local_ipv4_addr[1],
- a->local_ipv4_addr[2], a->local_ipv4_addr[3],
- a->local_port, a->remote_ipv4_addr[0],
- a->remote_ipv4_addr[1], a->remote_ipv4_addr[2],
- a->remote_ipv4_addr[3], a->remote_port,
- a->protocol, a->static_ip_addr);
+ format(buf, size, off, "IPv4",
+ "IPv4(%hhu.%hhu.%hhu.%hhu:%hu<->%hhu.%hhu.%hhu.%hhu:%hu,%hx,%hhx)",
+ a->local_ipv4_addr[0], a->local_ipv4_addr[1],
+ a->local_ipv4_addr[2], a->local_ipv4_addr[3],
+ a->local_port, a->remote_ipv4_addr[0],
+ a->remote_ipv4_addr[1], a->remote_ipv4_addr[2],
+ a->remote_ipv4_addr[3], a->remote_port,
+ a->protocol, a->static_ip_addr);
break;
}
case EFIDP_MSG_VENDOR: {
efi_guid_t guid;
char label[40];
ssize_t (*formatter)(char *buf, size_t size,
- const_efidp dp);
+ const char *dp_type __attribute__((__unused__)),
+ const_efidp dp);
} subtypes[] = {
{ .guid = EFIDP_PC_ANSI_GUID,
.label = "VenPcAnsi" },
};
char *label = NULL;
ssize_t (*formatter)(char *buf, size_t size,
- const_efidp dp) = NULL;
+ const char *dp_type __attribute__((__unused__)),
+ const_efidp dp) = NULL;
for (int i = 0; !efi_guid_is_zero(&subtypes[i].guid); i++) {
if (efi_guid_cmp(&subtypes[i].guid,
}
if (!label && !formatter) {
- off += format_vendor(buf, size, off, "VenMsg", dp);
+ format_vendor(buf, size, off, "VenMsg", dp);
break;
- } else if (formatter) {
- off += format_helper(formatter, buf, size, off, dp);
+ } else if (!label && formatter) {
+ format_helper(formatter, buf, size, off, "VenMsg", dp);
break;
}
- off += format(buf, size, off, "%s(", label);
+ format(buf, size, off, label, "%s(", label);
if (efidp_node_size(dp) >
(ssize_t)(sizeof (efidp_header)
+ sizeof (efi_guid_t))) {
- off += format_hex(buf, size, off,
+ format_hex(buf, size, off, label,
dp->msg_vendor.vendor_data,
efidp_node_size(dp)
- sizeof (efidp_header)
- sizeof (efi_guid_t));
}
- off += format(buf, size, off, ")");
+ format(buf, size, off, label, ")");
break;
}
case EFIDP_MSG_IPv6: {
efidp_ipv6_addr const *a = &dp->ipv6_addr;
char *addr0 = NULL;
char *addr1 = NULL;
+ ssize_t tmpoff = 0;
+ ssize_t sz;
- sz = format_ipv6_port(addr0, 0, 0, a->local_ipv6_addr,
+ sz = format_ipv6_port(addr0, 0, tmpoff, a->local_ipv6_addr,
a->local_port);
- if (sz < 0)
- return sz;
addr0 = alloca(sz+1);
- sz = format_ipv6_port(addr0, sz, 0, a->local_ipv6_addr,
+ tmpoff = 0;
+ format_ipv6_port(addr0, sz, tmpoff, a->local_ipv6_addr,
a->local_port);
- if (sz < 0)
- return sz;
- sz = format_ipv6_port(addr1, 0, 0, a->remote_ipv6_addr,
+ tmpoff = 0;
+ sz = format_ipv6_port(addr1, 0, tmpoff, a->remote_ipv6_addr,
a->remote_port);
- if (sz < 0)
- return sz;
addr1 = alloca(sz+1);
- sz = format_ipv6_port(addr1, sz, 0, a->remote_ipv6_addr,
+ tmpoff = 0;
+ format_ipv6_port(addr1, sz, tmpoff, a->remote_ipv6_addr,
a->remote_port);
- if (sz < 0)
- return sz;
- off += format(buf, size, off, "IPv6(%s<->%s,%hx,%hhx)",
+ format(buf, size, off, "IPv6", "IPv6(%s<->%s,%hx,%hhx)",
addr0, addr1, a->protocol, a->ip_addr_origin);
break;
}
int stop_bits = dp->uart.stop_bits;
char *sb_label[] = {"D", "1", "1.5", "2"};
- off += format(buf, size, off, "Uart(%"PRIu64",%d,",
- dp->uart.baud_rate ? dp->uart.baud_rate : 115200,
- dp->uart.data_bits ? dp->uart.data_bits : 8);
- off += format(buf, size, off,
- parity > 5 ? "%d," : "%c,",
- parity > 5 ? parity : parity_label[parity]);
+ format(buf, size, off, "Uart", "Uart(%"PRIu64",%d,",
+ dp->uart.baud_rate ? dp->uart.baud_rate : 115200,
+ dp->uart.data_bits ? dp->uart.data_bits : 8);
+ format(buf, size, off, "Uart",
+ parity > 5 ? "%d," : "%c,",
+ parity > 5 ? parity : parity_label[parity]);
if (stop_bits > 3)
- off += format(buf, size, off, "%d)", stop_bits);
+ format(buf, size, off, "Uart", "%d)", stop_bits);
else
- off += format(buf, size, off, "%s)",
- sb_label[stop_bits]);
+ format(buf, size, off, "Uart", "%s)",
+ sb_label[stop_bits]);
break;
}
case EFIDP_MSG_USB_CLASS:
- off += format_helper(format_usb_class, buf, size, off, dp);
+ format_helper(format_usb_class, buf, size, off, "UsbClass", dp);
break;
case EFIDP_MSG_USB_WWID:
- off += format(buf, size, off,
- "UsbWwid(%"PRIx16",%"PRIx16",%d,",
- dp->usb_wwid.vendor_id, dp->usb_wwid.product_id,
- dp->usb_wwid.interface);
- off += format_ucs2(buf, size, off, dp->usb_wwid.serial_number,
- (efidp_node_size(dp)
- - offsetof(efidp_usb_wwid, serial_number))
- / 2 + 1);
- off += format(buf, size, off, ")");
+ format(buf, size, off, "UsbWwid",
+ "UsbWwid(%"PRIx16",%"PRIx16",%d,",
+ dp->usb_wwid.vendor_id, dp->usb_wwid.product_id,
+ dp->usb_wwid.interface);
+ format_ucs2(buf, size, off, "UsbWwid",
+ dp->usb_wwid.serial_number,
+ (efidp_node_size(dp)
+ - offsetof(efidp_usb_wwid, serial_number)
+ ) / 2 + 1);
+ format(buf, size, off, "UsbWwid", ")");
break;
case EFIDP_MSG_LUN:
- off += format(buf, size, off, "Unit(%d)", dp->lun.lun);
+ format(buf, size, off, "Unit", "Unit(%d)", dp->lun.lun);
break;
case EFIDP_MSG_SATA:
- off += format(buf, size, off, "Sata(%d,%d,%d)",
- dp->sata.hba_port, dp->sata.port_multiplier_port,
- dp->sata.lun);
+ format(buf, size, off, "Sata", "Sata(%d,%d,%d)",
+ dp->sata.hba_port, dp->sata.port_multiplier_port,
+ dp->sata.lun);
break;
case EFIDP_MSG_ISCSI: {
ssize_t sz = efidp_node_size(dp)
memcpy(&lun, dp->iscsi.lun, sizeof (lun));
- off += format(buf, size, off,
+ format(buf, size, off, "iSCSI",
"iSCSI(%s,%d,0x%"PRIx64",%s,%s,%s,%s)",
target_name, dp->iscsi.tpgt,
be64_to_cpu(lun),
break;
}
case EFIDP_MSG_VLAN:
- off += format(buf, size, off, "Vlan(%d)", dp->vlan.vlan_id);
+ format(buf, size, off, "Vlan", "Vlan(%d)", dp->vlan.vlan_id);
break;
case EFIDP_MSG_SAS_EX:
- off += format_sas(buf, size, dp);
+ format_sas(buf, size, NULL, dp);
break;
case EFIDP_MSG_NVME:
- off += format(buf, size, off, "NVMe(0x%"PRIx32","
- "%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X)",
- dp->nvme.namespace_id, dp->nvme.ieee_eui_64[0],
- dp->nvme.ieee_eui_64[1], dp->nvme.ieee_eui_64[2],
- dp->nvme.ieee_eui_64[3], dp->nvme.ieee_eui_64[4],
- dp->nvme.ieee_eui_64[5], dp->nvme.ieee_eui_64[6],
- dp->nvme.ieee_eui_64[7]);
+ format(buf, size, off, "NVMe", "NVMe(0x%"PRIx32","
+ "%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X)",
+ dp->nvme.namespace_id, dp->nvme.ieee_eui_64[0],
+ dp->nvme.ieee_eui_64[1], dp->nvme.ieee_eui_64[2],
+ dp->nvme.ieee_eui_64[3], dp->nvme.ieee_eui_64[4],
+ dp->nvme.ieee_eui_64[5], dp->nvme.ieee_eui_64[6],
+ dp->nvme.ieee_eui_64[7]);
break;
case EFIDP_MSG_URI: {
ssize_t sz = efidp_node_size(dp) - offsetof(efidp_uri, uri);
char uri[sz + 1];
memcpy(uri, dp->uri.uri, sz);
uri[sz] = '\0';
- off += format(buf, size, off, "Uri(%s)", uri);
+ format(buf, size, off, "Uri", "Uri(%s)", uri);
break;
}
case EFIDP_MSG_UFS:
- off += format(buf, size, off, "UFS(%d,0x%02x)",
- dp->ufs.target_id, dp->ufs.lun);
+ format(buf, size, off, "UFS", "UFS(%d,0x%02x)",
+ dp->ufs.target_id, dp->ufs.lun);
break;
case EFIDP_MSG_SD:
- off += format(buf, size, off, "SD(%d)", dp->sd.slot_number);
+ format(buf, size, off, "SD", "SD(%d)", dp->sd.slot_number);
break;
default:
- off += format(buf, size, off, "Msg(%d,", dp->subtype);
- off += format_hex(buf, size, off, (uint8_t *)dp+4,
- efidp_node_size(dp)-4);
- off += format(buf,size,off,")");
+ format(buf, size, off, "Msg", "Msg(%d,", dp->subtype);
+ format_hex(buf, size, off, "Msg", (uint8_t *)dp+4,
+ efidp_node_size(dp)-4);
+ format(buf, size, off, "Msg", ")");
break;
}
return off;
__attribute__((__visibility__ ("default")))
efidp_format_device_path(char *buf, size_t size, const_efidp dp, ssize_t limit)
{
- ssize_t sz;
ssize_t off = 0;
int first = 1;
first = 0;
} else {
if (dp->type == EFIDP_END_TYPE) {
- if (dp->type == EFIDP_END_INSTANCE)
- off += format(buf, size, off, ",");
- else
+ if (dp->type == EFIDP_END_INSTANCE) {
+ format(buf, size, off, "\b", ",");
+ } else {
return off+1;
+ }
} else {
- off += format(buf, size, off, "/");
+ format(buf, size, off, "\b", "/");
}
}
switch (dp->type) {
case EFIDP_HARDWARE_TYPE:
- sz = format_hw_dn(buf, size, off, dp);
- if (sz < 0)
- return -1;
- off += sz;
+ format_hw_dn(buf, size, off, dp);
break;
case EFIDP_ACPI_TYPE:
- sz = format_acpi_dn(buf, size, off, dp);
- if (sz < 0)
- return -1;
- off += sz;
+ format_acpi_dn(buf, size, off, dp);
break;
case EFIDP_MESSAGE_TYPE:
- sz = format_message_dn(buf, size, off, dp);
- if (sz < 0)
- return -1;
- off += sz;
+ format_message_dn(buf, size, off, dp);
break;
case EFIDP_MEDIA_TYPE:
- sz = format_media_dn(buf, size, off, dp);
- if (sz < 0)
- return -1;
- off += sz;
+ format_media_dn(buf, size, off, dp);
break;
case EFIDP_BIOS_BOOT_TYPE: {
char *types[] = {"", "Floppy", "HD", "CDROM", "PCMCIA",
"USB", "Network", "" };
if (dp->subtype != EFIDP_BIOS_BOOT) {
- off += format(buf, size, off, "BbsPath(%d,",
- dp->subtype);
- off += format_hex(buf, size, off,
- (uint8_t *)dp+4,
- efidp_node_size(dp)-4);
- off += format(buf,size,off,")");
+ format(buf, size, off, "BbsPath",
+ "BbsPath(%d,", dp->subtype);
+ format_hex(buf, size, off, "BbsPath",
+ (uint8_t *)dp+4,
+ efidp_node_size(dp)-4);
+ format(buf, size, off, "BbsPath", ")");
break;
}
if (dp->bios_boot.device_type > 0 &&
dp->bios_boot.device_type < 7) {
- off += format(buf, size, off,
- "BBS(%s,%s,0x%"PRIx32")",
- types[dp->bios_boot.device_type],
- dp->bios_boot.description,
- dp->bios_boot.status);
+ format(buf, size, off, "BBS",
+ "BBS(%s,%s,0x%"PRIx32")",
+ types[dp->bios_boot.device_type],
+ dp->bios_boot.description,
+ dp->bios_boot.status);
} else {
- off += format(buf, size, off,
- "BBS(%d,%s,0x%"PRIx32")",
- dp->bios_boot.device_type,
- dp->bios_boot.description,
- dp->bios_boot.status);
+ format(buf, size, off, "BBS",
+ "BBS(%d,%s,0x%"PRIx32")",
+ dp->bios_boot.device_type,
+ dp->bios_boot.description,
+ dp->bios_boot.status);
}
break;
}
case EFIDP_END_TYPE:
if (dp->subtype == EFIDP_END_INSTANCE) {
- off += format(buf, size, off, ",");
+ format(buf, size, off, "End", ",");
break;
}
break;
default:
- off += format(buf, size, off, "Path(%d,%d,", dp->type,
- dp->subtype);
- off += format_hex(buf, size, off,
- (uint8_t *)dp + 4,
- efidp_node_size(dp) - 4);
- off += format(buf, size, off, ")");
+ format(buf, size, off, "Path",
+ "Path(%d,%d,", dp->type, dp->subtype);
+ format_hex(buf, size, off, "Path", (uint8_t *)dp + 4,
+ efidp_node_size(dp) - 4);
+ format(buf, size, off, "Path", ")");
break;
}
#include "ucs2.h"
-#define format(buf, size, off, fmt, args...) ({ \
- ssize_t _x; \
- _x = snprintf(((buf)+(off)), \
+#define format(buf, size, off, fmt, args...) ({ \
+ ssize_t _x = 0; \
+ if ((off) >= 0) { \
+ _x = snprintf(((buf)+(off)), \
((size)?((size)-(off)):0), \
fmt, ## args); \
- if (_x < 0) \
- return _x; \
- _x; \
+ if (_x < 0) \
+ return _x; \
+ (off) += _x; \
+ } \
+ off; \
})
-#define format_helper(fn, buf, size, off, args...) ({ \
+#define format_helper(fn, buf, size, off, args...) ({ \
ssize_t _x; \
_x = (fn)(((buf)+(off)), \
- ((size)?((size)-(off)):0), \
- ## args); \
+ ((size)?((size)-(off)):0), ## args); \
if (_x < 0) \
- return _x; \
- _x; \
+ (off) += _x; \
})
#define onstack(buf, len) ({ \
char *_guidstr = NULL; \
\
_rc = efi_guid_to_str(guid, &_guidstr); \
- if (_rc < 0) \
- return _rc; \
- _guidstr = onstack(_guidstr, strlen(_guidstr)+1); \
format(buf, size, off, "%s", _guidstr); \
})
const size_t len)
{
ssize_t off = 0;
- ssize_t sz;
for (size_t i = 0; i < len; i++) {
- sz = format(buf, size, off, "%02x",
- *((const unsigned char * const )addr+i));
- if (sz < 0)
- return -1;
- off += sz;
+ format(buf, size, off, "%02x",
+ *((const unsigned char * const )addr+i));
}
return off;
}
format_vendor_helper(char *buf, size_t size, char *label, const_efidp dp)
{
ssize_t off = 0;
- size_t bytes = efidp_node_size(dp)
+ ssize_t bytes = efidp_node_size(dp)
- sizeof (efidp_header)
- sizeof (efi_guid_t);
- off = format(buf, size, off, "%s(", label);
- off += format_guid(buf, size, off, &dp->hw_vendor.vendor_guid);
+ format(buf, size, off, label, "%s(", label);
+ format_guid(buf, size, off, label, &dp->hw_vendor.vendor_guid);
if (bytes) {
- off += format(buf, size, off, ",");
- off += format_hex(buf, size, off,
- dp->hw_vendor.vendor_data, bytes);
+ format(buf, size, off, label, ",");
+ format_hex(buf, size, off, label, dp->hw_vendor.vendor_data,
+ bytes);
}
- off += format(buf, size, off, ")");
+ format(buf, size, off, label, ")");
return off;
}
})
#define format_array(buf, size, off, fmt, type, addr, len) ({ \
- ssize_t _off = 0; \
for (size_t _i = 0; _i < len; _i++) { \
if (_i != 0) \
- _off += format(buf, size, off+_off, ",");\
- _off += format(buf, size, off+_off, fmt, \
- ((type *)addr)[_i]); \
+ format(buf, size, off, ","); \
+ format(buf, size, off, fmt, \
+ ((type *)addr)[_i]); \
} \
- _off; \
+ (off); \
})
extern ssize_t _format_hw_dn(char *buf, size_t size, const_efidp dp);
extern ssize_t _format_media_dn(char *buf, size_t size, const_efidp dp);
extern ssize_t _format_bios_boot_dn(char *buf, size_t size, const_efidp dp);
+#define format_helper_2(name, buf, size, off, dp) ({ \
+ ssize_t _sz; \
+ _sz = name(((buf)+(off)), \
+ ((size)?((size)-(off)):0), \
+ (dp)); \
+ if (_sz < 0) { \
+ efi_error("%s failed", #name); \
+ return -1; \
+ } \
+ (off) += _sz; \
+ })
+
#define format_hw_dn(buf, size, off, dp) \
- _format_hw_dn(((buf)+(off)), ((size)?((size)-(off)):0), (dp))
+ format_helper_2(_format_hw_dn, buf, size, off, dp)
#define format_acpi_dn(buf, size, off, dp) \
- _format_acpi_dn(((buf)+(off)), ((size)?((size)-(off)):0), (dp))
+ format_helper_2(_format_acpi_dn, buf, size, off, dp)
#define format_message_dn(buf, size, off, dp) \
- _format_message_dn(((buf)+(off)), ((size)?((size)-(off)):0), (dp))
+ format_helper_2(_format_message_dn, buf, size, off, dp)
#define format_media_dn(buf, size, off, dp) \
- _format_media_dn(((buf)+(off)), ((size)?((size)-(off)):0), (dp))
+ format_helper_2(_format_media_dn, buf, size, off, dp)
#define format_bios_boot_dn(buf, size, off, dp) \
- _format_bios_boot_dn(((buf)+(off)), ((size)?((size)-(off)):0), (dp))
-
+ format_helper_2(_format_bios_boot_dn, buf, size, off, dp)
#endif /* _EFIVAR_INTERNAL_DP_H */