libfru 3.0.2.gb79b203
FRU Manupulation Library
|
Common definitions for the library. More...
Data Structures | |
struct | fru_errno_t |
struct | fru_t |
Exploded/decoded FRU data structure. More... | |
Macros | |
#define | LIBFRU_MAJOR |
Major component of the library version. | |
#define | LIBFRU_MINOR |
Minor component of the library version. | |
#define | LIBFRU_SUBMINOR |
Subminor component of the library version. | |
#define | LIBFRU_VERSION |
Integer representation of the library version. | |
#define | FRU_IS_VALID_AREA(atype) |
Check if atype is any valid area type. | |
#define | FRU_FOREACH_AREA(it) |
Iterate through all area types using it as an iterator. | |
#define | FRU_ATYPE_HAS_TYPE(atype) |
Check if the area has a 'type' field. | |
#define | FRU_ATYPE_HAS_LANG(atype) |
Check if the area has a 'lang' field. | |
#define | FRU_ARRAY_SZ(a) |
A convenience macro to get the size of an array in elements. | |
#define | FRU_LIST_HEAD |
Add entry at the head of the list, used by fru_add_mr() and alike. | |
#define | FRU_LIST_TAIL |
Add entry at the end of the list, used by fru_add_mr() and alike. | |
#define | FRU_IS_APOS_VALID(pos) |
#define | fru_free(fru) |
Deallocate a dynamically allocated fru structure. | |
Functions | |
const char * | fru_strerr (fru_errno_t) |
Get a description of the given fru_errno value. | |
void | fru_clearerr (void) |
Clear the error status of the library. | |
int16_t | fru_hex2byte (const char *hex) |
Convert 2 first bytes of hex string into a binary byte. | |
fru_t * | fru_init (fru_t *fru) |
Initialize/allocate a fru structure. | |
fru_t * | fru_loadfile (fru_t *fru, const char *filename, fru_flags_t flags) |
Load FRU information from a binary file. | |
fru_t * | fru_loadbuffer (fru_t *fru, const void *buf, size_t size, fru_flags_t flags) |
Load FRU information from a binary file. | |
void | fru_wipe (fru_t *fru) |
Wipe the contents of a fru_t structure. | |
bool | fru_enable_area (fru_t *fru, fru_area_type_t area, fru_area_position_t after) |
Enable a previously disabled / non-present area. | |
bool | fru_disable_area (fru_t *fru, fru_area_type_t atype) |
Disable a previously enabled / present area. | |
bool | fru_move_area (fru_t *fru, fru_area_type_t area, fru_area_position_t after) |
Move an enabled/present area. | |
bool | fru_savebuffer (void **bufptr, size_t *size, const fru_t *fru) |
Encode a FRU info structure into a binary buffer. | |
bool | fru_savefile (const char *fname, const fru_t *fru) |
Encode a FRU info structure into a binary file. | |
Variables | |
fru_error_code_t | fru_errno_t::code |
The error code. | |
fru_error_source_t | fru_errno_t::src |
The source of error. | |
int | fru_errno_t::index |
Index of the offending entity within the source, that is, an index of a field (for FRU_*_INFO) or a record (for FRU_MR). | |
__thread fru_errno_t | fru_errno |
Numeric code of an error. | |
Common definitions for the library.
#define FRU_ARRAY_SZ | ( | a | ) |
A convenience macro to get the size of an array in elements.
#define FRU_ATYPE_HAS_LANG | ( | atype | ) |
Check if the area has a 'lang' field.
#define FRU_ATYPE_HAS_TYPE | ( | atype | ) |
Check if the area has a 'type' field.
#define FRU_FOREACH_AREA | ( | it | ) |
Iterate through all area types using it as an iterator.
It is recommended to declare it as fru_area_type_t.
Example
#define fru_free | ( | fru | ) |
Deallocate a dynamically allocated fru structure.
Same as fru_wipe(), but also deallocates the fru structure itself. Use on dynamically allocated structures only.
Sets fru to NULL upon successful deletion.
[in] | fru | Pointer to the decoded FRU information structure to delete |
#define FRU_IS_APOS_VALID | ( | pos | ) |
#define FRU_IS_VALID_AREA | ( | atype | ) |
Check if atype is any valid area type.
#define FRU_LIST_HEAD |
Add entry at the head of the list, used by fru_add_mr() and alike.
#define FRU_LIST_TAIL |
Add entry at the end of the list, used by fru_add_mr() and alike.
#define LIBFRU_MAJOR |
Major component of the library version.
#define LIBFRU_MINOR |
Minor component of the library version.
#define LIBFRU_SUBMINOR |
Subminor component of the library version.
#define LIBFRU_VERSION |
Integer representation of the library version.
You may use this as a feature test macro, e.g.:
enum fru_area_position_t |
Define FRU area position in the binary file.
Use with fru_enable_area() and fru_move_area().
The order and meaning of non-negative values matches that of fru_area_type_t and follows the FRU specification. It is always safe to compare variables of the two types as well as type cast one to another if the value of fru_area_position_t is non-negative.
enum fru_area_type_t |
FRU area types.
Also area indices inside the FRU information structure header
Enumerator | |
---|---|
FRU_INTERNAL_USE | Internal use area. |
FRU_MIN_AREA | Minimum area type (equals FRU_INTERNAL_USE) |
FRU_CHASSIS_INFO | Chassis information area. |
FRU_BOARD_INFO | Board information area. |
FRU_PRODUCT_INFO | Product information area. |
FRU_MR | Multirecord area. |
FRU_MAX_AREA | Maximum area type (equals FRU_MR) |
FRU_TOTAL_AREAS | Maximum total count of areas in a FRU file. |
enum fru_error_code_t |
Defines the errors specific to libfru.
These values are applicable to fru_errno.code
enum fru_error_source_t |
Describes an offending area, see fru_errno_t.
For area-related values this enum matches fru_area_type_t
Enumerator | |
---|---|
FERR_LOC_INTERNAL | The error is in the internal use area. |
FERR_LOC_CHASSIS | The error is in the chassis information area. |
FERR_LOC_BOARD | The error is in the board information area. |
FERR_LOC_PRODUCT | The error is in the product information area. |
FERR_LOC_MR | The error is in the multirecord area. |
FERR_LOC_GENERAL | The error is about FRU file or structure in general, not about any specific area. This is also used when a non-area specific call, such as fru_setfield(), encounters an error. |
FERR_LOC_CALLER | The error is in the calling code (bad arguments?) |
FERR_LOC_COUNT | The total count of possible error locations. |
enum fru_flags_t |
Debug flags to FRU decoding functions.
Sometimes some vendors make errors in their FRU info files. These flags are needed to ignore those possible errors and load as much information as possible. Without these flags, the fru_loadfile() and fru_loadbuffer() will fail immediately upon detection of an error in the input.
void fru_clearerr | ( | void | ) |
bool fru_disable_area | ( | fru_t * | fru, |
fru_area_type_t | atype | ||
) |
Disable a previously enabled / present area.
Marks the requested area type as non-present and resets its order relative to other areas. Disabled areas will not be saved by fru_savefile() or fru_savebuffer().
[in,out] | fru | A pointer to the FRU structure to modify |
[in] | atype | The area type to disable |
true | Success, will also set fru_errno.code to FEADISABLED if the area was already disabled before the call |
false | Error, see fru_errno for details |
bool fru_enable_area | ( | fru_t * | fru, |
fru_area_type_t | area, | ||
fru_area_position_t | after | ||
) |
Enable a previously disabled / non-present area.
Marks the requested area type as present and sets up its order relative to other areas as requested. Can either position the area automatically if after is FRU_APOS_AUTO, or put it at the requested position. See fru_area_position_t for the values of after.
If the area specified by after is not enabled, then the function will behave as if after was FRU_APOS_AUTO.
When after is FRU_APOS_AUTO, the area will be put:
Thus, if you always use FRU_APOS_AUTO, all areas will be then saved in the the natural order of their respective offset locations in the FRU header, as per the specification. That is:
It is advised that you first enable areas that you want to be in the natural order, then enable the areas that you want to go after some other specific areas, and finally enable the ones that you want to go first or last.
Otherwise, if you, for example, first enable FRU_BOARD_INFO to go after FRU_PRODUCT_INFO, and then enable FRU_MR with FRU_APOS_AUTO, then MR area will be placed between the product and board areas, which may be contrary to what you intended.
Alternatively, you may set the order manually by modifying fru->order
array, but be careful there.
[in,out] | fru | A pointer to the FRU structure to modify |
[in] | area | The area type to enable |
[in] | after | An area position where to put the enabled area, or FRU_APOS_AUTO for automatic placement. Specify FRU_APOS_FIRST to make the enableed area first or FRU_APOS_LAST to make it last. Use any of FRU_AFTER_* to select a relative position. |
true | Success |
false | Error, see fru_errno for details |
int16_t fru_hex2byte | ( | const char * | hex | ) |
Convert 2 first bytes of hex string into a binary byte.
This is just a convenience utility function, not directly related to FRU.
-1 | An error occured. See fru_errno |
Initialize/allocate a fru structure.
Initializes a statically allocated fru structure for later modification and saving with fru_savebuffer() or fru_savefile().
If a fru is NULL
, then a new FRU structure is allocated, otherwise the supplied one will be initialized. Any previously existing values or pointers will be reset, so make sure to never call this function on a previously loaded or otherwise actively used fru structure as that may result in memory leakage.
In the initialized structure:
[in,out] | fru | Pointer to an initial FRU structure (can be NULL ) |
NULL | Error detected, fru_errno is set accordingly. |
fru_t * fru_loadbuffer | ( | fru_t * | fru, |
const void * | buf, | ||
size_t | size, | ||
fru_flags_t | flags | ||
) |
Load FRU information from a binary file.
Same as fru_loadfile(), but takes a binary buffer as input. In fact, fru_loadfile() calls this one under the hood after memory-mapping the binary FRU file.
[in,out] | fru | Pointer to an initial FRU structure (can be NULL ) |
[in] | buf | Buffer containing a binary FRU information file |
[in] | size | Buffer size |
[in] | flags | Debug flags or FRU_NOFLAGS |
NULL | Error detected, fru_errno is set accordingly. |
fru_t * fru_loadfile | ( | fru_t * | fru, |
const char * | filename, | ||
fru_flags_t | flags | ||
) |
Load FRU information from a binary file.
Takes a binary FRU information file (e.g. EEPROM dump or the output of ipmitool fru read
, and loads it as a fru_t structure for further modification.
If fru is NULL
, then a new FRU structure is allocated, otherwise the supplied one will be filled in, and the existing values will be overwritten with the contents of the file. The function will fail if fru_t.internal
, fru_t.mr
, or any of the cust
lists in the info area members of fru are non-NULL.
Supported are:
false
. Otherwise that option will be set to true
.[in,out] | fru | Pointer to an initial FRU structure (can be NULL ) |
[in] | filename | Name of the file to load |
[in] | flags | flags or FRU_NOFLAGS |
NULL | Error detected, fru_errno is set accordingly. |
bool fru_move_area | ( | fru_t * | fru, |
fru_area_type_t | area, | ||
fru_area_position_t | after | ||
) |
Move an enabled/present area.
Effectively performs a call to fru_disable_area() followed by a call to fru_enable_area(), but will fail on already disabled areas unlike the former.
See the description for fru_enable_area() for the info on this function's arguments and return values.
bool fru_savebuffer | ( | void ** | bufptr, |
size_t * | size, | ||
const fru_t * | fru | ||
) |
Encode a FRU info structure into a binary buffer.
If buf is NULL
, allocates a new one. Always calculates the resulting size and stores it in size in the event of successful completion.
[in] | fru | The FRU information structure to encode/export |
[in,out] | bufptr | Pointer to a buffer to save the binary FRU information file to (allocated if NULL ) |
[in,out] | size | Pointer to the size of the output buffer (size is adjusted upon return to the actual size of the encoded data). The input value pointed to by size can be 0 if bufptr is NULL . |
true | Encoded successfully, size adjusted. |
false | Failed to encode. fru_errno is set accordingly. |
bool fru_savefile | ( | const char * | fname, |
const fru_t * | fru | ||
) |
Encode a FRU info structure into a binary file.
Creates/overwrites the specified file with the encoded FRU info data. Calls fru_savebuffer() under the hood.
[in] | fru | The decoded FRU information structure to encode |
[in] | fname | Name of the file to create |
true | Encoded and written successfully. |
false | Failed to encode or write, fru_errno is set accordingly. |
const char * fru_strerr | ( | fru_errno_t | ) |
Get a description of the given fru_errno
value.
Converts a numeric error represented by fru_errno into a string description of the error. If fru_errno is FEGENERIC, this function will call strerror()
to obtain the description of the generic libc error.
NULL | No description found for the given value. |
void fru_wipe | ( | fru_t * | fru | ) |
Wipe the contents of a fru_t structure.
Will free any memory allocated by fru_loadfile(), fru_loadbuffer(), fru_add_mr(), and fru_add_custom() functions for the members of fru. Any deallocated members will be set to NULL.
Will zero all fields of fru, but will not free fru itself to allow for static allocation of the top-level structure. If it was dynamically allocated (e.g, by a call to fru_loadfile() with NULL
for fru argument), then your are to explicitly call free()
on it after calling fru_wipe().
If you're only dealing with dynamically allocated fru structures, consider using fru_free() instead.
[in,out] | fru | Pointer to a FRU structure to free |
fru_error_code_t fru_errno_t::code |
The error code.
|
extern |
Numeric code of an error.
Similar to errno
, this thread-local variable is modified by most functons in libfru in the event of an error.
Call fru_clearerr() before invocation of any libfru function, check for non-zero values of the code
field after the invocation.
Unlike errno
, this variable contains the information about not just the error, but also about the part of FRU where it was detected. If the fru_errno.code
is FEGENERIC, then you need to check errno
for the actual error.
Please also see fru_strerr()
int fru_errno_t::index |
Index of the offending entity within the source, that is, an index of a field (for FRU_*_INFO) or a record (for FRU_MR).
This is (-1) when not applicable. That is, the area indicated by src doesn't have any fields/records, or the error is in the area as a whole, not in some particular field/record, or the error is not in a FRU area at all (e.g., src == FERR_LOC_CALLER).
For info areas this is less than the respective FRU_*_FIELD_COUNT
for the standard/mandatory fields, or is FRU_*_FIELD_COUNT + X
, where X
is the index of the offending custom field.
For FEAREANOTSUP and FEAREABADTYPE this field contains the bad area type (see fru_area_type_t).
fru_error_source_t fru_errno_t::src |
The source of error.