Refactor findsize into util away from erase
At first the size was only needed for erase, now it is needed for the
drives interface. The code needed to be refactored to make drive
interface implementation possible.
Signed-off-by: John Edward Broadbent <jebr@google.com>
Change-Id: I0a23ee23a0de3fd89a9e776b4854e8da9a8ff2e4
diff --git a/src/erase/meson.build b/src/erase/meson.build
index d5be948..233fc59 100644
--- a/src/erase/meson.build
+++ b/src/erase/meson.build
@@ -3,7 +3,6 @@
'verifyDriveGeometry.cpp',
'pattern.cpp',
'cryptoErase.cpp',
- 'erase.cpp',
'zero.cpp',
include_directories : eStoraged_headers,
implicit_include_directories: false,
diff --git a/src/estoraged.cpp b/src/estoraged.cpp
index b52a5f4..6285079 100644
--- a/src/estoraged.cpp
+++ b/src/estoraged.cpp
@@ -69,21 +69,19 @@
case EraseMethod::VerifyGeometry:
{
VerifyDriveGeometry myVerifyGeometry(devPath);
- uint64_t size = myVerifyGeometry.findSizeOfBlockDevice();
- myVerifyGeometry.geometryOkay(size);
+ myVerifyGeometry.geometryOkay();
break;
}
case EraseMethod::LogicalOverWrite:
{
Pattern myErasePattern(devPath);
- myErasePattern.writePattern(myErasePattern.findSizeOfBlockDevice());
+ myErasePattern.writePattern();
break;
}
case EraseMethod::LogicalVerify:
{
Pattern myErasePattern(devPath);
- myErasePattern.verifyPattern(
- myErasePattern.findSizeOfBlockDevice());
+ myErasePattern.verifyPattern();
break;
}
case EraseMethod::VendorSanitize:
@@ -93,13 +91,13 @@
case EraseMethod::ZeroOverWrite:
{
Zero myZero(devPath);
- myZero.writeZero(myZero.findSizeOfBlockDevice());
+ myZero.writeZero();
break;
}
case EraseMethod::ZeroVerify:
{
Zero myZero(devPath);
- myZero.verifyZero(myZero.findSizeOfBlockDevice());
+ myZero.verifyZero();
break;
}
case EraseMethod::SecuredLocked:
diff --git a/src/meson.build b/src/meson.build
index 4bb75a2..ed28e88 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -17,6 +17,7 @@
libeStoraged_lib = static_library(
'eStoraged-lib',
'estoraged.cpp',
+ 'util.cpp',
include_directories : eStoraged_headers,
implicit_include_directories: false,
dependencies: [libeStoraged_deps, libeStoragedErase_dep],
diff --git a/src/erase/erase.cpp b/src/util.cpp
similarity index 75%
rename from src/erase/erase.cpp
rename to src/util.cpp
index 40a954e..7200d0a 100644
--- a/src/erase/erase.cpp
+++ b/src/util.cpp
@@ -1,4 +1,4 @@
-#include "erase.hpp"
+#include "util.hpp"
#include <linux/fs.h>
@@ -8,13 +8,16 @@
#include <stdplus/handle/managed.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
+#include <string_view>
+
namespace estoraged
{
+namespace util
+{
+using ::sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
+using ::stdplus::fd::ManagedFd;
-using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
-using stdplus::fd::ManagedFd;
-
-uint64_t Erase::findSizeOfBlockDevice()
+uint64_t Util::findSizeOfBlockDevice(const std::string& devPath)
{
ManagedFd fd;
uint64_t bytes = 0;
@@ -35,4 +38,6 @@
return bytes;
}
+} // namespace util
+
} // namespace estoraged