| #pragma once |
| |
| #include "erase.hpp" |
| #include "util.hpp" |
| |
| #include <stdplus/fd/create.hpp> |
| #include <stdplus/fd/managed.hpp> |
| |
| #include <chrono> |
| #include <span> |
| #include <string> |
| |
| namespace estoraged |
| { |
| using stdplus::fd::Fd; |
| |
| class Pattern : public Erase |
| { |
| public: |
| /** @brief Creates a pattern erase object. |
| * |
| * @param[in] inDevPath - the linux device path for the block device. |
| */ |
| Pattern(std::string_view inDevPath) : Erase(inDevPath) |
| {} |
| |
| /** @brief writes an uncompressible random pattern to the drive, using |
| * default parameters. It also throws errors accordingly. |
| */ |
| void writePattern() |
| { |
| stdplus::fd::Fd&& fd = |
| stdplus::fd::open(devPath, stdplus::fd::OpenAccess::WriteOnly); |
| writePattern(util::findSizeOfBlockDevice(devPath), fd); |
| } |
| |
| /** @brief writes an uncompressible random pattern to the drive |
| * and throws errors accordingly. |
| * |
| * @param[in] bytes - Size of the block device |
| * @param[in] fd - the stdplus file descriptor |
| */ |
| void writePattern(uint64_t driveSize, Fd& fd); |
| |
| /** @brief verifies the uncompressible random pattern is on the drive, using |
| * default parameters. It also throws errors accordingly. |
| */ |
| void verifyPattern() |
| { |
| stdplus::fd::Fd&& fd = |
| stdplus::fd::open(devPath, stdplus::fd::OpenAccess::ReadOnly); |
| verifyPattern(util::findSizeOfBlockDevice(devPath), fd); |
| } |
| |
| /** @brief verifies the uncompressible random pattern is on the drive |
| * and throws errors accordingly. |
| * |
| * @param[in] bytes - Size of the block device |
| * @param[in] fd - the stdplus file descriptor |
| */ |
| void verifyPattern(uint64_t driveSize, Fd& fd); |
| |
| private: |
| static constexpr uint32_t seed = 0x6a656272; |
| static constexpr size_t blockSize = 4096; |
| static constexpr size_t blockSizeUsing32 = blockSize / sizeof(uint32_t); |
| static constexpr size_t maxRetry = 32; |
| static constexpr std::chrono::duration delay = std::chrono::milliseconds(1); |
| }; |
| |
| } // namespace estoraged |