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