Update 1 bit correction flow

In case of 1 bit EEPROM flip ecc check algorithms detects and updates
the same in the buffer passed to the algorithm.
The data in case of some FRUs is getting corrupted once the algorithm
performs 1 bit correction on th evector.
Hence to avoid any data corruption in that flow, a copy of the buffer
is being passed to the API and writing back to the EEPROM has been
removed.

Change-Id: Ief4189d24e29059e725927b3023f226356b9999a
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
diff --git a/vpd-manager/src/ipz_parser.cpp b/vpd-manager/src/ipz_parser.cpp
index f2dfa2b..a465a03 100644
--- a/vpd-manager/src/ipz_parser.cpp
+++ b/vpd-manager/src/ipz_parser.cpp
@@ -5,6 +5,7 @@
 #include "vpdecc/vpdecc.h"
 
 #include "constants.hpp"
+#include "event_logger.hpp"
 #include "exceptions.hpp"
 
 #include <nlohmann/json.hpp>
@@ -60,7 +61,9 @@
 
 bool IpzVpdParser::vhdrEccCheck()
 {
-    auto vpdPtr = m_vpdVector.cbegin();
+    // To avoid 1 bit flip correction from corrupting the main buffer.
+    const types::BinaryVector tempVector = m_vpdVector;
+    auto vpdPtr = tempVector.cbegin();
 
     auto l_status = vpdecc_check_data(
         const_cast<uint8_t*>(&vpdPtr[Offset::VHDR_RECORD]),
@@ -69,29 +72,11 @@
         Length::VHDR_ECC_LENGTH);
     if (l_status == VPD_ECC_CORRECTABLE_DATA)
     {
-        try
-        {
-            if (m_vpdFileStream.is_open())
-            {
-                m_vpdFileStream.seekp(m_vpdStartOffset + Offset::VHDR_RECORD,
-                                      std::ios::beg);
-                m_vpdFileStream.write(reinterpret_cast<const char*>(
-                                          &m_vpdVector[Offset::VHDR_RECORD]),
-                                      Length::VHDR_RECORD_LENGTH);
-            }
-            else
-            {
-                logging::logMessage("File not open");
-                return false;
-            }
-        }
-        catch (const std::fstream::failure& e)
-        {
-            logging::logMessage(
-                "Error while operating on file with exception: " +
-                std::string(e.what()));
-            return false;
-        }
+        EventLogger::createSyncPel(
+            types::ErrorType::EccCheckFailed,
+            types::SeverityType::Informational, __FILE__, __FUNCTION__, 0,
+            "One bit correction for VHDR performed", std::nullopt, std::nullopt,
+            std::nullopt, std::nullopt);
     }
     else if (l_status != VPD_ECC_OK)
     {
@@ -122,37 +107,22 @@
     std::advance(vpdPtr, sizeof(types::ECCOffset));
     auto vtocECCLength = readUInt16LE(vpdPtr);
 
+    // To avoid 1 bit flip correction from corrupting the main buffer.
+    const types::BinaryVector tempVector = m_vpdVector;
     // Reset pointer to start of the vpd,
     // so that Offset will point to correct address
-    vpdPtr = m_vpdVector.cbegin();
+    vpdPtr = tempVector.cbegin();
+
     auto l_status = vpdecc_check_data(
-        const_cast<uint8_t*>(&m_vpdVector[vtocOffset]), vtocLength,
-        const_cast<uint8_t*>(&m_vpdVector[vtocECCOffset]), vtocECCLength);
+        const_cast<uint8_t*>(&vpdPtr[vtocOffset]), vtocLength,
+        const_cast<uint8_t*>(&vpdPtr[vtocECCOffset]), vtocECCLength);
     if (l_status == VPD_ECC_CORRECTABLE_DATA)
     {
-        try
-        {
-            if (m_vpdFileStream.is_open())
-            {
-                m_vpdFileStream.seekp(m_vpdStartOffset + vtocOffset,
-                                      std::ios::beg);
-                m_vpdFileStream.write(
-                    reinterpret_cast<const char*>(&m_vpdVector[vtocOffset]),
-                    vtocLength);
-            }
-            else
-            {
-                logging::logMessage("File not open");
-                return false;
-            }
-        }
-        catch (const std::fstream::failure& e)
-        {
-            logging::logMessage(
-                "Error while operating on file with exception " +
-                std::string(e.what()));
-            return false;
-        }
+        EventLogger::createSyncPel(
+            types::ErrorType::EccCheckFailed,
+            types::SeverityType::Informational, __FILE__, __FUNCTION__, 0,
+            "One bit correction for VTOC performed", std::nullopt, std::nullopt,
+            std::nullopt, std::nullopt);
     }
     else if (l_status != VPD_ECC_OK)
     {
@@ -185,16 +155,28 @@
         throw(EccException("Invalid ECC length or offset."));
     }
 
-    auto vpdPtr = m_vpdVector.cbegin();
+    // To avoid 1 bit flip correction from corrupting the main buffer.
+    const types::BinaryVector tempVector = m_vpdVector;
+    auto vpdPtr = tempVector.cbegin();
 
-    if (vpdecc_check_data(
-            const_cast<uint8_t*>(&vpdPtr[recordOffset]), recordLength,
-            const_cast<uint8_t*>(&vpdPtr[eccOffset]), eccLength) == VPD_ECC_OK)
+    auto l_status = vpdecc_check_data(
+        const_cast<uint8_t*>(&vpdPtr[recordOffset]), recordLength,
+        const_cast<uint8_t*>(&vpdPtr[eccOffset]), eccLength);
+
+    if (l_status == VPD_ECC_CORRECTABLE_DATA)
     {
-        return true;
+        EventLogger::createSyncPel(
+            types::ErrorType::EccCheckFailed,
+            types::SeverityType::Informational, __FILE__, __FUNCTION__, 0,
+            "One bit correction for record performed", std::nullopt,
+            std::nullopt, std::nullopt, std::nullopt);
+    }
+    else if (l_status != VPD_ECC_OK)
+    {
+        return false;
     }
 
-    return false;
+    return true;
 }
 
 void IpzVpdParser::checkHeader(types::BinaryVector::const_iterator itrToVPD)