John Edward Broadbent | 4bc8a10 | 2021-12-30 16:11:49 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "erase.hpp" |
John Edward Broadbent | a6e3b99 | 2022-03-17 14:33:15 -0700 | [diff] [blame] | 4 | #include "util.hpp" |
John Edward Broadbent | 4bc8a10 | 2021-12-30 16:11:49 -0800 | [diff] [blame] | 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 | {} |
John Edward Broadbent | 4bc8a10 | 2021-12-30 16:11:49 -0800 | [diff] [blame] | 23 | /** @brief writes zero to the drive |
| 24 | * and throws errors accordingly. |
John Edward Broadbent | a6e3b99 | 2022-03-17 14:33:15 -0700 | [diff] [blame] | 25 | * @param[in] driveSize - the size of the block device in bytes |
John Edward Broadbent | 4bc8a10 | 2021-12-30 16:11:49 -0800 | [diff] [blame] | 26 | */ |
John Edward Broadbent | 6978676 | 2022-01-21 14:16:23 -0800 | [diff] [blame] | 27 | void writeZero(uint64_t driveSize); |
John Edward Broadbent | 4bc8a10 | 2021-12-30 16:11:49 -0800 | [diff] [blame] | 28 | |
John Edward Broadbent | a6e3b99 | 2022-03-17 14:33:15 -0700 | [diff] [blame] | 29 | /** @brief writes zero to the drive |
| 30 | * and throws errors accordingly. |
| 31 | */ |
| 32 | void writeZero() |
| 33 | { |
John Edward Broadbent | 5d799bb | 2022-03-22 16:14:24 -0700 | [diff] [blame^] | 34 | writeZero(util::findSizeOfBlockDevice(devPath)); |
John Edward Broadbent | a6e3b99 | 2022-03-17 14:33:15 -0700 | [diff] [blame] | 35 | } |
| 36 | |
John Edward Broadbent | 4bc8a10 | 2021-12-30 16:11:49 -0800 | [diff] [blame] | 37 | /** @brief verifies the uncompressible random pattern is on the drive |
| 38 | * and throws errors accordingly. |
John Edward Broadbent | a6e3b99 | 2022-03-17 14:33:15 -0700 | [diff] [blame] | 39 | * @param[in] driveSize - the size of the block device in bytes |
John Edward Broadbent | 4bc8a10 | 2021-12-30 16:11:49 -0800 | [diff] [blame] | 40 | */ |
John Edward Broadbent | 6978676 | 2022-01-21 14:16:23 -0800 | [diff] [blame] | 41 | void verifyZero(uint64_t driveSize); |
John Edward Broadbent | 4bc8a10 | 2021-12-30 16:11:49 -0800 | [diff] [blame] | 42 | |
John Edward Broadbent | a6e3b99 | 2022-03-17 14:33:15 -0700 | [diff] [blame] | 43 | /** @brief verifies the uncompressible random pattern is on the drive |
| 44 | * and throws errors accordingly. |
| 45 | */ |
| 46 | void verifyZero() |
| 47 | { |
John Edward Broadbent | 5d799bb | 2022-03-22 16:14:24 -0700 | [diff] [blame^] | 48 | verifyZero(util::findSizeOfBlockDevice(devPath)); |
John Edward Broadbent | a6e3b99 | 2022-03-17 14:33:15 -0700 | [diff] [blame] | 49 | } |
| 50 | |
John Edward Broadbent | 4bc8a10 | 2021-12-30 16:11:49 -0800 | [diff] [blame] | 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 |