zero.cpp (6978676100aa65c551e00ea58c6a891223f25be5) zero.cpp (82897c35761f505c2b881f72c61f726f7d562692)
1#include "zero.hpp"
2
3#include "erase.hpp"
4
5#include <phosphor-logging/lg2.hpp>
6#include <stdplus/fd/create.hpp>
7#include <stdplus/fd/managed.hpp>
8#include <xyz/openbmc_project/Common/error.hpp>

--- 37 unchanged lines hidden (view full) ---

46}
47
48void Zero::verifyZero(uint64_t driveSize)
49{
50 ManagedFd fd =
51 stdplus::fd::open(devPath, stdplus::fd::OpenAccess::ReadOnly);
52
53 uint64_t currentIndex = 0;
1#include "zero.hpp"
2
3#include "erase.hpp"
4
5#include <phosphor-logging/lg2.hpp>
6#include <stdplus/fd/create.hpp>
7#include <stdplus/fd/managed.hpp>
8#include <xyz/openbmc_project/Common/error.hpp>

--- 37 unchanged lines hidden (view full) ---

46}
47
48void Zero::verifyZero(uint64_t driveSize)
49{
50 ManagedFd fd =
51 stdplus::fd::open(devPath, stdplus::fd::OpenAccess::ReadOnly);
52
53 uint64_t currentIndex = 0;
54 std::array<std::byte, blockSize> readArr;
54 std::array<std::byte, blockSize> readArr{};
55 const std::array<const std::byte, blockSize> blockOfZeros{};
56
57 while (currentIndex < driveSize)
58 {
59 uint32_t readSize = currentIndex + blockSize < driveSize
60 ? blockSize
61 : driveSize - currentIndex;
62 try
63 {
64 fd.read({readArr.data(), readSize});
65 }
66 catch (...)
67 {
68 lg2::error("Estoraged erase zeros block unable to read size",
69 "REDFISH_MESSAGE_ID",
70 std::string("eStorageD.1.0.EraseFailure"));
71 throw InternalFailure();
72 }
55 const std::array<const std::byte, blockSize> blockOfZeros{};
56
57 while (currentIndex < driveSize)
58 {
59 uint32_t readSize = currentIndex + blockSize < driveSize
60 ? blockSize
61 : driveSize - currentIndex;
62 try
63 {
64 fd.read({readArr.data(), readSize});
65 }
66 catch (...)
67 {
68 lg2::error("Estoraged erase zeros block unable to read size",
69 "REDFISH_MESSAGE_ID",
70 std::string("eStorageD.1.0.EraseFailure"));
71 throw InternalFailure();
72 }
73 if (memcmp(readArr.data(), blockOfZeros.data(), readSize))
73 if (memcmp(readArr.data(), blockOfZeros.data(), readSize) != 0)
74 {
75 lg2::error("Estoraged erase zeros block is not zero",
76 "REDFISH_MESSAGE_ID",
77 std::string("eStorageD.1.0.EraseFailure"));
78 throw InternalFailure();
79 }
80 currentIndex += readSize;
81 }
82}
83
84} // namespace estoraged
74 {
75 lg2::error("Estoraged erase zeros block is not zero",
76 "REDFISH_MESSAGE_ID",
77 std::string("eStorageD.1.0.EraseFailure"));
78 throw InternalFailure();
79 }
80 currentIndex += readSize;
81 }
82}
83
84} // namespace estoraged