cleanup sdr cache generation

This commit is contained in:
Duncan Laurie 2006-03-19 22:53:15 +00:00
parent e37e785449
commit 4b1ccbfdc3
2 changed files with 44 additions and 22 deletions

View File

@ -722,7 +722,10 @@ struct ipmi_sdr_iterator {
struct sdr_record_list {
uint16_t id;
uint8_t version;
uint8_t type;
uint8_t length;
uint8_t *raw;
struct sdr_record_list *next;
union {
struct sdr_record_full_sensor *full;

View File

@ -3730,13 +3730,10 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile)
{
struct sdr_get_rs *header;
struct ipmi_sdr_iterator *itr;
struct sdr_record_list *sdrr;
FILE *fp;
int rc = 0;
fp = ipmi_open_file_write(ofile);
if (fp == NULL)
return -1;
/* open connection to SDR */
itr = ipmi_sdr_start(intf);
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);
/* go through sdr records */
/* generate list of records */
while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL) {
int r;
uint8_t h[5];
uint8_t *rec;
sdrr = malloc(sizeof(struct sdr_record_list));
if (sdrr == NULL) {
lprintf(LOG_ERR, "ipmitool: malloc failure");
return -1;
}
memset(sdrr, 0, sizeof(struct sdr_record_list));
lprintf(LOG_INFO, "Record ID %04x (%d bytes)",
header->id, header->length);
rec = ipmi_sdr_get_record(intf, header, itr);
if (rec == NULL)
continue;
sdrr->id = header->id;
sdrr->version = header->version;
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 */
h[0] = header->id & 0xff;
h[1] = (header->id >> 8) & 0xff;
h[2] = header->version;
h[3] = header->type;
h[4] = header->length;
h[0] = sdrr->id & 0xff;
h[1] = (sdrr->id >> 8) & 0xff;
h[2] = sdrr->version;
h[3] = sdrr->type;
h[4] = sdrr->length;
r = fwrite(h, 1, 5, fp);
if (r != 5) {
@ -3776,18 +3797,16 @@ ipmi_sdr_dump_bin(struct ipmi_intf *intf, const char *ofile)
}
/* write sdr entry */
r = fwrite(rec, 1, header->length, fp);
if (r != header->length) {
r = fwrite(sdrr->raw, 1, sdrr->length, fp);
if (r != sdrr->length) {
lprintf(LOG_ERR, "Error writing %d record bytes "
"to output file %s", header->length, ofile);
"to output file %s", sdrr->length, ofile);
rc = -1;
break;
}
}
ipmi_sdr_end(intf, itr);
fclose(fp);
return rc;
}