John Edward Broadbent | 7f2ab64 | 2021-11-11 21:00:38 -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 | 7f2ab64 | 2021-11-11 21:00:38 -0800 | [diff] [blame] | 5 | |
| 6 | #include <stdplus/fd/create.hpp> |
| 7 | #include <stdplus/fd/managed.hpp> |
| 8 | |
| 9 | #include <span> |
| 10 | #include <string> |
| 11 | |
John Edward Broadbent | d3bfa7b | 2022-01-13 17:41:32 -0800 | [diff] [blame] | 12 | namespace estoraged |
| 13 | { |
John Edward Broadbent | 7f2ab64 | 2021-11-11 21:00:38 -0800 | [diff] [blame] | 14 | using stdplus::fd::ManagedFd; |
| 15 | |
| 16 | class Pattern : public Erase |
| 17 | { |
| 18 | public: |
| 19 | /** @brief Creates a pattern erase object. |
| 20 | * |
| 21 | * @param[in] inDevPath - the linux device path for the block device. |
| 22 | */ |
| 23 | Pattern(std::string_view inDevPath) : Erase(inDevPath) |
| 24 | {} |
| 25 | |
| 26 | /** @brief writes an uncompressible random pattern to the drive |
| 27 | * and throws errors accordingly. |
| 28 | * |
| 29 | * @param[in] bytes - Size of the block device |
John Edward Broadbent | 7f2ab64 | 2021-11-11 21:00:38 -0800 | [diff] [blame] | 30 | */ |
John Edward Broadbent | a6e3b99 | 2022-03-17 14:33:15 -0700 | [diff] [blame] | 31 | void writePattern() |
| 32 | { |
| 33 | writePattern(util::Util::findSizeOfBlockDevice(devPath)); |
| 34 | } |
| 35 | |
John Edward Broadbent | 6978676 | 2022-01-21 14:16:23 -0800 | [diff] [blame] | 36 | void writePattern(uint64_t driveSize); |
John Edward Broadbent | 7f2ab64 | 2021-11-11 21:00:38 -0800 | [diff] [blame] | 37 | |
| 38 | /** @brief verifies the uncompressible random pattern is on the drive |
| 39 | * and throws errors accordingly. |
| 40 | * |
| 41 | * @param[in] bytes - Size of the block device |
John Edward Broadbent | 7f2ab64 | 2021-11-11 21:00:38 -0800 | [diff] [blame] | 42 | */ |
John Edward Broadbent | a6e3b99 | 2022-03-17 14:33:15 -0700 | [diff] [blame] | 43 | |
| 44 | void verifyPattern() |
| 45 | { |
| 46 | verifyPattern(util::Util::findSizeOfBlockDevice(devPath)); |
| 47 | } |
John Edward Broadbent | 6978676 | 2022-01-21 14:16:23 -0800 | [diff] [blame] | 48 | void verifyPattern(uint64_t driveSize); |
John Edward Broadbent | 7f2ab64 | 2021-11-11 21:00:38 -0800 | [diff] [blame] | 49 | }; |
John Edward Broadbent | d3bfa7b | 2022-01-13 17:41:32 -0800 | [diff] [blame] | 50 | |
| 51 | } // namespace estoraged |