#include "util.hpp" #include #include #include #include #include #include #include namespace estoraged { namespace util { using ::sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; using ::stdplus::fd::ManagedFd; uint64_t Util::findSizeOfBlockDevice(const std::string& devPath) { ManagedFd fd; uint64_t bytes = 0; try { // open block dev fd = stdplus::fd::open(devPath, stdplus::fd::OpenAccess::ReadOnly); // get block size fd.ioctl(BLKGETSIZE64, &bytes); } catch (...) { lg2::error("erase unable to open blockdev", "REDFISH_MESSAGE_ID", std::string("OpenBMC.0.1.DriveEraseFailure"), "REDFISH_MESSAGE_ARGS", std::to_string(fd.get())); throw InternalFailure(); } return bytes; } } // namespace util } // namespace estoraged