libfru 2.0+git20240917.25293b1
FRU Manupulation Library
|
FRU generator utility. More...
#include <getopt.h>
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include <limits.h>
#include <ctype.h>
#include "fru.h"
#include "fru-errno.h"
#include "frugen.h"
#include "smbios.h"
Macros | |
#define | VERSION "BROKEN" |
#define | COPYRIGHT_YEARS "2016-2024" |
#define | MAX_FILE_SIZE 1L * 1024L * 1024L |
#define | _GNU_SOURCE |
#define | debug_dump(level, data, len, fmt, args...) |
#define | DATEBUF_SZ 20 |
#define | FRU_FIELD_NOT_PRESENT (-1) |
Functions | |
fru_mr_mgmt_type_t | fru_mr_mgmt_type_by_name (const char *name) |
const char * | fru_mr_mgmt_name_by_type (fru_mr_mgmt_type_t type) |
bool | datestr_to_tv (const char *datestr, struct timeval *tv) |
void | tv_to_datestr (char *datestr, const struct timeval *tv) |
fieldopt_t | arg_to_fieldopt (char *arg) |
void | load_from_binary_file (const char *fname, const struct frugen_config_s *config, struct frugen_fruinfo_s *info) |
void | load_fromfile (const char *fname, const struct frugen_config_s *config, struct frugen_fruinfo_s *info) |
void | save_to_text_file (FILE **fp, const char *fname, const struct frugen_fruinfo_s *info, const struct frugen_config_s *config) |
void | save_to_binary_file (const char *fname, struct frugen_fruinfo_s *info, const struct frugen_config_s *config) |
int | main (int argc, char *argv[]) |
Variables | |
volatile int | debug_level = 0 |
FRU generator utility.
Copyright (C) 2016-2024 Alexander Amelkin alexa.nosp@m.nder.nosp@m.@amel.nosp@m.kin..nosp@m.msk.r.nosp@m.u SPDX-License-Identifier: GPL-2.0-or-later OR Apache-2.0
#define _GNU_SOURCE |
#define COPYRIGHT_YEARS "2016-2024" |
#define DATEBUF_SZ 20 |
#define debug_dump | ( | level, | |
data, | |||
len, | |||
fmt, | |||
args... | |||
) |
#define FRU_FIELD_NOT_PRESENT (-1) |
#define MAX_FILE_SIZE 1L * 1024L * 1024L |
#define VERSION "BROKEN" |
fieldopt_t arg_to_fieldopt | ( | char * | arg | ) |
Split a --set
command line option argument string into fields.
The argument format is expected to be:
[<encoding>:]<area>.<field>=
Works for string fields only (i.e. not chassis.type or board.date)
Examples: 6bitascii:product.pn=ABCDEF123 // Force 6-bit ASCII if possible text:procuct.name=SOMEPRODUCT // Force plain text, prevent 6-bit board.serial=Whatever // Autodetect encoding product.custom=Sometext // Autodetect, request addition product.custom.1=Sometext // Autodetect, request replacement of field 1
Returns field_opt_t structure. Terminates the program on parsing failure.
WARNING: Modifies the input string.
References fieldopt_t::area, fieldopt_t::custom_index, debug, fatal, fieldopt_t::field, fru_enc_name_by_type(), fru_enc_type_by_name(), FRU_FIELD_CUSTOM, FRU_FIELD_NOT_PRESENT, fieldopt_t::index, fieldopt_t::type, and fieldopt_t::value.
Referenced by main().
bool datestr_to_tv | ( | const char * | datestr, |
struct timeval * | tv | ||
) |
Convert local date/time string to UTC time in seconds for FRU
Referenced by load_from_json_file(), and main().
const char * fru_mr_mgmt_name_by_type | ( | fru_mr_mgmt_type_t | type | ) |
Get Multirecord Area Record name by its type
Reverse of fru_mr_mgmt_type_by_name()
References fatal, and MGMT_TYPE_ID.
fru_mr_mgmt_type_t fru_mr_mgmt_type_by_name | ( | const char * | name | ) |
Find a Management Access record subtype by its short name
Takes a short name of the subtype from the following list and returs the ID as per Table 18-6.
Terminates the program on failure.
[in] | name | The short name of the type: surl = System URL sname = System Name spingaddr = System ping address curl = Component URL cname = Component name cpingaddr = Component ping address uuid = System UUID |
1..7 | The subtype ID |
References fatal.
void load_from_binary_file | ( | const char * | fname, |
const struct frugen_config_s * | config, | ||
struct frugen_fruinfo_s * | info | ||
) |
References debug, fatal, find_fru_internal_use_area(), find_fru_mr_area(), frugen_config_s::flags, frugen_fruinfo_s::fru, fru_decode_board_info(), fru_decode_chassis_info(), fru_decode_internal_use_area(), fru_decode_mr_area(), fru_decode_product_info(), fru_errno, fru_strerr(), frugen_fruinfo_s::has_board, frugen_fruinfo_s::has_chassis, frugen_fruinfo_s::has_internal, frugen_fruinfo_s::has_multirec, frugen_fruinfo_s::has_product, and MAX_FILE_SIZE.
Referenced by load_fromfile().
void load_fromfile | ( | const char * | fname, |
const struct frugen_config_s * | config, | ||
struct frugen_fruinfo_s * | info | ||
) |
References fatal, frugen_config_s::format, FRUGEN_FMT_BINARY, FRUGEN_FMT_JSON, load_from_binary_file(), and load_from_json_file().
Referenced by main().
int main | ( | int | argc, |
char * | argv[] | ||
) |
References fieldopt_t::area, arg_to_fieldopt(), COPYRIGHT_YEARS, fieldopt_t::custom_index, datestr_to_tv(), debug, debug_level, fatal, fieldopt_t::field, frugen_config_s::flags, frugen_config_s::format, frugen_fruinfo_s::fru, fru_errno, FRU_FIELD_CUSTOM, fru_loadfield(), fru_mr_uuid2rec(), fru_strerr(), FRUGEN_FMT_BINARY, FRUGEN_FMT_FIRST, FRUGEN_FMT_JSON, FRUGEN_FMT_LAST, FRUGEN_FMT_TEXTOUT, frugen_fruinfo_s::has_board, frugen_fruinfo_s::has_chassis, frugen_fruinfo_s::has_multirec, frugen_fruinfo_s::has_product, fieldopt_t::index, load_fromfile(), frugen_config_s::no_curr_date, frugen_config_s::outformat, save_to_binary_file(), save_to_json_file(), save_to_text_file(), SMBIOS_CHASSIS_UNKNOWN, fieldopt_t::type, fieldopt_t::value, VERSION, and warn.
void save_to_binary_file | ( | const char * | fname, |
struct frugen_fruinfo_s * | info, | ||
const struct frugen_config_s * | config | ||
) |
Save the encoded FRU from info into a binary file specified by fname.
[in] | fname | Filename to open when *fp is NULL, may be NULL otherwise |
[in] | info | The FRU information structure to get the FRU data from |
[in] | config | Various frugen configuration settings structure |
References frugen_fruinfo_s::areas, debug, debug_dump, fatal, frugen_fruinfo_s::fru, fru_create(), fru_encode_board_info(), fru_encode_chassis_info(), fru_encode_internal_use_area(), fru_encode_mr_area(), fru_encode_product_info(), fru_errno, fru_strerr(), frugen_fruinfo_s::has_bdate, frugen_fruinfo_s::has_board, frugen_fruinfo_s::has_chassis, frugen_fruinfo_s::has_internal, frugen_fruinfo_s::has_multirec, frugen_fruinfo_s::has_product, and frugen_config_s::no_curr_date.
Referenced by main().
void save_to_text_file | ( | FILE ** | fp, |
const char * | fname, | ||
const struct frugen_fruinfo_s * | info, | ||
const struct frugen_config_s * | config | ||
) |
Save the decoded FRU from info into a text file specified by *fp or fname.
[in,out] | fp | Pointer to the file pointer to use for output. If *fp is NULL, fname will be opened, and the pointer to it will be stored in *fp. |
[in] | fname | Filename to open when *fp is NULL, may be NULL otherwise |
[in] | info | The FRU information structure to get the FRU data from |
[in] | config | Various frugen configuration settings structure |
References frugen_fruinfo_s::areas, fatal, frugen_fruinfo_s::fru, fru_enc_name_by_type(), fru_encode_internal_use_area(), fru_errno, fru_strerr(), frugen_fruinfo_s::has_board, frugen_fruinfo_s::has_chassis, frugen_fruinfo_s::has_internal, frugen_fruinfo_s::has_multirec, frugen_fruinfo_s::has_product, and tv_to_datestr().
Referenced by main().
void tv_to_datestr | ( | char * | datestr, |
const struct timeval * | tv | ||
) |
Convert FRU time (in UTC) to a local date/time string
Referenced by save_to_json_file(), and save_to_text_file().
volatile int debug_level = 0 |
Referenced by main().