dmi_save
Synopsis
#include <opendmi/context.h>
typedef enum dmi_save_flags {
DMI_SAVE_FLAG_OVERWRITE = (1 << 0),
DMI_SAVE_FLAG_ANONYMIZE = (1 << 1)
} dmi_save_flags_t;
bool dmi_save(dmi_context_t *context, const char *path, unsigned flags);
Description
The dmi_save function writes the SMBIOS data of an open context into a
dump file, which dmi_load reads back.
The dump is interchangeable with the ones dmidecode --dump-bin writes: the
entry point, padded with zeros to the largest size of an entry point,
followed by the table. The table is written the way it has been read, and
the address of the table the entry point holds is set to its offset within
the file. A context read on a platform which gives no access to the entry
point has none, and a 64-bit entry point is made up for it.
An existing file is replaced only with DMI_SAVE_FLAG_OVERWRITE. A dump
into a regular file, existing or not, is written to a temporary file in the
same directory, which is renamed over path only once it is complete: a
failure neither leaves an incomplete dump behind nor destroys the file being
replaced, and the replaced file keeps its permissions. Since path is
replaced rather than written to, the directory must be writable, and other
hard links to the file keep its former contents. Devices, pipes and symbolic
links, e.g. /dev/stdout, are written directly instead. Devices and pipes,
and the symbolic links to them, are written whether DMI_SAVE_FLAG_OVERWRITE
is set or not, since there is no file to keep, while a symbolic link to a
file, or to nothing, is taken as an existing file.
With DMI_SAVE_FLAG_ANONYMIZE, the table written is the copy
dmi_anonymize makes of it, in which the values identifying the system,
e.g. serial numbers, asset tags, UUIDs and MAC addresses, are replaced. The
copy has the length and the layout of the table, so the entry point holds for
it as it is, and the context itself is left as it is.
Parameters
context-
Open context to save.
path-
Path to the dump file.
flags-
Flags of
dmi_save_flags_t, zero for none:DMI_SAVE_FLAG_OVERWRITE-
Replace the file if it exists, rather than failing.
DMI_SAVE_FLAG_ANONYMIZE-
Write the anonymized copy of the table, see
dmi_anonymize.
Errors
DMI_ERROR_ARGUMENT_NULL-
Path is
nullptr. DMI_ERROR_STATE_INVALID-
Context is not open, or the table is to be anonymized and its structures carry additional information entries applied to them.
DMI_ERROR_ENTRY_LENGTH_INVALID-
Entry point is longer than an entry point can be.
DMI_ERROR_FILE_OPEN_FAILED-
File or its temporary file cannot be created, or the file exists and
DMI_SAVE_FLAG_OVERWRITEis not set. DMI_ERROR_FILE_WRITE_FAILED-
File cannot be written, or the temporary file cannot be renamed over it.
DMI_ERROR_OUT_OF_MEMORY-
Memory for the anonymized copy cannot be allocated.
DMI_ERROR_INTERNAL-
Table cannot be anonymized, see
dmi_anonymize.