diff options
author | Patrick Venture <venture@google.com> | 2018-10-16 17:18:43 -0700 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2018-10-17 10:50:20 -0700 |
commit | c9508db8d33f4394e7c632b2c5cd15febaa8bf5e (patch) | |
tree | b55c60c320363a9540da430725579910c43117fb /strgfnhandler.cpp | |
parent | 0d963f5938e68e05389fb479370f5d5fe8626729 (diff) | |
download | ipmi-fru-parser-c9508db8d33f4394e7c632b2c5cd15febaa8bf5e.tar.gz ipmi-fru-parser-c9508db8d33f4394e7c632b2c5cd15febaa8bf5e.zip |
add clang-format
Add clang-format file.
Change-Id: Ib99bbeb0ec59b5befb742dec38286c24a7f842ea
Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'strgfnhandler.cpp')
-rw-r--r-- | strgfnhandler.cpp | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/strgfnhandler.cpp b/strgfnhandler.cpp index 2cbbf4d..63e9bd6 100644 --- a/strgfnhandler.cpp +++ b/strgfnhandler.cpp @@ -1,8 +1,9 @@ +#include "writefrudata.hpp" + #include <host-ipmid/ipmid-api.h> #include <stdio.h> #include <string.h> #include <unistd.h> -#include "writefrudata.hpp" void register_netfn_storage_write_fru() __attribute__((constructor)); @@ -12,18 +13,20 @@ sd_bus* ipmid_get_sd_bus_connection(void); // Called by IPMI netfn router for write fru data command //-------------------------------------------------------- ipmi_ret_t ipmi_storage_write_fru_data(ipmi_netfn_t netfn, ipmi_cmd_t cmd, - ipmi_request_t request, ipmi_response_t response, - ipmi_data_len_t data_len, ipmi_context_t context) + ipmi_request_t request, + ipmi_response_t response, + ipmi_data_len_t data_len, + ipmi_context_t context) { - FILE *fp = NULL; + FILE* fp = NULL; char fru_file_name[16] = {0}; uint8_t offset = 0; uint16_t len = 0; ipmi_ret_t rc = IPMI_CC_INVALID; - const char *mode = NULL; + const char* mode = NULL; // From the payload, extract the header that has fruid and the offsets - write_fru_data_t *reqptr = (write_fru_data_t*)request; + write_fru_data_t* reqptr = (write_fru_data_t*)request; // Maintaining a temporary file to pump the data sprintf(fru_file_name, "%s%02x", "/tmp/ipmifru", reqptr->frunum); @@ -34,33 +37,35 @@ ipmi_ret_t ipmi_storage_write_fru_data(ipmi_netfn_t netfn, ipmi_cmd_t cmd, // The header contains an extra byte to indicate the start of // the data (so didn't need to worry about word/byte boundaries) // hence the -1... - len = ((uint16_t)*data_len) - (sizeof(write_fru_data_t)-1); + len = ((uint16_t)*data_len) - (sizeof(write_fru_data_t) - 1); // On error there is no response data for this command. *data_len = 0; #ifdef __IPMI__DEBUG__ printf("IPMI WRITE-FRU-DATA for [%s] Offset = [%d] Length = [%d]\n", - fru_file_name, offset, len); + fru_file_name, offset, len); #endif - - if( access( fru_file_name, F_OK ) == -1 ) { + if (access(fru_file_name, F_OK) == -1) + { mode = "wb"; - } else { + } + else + { mode = "rb+"; } if ((fp = fopen(fru_file_name, mode)) != NULL) { - if(fseek(fp, offset, SEEK_SET)) + if (fseek(fp, offset, SEEK_SET)) { perror("Error:"); fclose(fp); return rc; } - if(fwrite(&reqptr->data, len, 1, fp) != 1) + if (fwrite(&reqptr->data, len, 1, fp) != 1) { perror("Error:"); fclose(fp); @@ -71,11 +76,11 @@ ipmi_ret_t ipmi_storage_write_fru_data(ipmi_netfn_t netfn, ipmi_cmd_t cmd, } else { - fprintf(stderr, "Error trying to write to fru file %s\n",fru_file_name); + fprintf(stderr, "Error trying to write to fru file %s\n", + fru_file_name); return rc; } - // If we got here then set the resonse byte // to the number of bytes written memcpy(response, &len, 1); @@ -83,7 +88,7 @@ ipmi_ret_t ipmi_storage_write_fru_data(ipmi_netfn_t netfn, ipmi_cmd_t cmd, rc = IPMI_CC_OK; // Get the reference to global sd_bus object - sd_bus *bus_type = ipmid_get_sd_bus_connection(); + sd_bus* bus_type = ipmid_get_sd_bus_connection(); // We received some bytes. It may be full or partial. Send a valid // FRU file to the inventory controller on DBus for the correct number @@ -98,7 +103,8 @@ ipmi_ret_t ipmi_storage_write_fru_data(ipmi_netfn_t netfn, ipmi_cmd_t cmd, //------------------------------------------------------- void register_netfn_storage_write_fru() { - printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_WRITE_FRU_DATA); - ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WRITE_FRU_DATA, NULL, ipmi_storage_write_fru_data, - SYSTEM_INTERFACE); + printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", NETFUN_STORAGE, + IPMI_CMD_WRITE_FRU_DATA); + ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WRITE_FRU_DATA, NULL, + ipmi_storage_write_fru_data, SYSTEM_INTERFACE); } |