blob: 562b8cea4111bc0cac387a8d7cf564b7c84e5d46 [file] [log] [blame]
John Edward Broadbent4bc8a102021-12-30 16:11:49 -08001#pragma once
2
3#include "erase.hpp"
John Edward Broadbenta6e3b992022-03-17 14:33:15 -07004#include "util.hpp"
John Edward Broadbent4bc8a102021-12-30 16:11:49 -08005
6#include <stdplus/fd/create.hpp>
7#include <stdplus/fd/managed.hpp>
8
9namespace estoraged
10{
11
12using stdplus::fd::ManagedFd;
13
14class 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 Broadbent4bc8a102021-12-30 16:11:49 -080023 /** @brief writes zero to the drive
24 * and throws errors accordingly.
John Edward Broadbenta6e3b992022-03-17 14:33:15 -070025 * @param[in] driveSize - the size of the block device in bytes
John Edward Broadbent4bc8a102021-12-30 16:11:49 -080026 */
John Edward Broadbent69786762022-01-21 14:16:23 -080027 void writeZero(uint64_t driveSize);
John Edward Broadbent4bc8a102021-12-30 16:11:49 -080028
John Edward Broadbenta6e3b992022-03-17 14:33:15 -070029 /** @brief writes zero to the drive
30 * and throws errors accordingly.
31 */
32 void writeZero()
33 {
John Edward Broadbent5d799bb2022-03-22 16:14:24 -070034 writeZero(util::findSizeOfBlockDevice(devPath));
John Edward Broadbenta6e3b992022-03-17 14:33:15 -070035 }
36
John Edward Broadbent4bc8a102021-12-30 16:11:49 -080037 /** @brief verifies the uncompressible random pattern is on the drive
38 * and throws errors accordingly.
John Edward Broadbenta6e3b992022-03-17 14:33:15 -070039 * @param[in] driveSize - the size of the block device in bytes
John Edward Broadbent4bc8a102021-12-30 16:11:49 -080040 */
John Edward Broadbent69786762022-01-21 14:16:23 -080041 void verifyZero(uint64_t driveSize);
John Edward Broadbent4bc8a102021-12-30 16:11:49 -080042
John Edward Broadbenta6e3b992022-03-17 14:33:15 -070043 /** @brief verifies the uncompressible random pattern is on the drive
44 * and throws errors accordingly.
45 */
46 void verifyZero()
47 {
John Edward Broadbent5d799bb2022-03-22 16:14:24 -070048 verifyZero(util::findSizeOfBlockDevice(devPath));
John Edward Broadbenta6e3b992022-03-17 14:33:15 -070049 }
50
John Edward Broadbent4bc8a102021-12-30 16:11:49 -080051 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