xref: /openbmc/estoraged/include/zero.hpp (revision 605085a6)
1 #pragma once
2 
3 #include "erase.hpp"
4 #include "util.hpp"
5 
6 #include <stdplus/fd/create.hpp>
7 #include <stdplus/fd/managed.hpp>
8 
9 namespace estoraged
10 {
11 
12 using stdplus::fd::ManagedFd;
13 
14 class Zero : public Erase
15 {
16   public:
17     /** @brief Creates a zero erase object.
18      *
19      *  @param[in] inDevPath - the linux device path for the block device.
20      */
21     Zero(std::string_view inDevPath) : Erase(inDevPath)
22     {}
23     /** @brief writes zero to the drive
24      * and throws errors accordingly.
25      *  @param[in] driveSize - the size of the block device in bytes
26      */
27     void writeZero(uint64_t driveSize);
28 
29     /** @brief writes zero to the drive
30      * and throws errors accordingly.
31      */
32     void writeZero()
33     {
34         writeZero(util::Util::findSizeOfBlockDevice(devPath));
35     }
36 
37     /** @brief verifies the  uncompressible random pattern is on the drive
38      * and throws errors accordingly.
39      *  @param[in] driveSize - the size of the block device in bytes
40      */
41     void verifyZero(uint64_t driveSize);
42 
43     /** @brief verifies the  uncompressible random pattern is on the drive
44      * and throws errors accordingly.
45      */
46     void verifyZero()
47     {
48         verifyZero(util::Util::findSizeOfBlockDevice(devPath));
49     }
50 
51   private:
52     /* @brief the size of the blocks in bytes used for write and verify.
53      * 32768 was also tested. It had almost identical performance.
54      */
55     static constexpr size_t blockSize = 4096;
56 };
57 
58 } // namespace estoraged
59