mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-13 20:17:23 +00:00
cleanup sdr cache generation
This commit is contained in:
parent
e37e785449
commit
4b1ccbfdc3
@ -722,7 +722,10 @@ struct ipmi_sdr_iterator {
|
|||||||
|
|
||||||
struct sdr_record_list {
|
struct sdr_record_list {
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
|
uint8_t version;
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
|
uint8_t length;
|
||||||
|
uint8_t *raw;
|
||||||
struct sdr_record_list *next;
|
struct sdr_record_list *next;
|
||||||
union {
|
union {
|
||||||
struct sdr_record_full_sensor *full;
|
struct sdr_record_full_sensor *full;
|
||||||
|
@ -3730,13 +3730,10 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile)
|
|||||||
{
|
{
|
||||||
struct sdr_get_rs *header;
|
struct sdr_get_rs *header;
|
||||||
struct ipmi_sdr_iterator *itr;
|
struct ipmi_sdr_iterator *itr;
|
||||||
|
struct sdr_record_list *sdrr;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
fp = ipmi_open_file_write(ofile);
|
|
||||||
if (fp == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/* open connection to SDR */
|
/* open connection to SDR */
|
||||||
itr = ipmi_sdr_start(intf);
|
itr = ipmi_sdr_start(intf);
|
||||||
if (itr == NULL) {
|
if (itr == NULL) {
|
||||||
@ -3747,25 +3744,49 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile)
|
|||||||
|
|
||||||
printf("Dumping Sensor Data Repository to '%s'\n", ofile);
|
printf("Dumping Sensor Data Repository to '%s'\n", ofile);
|
||||||
|
|
||||||
/* go through sdr records */
|
/* generate list of records */
|
||||||
while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL) {
|
while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL) {
|
||||||
int r;
|
sdrr = malloc(sizeof(struct sdr_record_list));
|
||||||
uint8_t h[5];
|
if (sdrr == NULL) {
|
||||||
uint8_t *rec;
|
lprintf(LOG_ERR, "ipmitool: malloc failure");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memset(sdrr, 0, sizeof(struct sdr_record_list));
|
||||||
|
|
||||||
lprintf(LOG_INFO, "Record ID %04x (%d bytes)",
|
lprintf(LOG_INFO, "Record ID %04x (%d bytes)",
|
||||||
header->id, header->length);
|
header->id, header->length);
|
||||||
|
|
||||||
rec = ipmi_sdr_get_record(intf, header, itr);
|
sdrr->id = header->id;
|
||||||
if (rec == NULL)
|
sdrr->version = header->version;
|
||||||
continue;
|
sdrr->type = header->type;
|
||||||
|
sdrr->length = header->length;
|
||||||
|
sdrr->raw = ipmi_sdr_get_record(intf, header, itr);
|
||||||
|
|
||||||
|
if (sdr_list_head == NULL)
|
||||||
|
sdr_list_head = sdrr;
|
||||||
|
else
|
||||||
|
sdr_list_tail->next = sdrr;
|
||||||
|
|
||||||
|
sdr_list_tail = sdrr;
|
||||||
|
}
|
||||||
|
|
||||||
|
ipmi_sdr_end(intf, itr);
|
||||||
|
|
||||||
|
/* now write to file */
|
||||||
|
fp = ipmi_open_file_write(ofile);
|
||||||
|
if (fp == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for (sdrr = sdr_list_head; sdrr != NULL; sdrr = sdrr->next) {
|
||||||
|
int r;
|
||||||
|
uint8_t h[5];
|
||||||
|
|
||||||
/* build and write sdr header */
|
/* build and write sdr header */
|
||||||
h[0] = header->id & 0xff;
|
h[0] = sdrr->id & 0xff;
|
||||||
h[1] = (header->id >> 8) & 0xff;
|
h[1] = (sdrr->id >> 8) & 0xff;
|
||||||
h[2] = header->version;
|
h[2] = sdrr->version;
|
||||||
h[3] = header->type;
|
h[3] = sdrr->type;
|
||||||
h[4] = header->length;
|
h[4] = sdrr->length;
|
||||||
|
|
||||||
r = fwrite(h, 1, 5, fp);
|
r = fwrite(h, 1, 5, fp);
|
||||||
if (r != 5) {
|
if (r != 5) {
|
||||||
@ -3776,18 +3797,16 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* write sdr entry */
|
/* write sdr entry */
|
||||||
r = fwrite(rec, 1, header->length, fp);
|
r = fwrite(sdrr->raw, 1, sdrr->length, fp);
|
||||||
if (r != header->length) {
|
if (r != sdrr->length) {
|
||||||
lprintf(LOG_ERR, "Error writing %d record bytes "
|
lprintf(LOG_ERR, "Error writing %d record bytes "
|
||||||
"to output file %s", header->length, ofile);
|
"to output file %s", sdrr->length, ofile);
|
||||||
rc = -1;
|
rc = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ipmi_sdr_end(intf, itr);
|
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user