xref: /openbmc/estoraged/include/zero.hpp (revision a6e3b99df73312c465b4b174b167bb785e886a71)
14bc8a10cSJohn Edward Broadbent #pragma once
24bc8a10cSJohn Edward Broadbent 
34bc8a10cSJohn Edward Broadbent #include "erase.hpp"
4*a6e3b99dSJohn Edward Broadbent #include "util.hpp"
54bc8a10cSJohn Edward Broadbent 
64bc8a10cSJohn Edward Broadbent #include <stdplus/fd/create.hpp>
74bc8a10cSJohn Edward Broadbent #include <stdplus/fd/managed.hpp>
84bc8a10cSJohn Edward Broadbent 
94bc8a10cSJohn Edward Broadbent namespace estoraged
104bc8a10cSJohn Edward Broadbent {
114bc8a10cSJohn Edward Broadbent 
124bc8a10cSJohn Edward Broadbent using stdplus::fd::ManagedFd;
134bc8a10cSJohn Edward Broadbent 
144bc8a10cSJohn Edward Broadbent class Zero : public Erase
154bc8a10cSJohn Edward Broadbent {
164bc8a10cSJohn Edward Broadbent   public:
174bc8a10cSJohn Edward Broadbent     /** @brief Creates a zero erase object.
184bc8a10cSJohn Edward Broadbent      *
194bc8a10cSJohn Edward Broadbent      *  @param[in] inDevPath - the linux device path for the block device.
204bc8a10cSJohn Edward Broadbent      */
214bc8a10cSJohn Edward Broadbent     Zero(std::string_view inDevPath) : Erase(inDevPath)
224bc8a10cSJohn Edward Broadbent     {}
234bc8a10cSJohn Edward Broadbent     /** @brief writes zero to the drive
244bc8a10cSJohn Edward Broadbent      * and throws errors accordingly.
25*a6e3b99dSJohn Edward Broadbent      *  @param[in] driveSize - the size of the block device in bytes
264bc8a10cSJohn Edward Broadbent      */
2769786761SJohn Edward Broadbent     void writeZero(uint64_t driveSize);
284bc8a10cSJohn Edward Broadbent 
29*a6e3b99dSJohn Edward Broadbent     /** @brief writes zero to the drive
30*a6e3b99dSJohn Edward Broadbent      * and throws errors accordingly.
31*a6e3b99dSJohn Edward Broadbent      */
32*a6e3b99dSJohn Edward Broadbent     void writeZero()
33*a6e3b99dSJohn Edward Broadbent     {
34*a6e3b99dSJohn Edward Broadbent         writeZero(util::Util::findSizeOfBlockDevice(devPath));
35*a6e3b99dSJohn Edward Broadbent     }
36*a6e3b99dSJohn Edward Broadbent 
374bc8a10cSJohn Edward Broadbent     /** @brief verifies the  uncompressible random pattern is on the drive
384bc8a10cSJohn Edward Broadbent      * and throws errors accordingly.
39*a6e3b99dSJohn Edward Broadbent      *  @param[in] driveSize - the size of the block device in bytes
404bc8a10cSJohn Edward Broadbent      */
4169786761SJohn Edward Broadbent     void verifyZero(uint64_t driveSize);
424bc8a10cSJohn Edward Broadbent 
43*a6e3b99dSJohn Edward Broadbent     /** @brief verifies the  uncompressible random pattern is on the drive
44*a6e3b99dSJohn Edward Broadbent      * and throws errors accordingly.
45*a6e3b99dSJohn Edward Broadbent      */
46*a6e3b99dSJohn Edward Broadbent     void verifyZero()
47*a6e3b99dSJohn Edward Broadbent     {
48*a6e3b99dSJohn Edward Broadbent         verifyZero(util::Util::findSizeOfBlockDevice(devPath));
49*a6e3b99dSJohn Edward Broadbent     }
50*a6e3b99dSJohn Edward Broadbent 
514bc8a10cSJohn Edward Broadbent   private:
524bc8a10cSJohn Edward Broadbent     /* @brief the size of the blocks in bytes used for write and verify.
534bc8a10cSJohn Edward Broadbent      * 32768 was also tested. It had almost identical performance.
544bc8a10cSJohn Edward Broadbent      */
554bc8a10cSJohn Edward Broadbent     static constexpr size_t blockSize = 4096;
564bc8a10cSJohn Edward Broadbent };
574bc8a10cSJohn Edward Broadbent 
584bc8a10cSJohn Edward Broadbent } // namespace estoraged
59