Not passing fd in the zero and pattern erase

The original erase zero, and erase pattern methods took fd that were
opened by the client code. This changes make zero and pattern open the
files internally, which is safe and a more standard practice.

Tested: This change has not been tested

Change-Id: Iae848429b304aa39d510d1f090ace416db88ac7e
Signed-off-by: John Edward Broadbent <jebr@google.com>
diff --git a/src/erase/pattern.cpp b/src/erase/pattern.cpp
index 649bd37..6fb08a7 100644
--- a/src/erase/pattern.cpp
+++ b/src/erase/pattern.cpp
@@ -22,13 +22,17 @@
 using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
 using stdplus::fd::ManagedFd;
 
-void Pattern::writePattern(const uint64_t driveSize, ManagedFd& fd)
+void Pattern::writePattern(const uint64_t driveSize)
 {
     // static seed defines a fixed prng sequnce so it can be verified later,
     // and validated for entropy
     uint64_t currentIndex = 0;
     std::minstd_rand0 generator(seed);
     std::array<std::byte, blockSize> randArr;
+
+    ManagedFd fd =
+        stdplus::fd::open(devPath, stdplus::fd::OpenAccess::WriteOnly);
+
     while (currentIndex < driveSize)
     {
         // generate a 4k block of prng
@@ -54,13 +58,17 @@
     }
 }
 
-void Pattern::verifyPattern(const uint64_t driveSize, ManagedFd& fd)
+void Pattern::verifyPattern(const uint64_t driveSize)
 {
 
     uint64_t currentIndex = 0;
     std::minstd_rand0 generator(seed);
     std::array<std::byte, blockSize> randArr;
     std::array<std::byte, blockSize> readArr;
+
+    ManagedFd fd =
+        stdplus::fd::open(devPath, stdplus::fd::OpenAccess::ReadOnly);
+
     while (currentIndex < driveSize)
     {
         size_t readSize = currentIndex + blockSize < driveSize
diff --git a/src/erase/zero.cpp b/src/erase/zero.cpp
index accb8c8..2c0d615 100644
--- a/src/erase/zero.cpp
+++ b/src/erase/zero.cpp
@@ -16,9 +16,12 @@
 using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
 using stdplus::fd::ManagedFd;
 
-void Zero::writeZero(const uint64_t driveSize, ManagedFd& fd)
+void Zero::writeZero(const uint64_t driveSize)
 {
 
+    ManagedFd fd =
+        stdplus::fd::open(devPath, stdplus::fd::OpenAccess::WriteOnly);
+
     uint64_t currentIndex = 0;
     const std::array<const std::byte, blockSize> blockOfZeros{};
 
@@ -42,8 +45,11 @@
     }
 }
 
-void Zero::verifyZero(uint64_t driveSize, ManagedFd& fd)
+void Zero::verifyZero(uint64_t driveSize)
 {
+    ManagedFd fd =
+        stdplus::fd::open(devPath, stdplus::fd::OpenAccess::ReadOnly);
+
     uint64_t currentIndex = 0;
     std::array<std::byte, blockSize> readArr;
     const std::array<const std::byte, blockSize> blockOfZeros{};