dmi_open

Synopsis

#include <opendmi/context.h>

bool dmi_open(dmi_context_t *context, const char *device);

Description

The dmi_open function reads the SMBIOS data of the system the program runs on into a closed context, through the backend of the platform, and decodes it the way the flags of the context say, see dmi_create:

The entry point is read and decoded, on the platforms which give access to it. The structures of the table are found, and the ones of the types the context knows are decoded, with additional information applied when the context has DMI_CONTEXT_FLAG_OVERLAY. The references between the structures are resolved when it has DMI_CONTEXT_FLAG_LINK.

Reading the data of a platform usually requires privileges, because the table is taken from physical memory or from an interface the kernel restricts. A dump of the data is read with dmi_load instead, with the privileges of the file itself.

The structures of the types the vendors define are decoded by the extension modules of the vendors. Before the rest of the table is decoded, the platform is told from the firmware information (type 0) and the system information (type 1), see dmi_get_platform. The modules of the platform are then enabled when the context has DMI_CONTEXT_FLAG_AUTO_MODULES, and the specifications of the enabled modules, including the ones added with dmi_add_extension beforehand, are chosen for the platform and its generation.

The context stays open until it is closed with dmi_close, and the structures are reached through its registry, see dmi_get_registry.

A context which fails to open is left closed, with the errors telling why in its error queue. A context which is open already is left as it is.

Parameters

context

Context to open, which is required to be closed.

device

Path to the memory device the table is read from on the platforms which read physical memory. It is not used at the moment, since every backend reads the data from where its platform provides it, and is passed as nullptr.

Return value

Returns true if the context has been opened, and false otherwise.

Errors

DMI_ERROR_STATE_INVALID

Context is open already.

DMI_ERROR_BACKEND_OPEN_FAILED

Data of the platform cannot be accessed, e.g. for the lack of privileges.

DMI_ERROR_ENTITY_TRUNCATED

Table area is empty, or a structure runs past its end.

DMI_ERROR_FIRMWARE_INFO_NOT_FOUND

Table holds no platform firmware information structure, in the strict mode only.

DMI_ERROR_MODULE_CONFLICT

Specifications of the modules enabled with dmi_add_extension, which apply to the platform, have the same type.

DMI_ERROR_OUT_OF_MEMORY

Memory is exhausted.

DMI_ERROR_CONTEXT_OPEN_FAILED

Context cannot be opened. Raised last on every failure but the one of a context which is open already, after the errors telling why.

Examples

if (!dmi_open(context, nullptr)) {
    const dmi_error_t *error;

    while ((error = dmi_error_get_first(context)) != nullptr)
        fprintf(stderr, "%s\n", dmi_error_message(error->reason));
}