1 #include "util.hpp" 2 3 #include <linux/fs.h> 4 5 #include <phosphor-logging/lg2.hpp> 6 #include <stdplus/fd/create.hpp> 7 #include <stdplus/fd/managed.hpp> 8 #include <stdplus/handle/managed.hpp> 9 #include <xyz/openbmc_project/Common/error.hpp> 10 11 #include <string_view> 12 13 namespace estoraged 14 { 15 namespace util 16 { 17 using ::sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; 18 using ::stdplus::fd::ManagedFd; 19 20 uint64_t Util::findSizeOfBlockDevice(const std::string& devPath) 21 { 22 ManagedFd fd; 23 uint64_t bytes = 0; 24 try 25 { 26 // open block dev 27 fd = stdplus::fd::open(devPath, stdplus::fd::OpenAccess::ReadOnly); 28 // get block size 29 fd.ioctl(BLKGETSIZE64, &bytes); 30 } 31 catch (...) 32 { 33 lg2::error("erase unable to open blockdev", "REDFISH_MESSAGE_ID", 34 std::string("OpenBMC.0.1.DriveEraseFailure"), 35 "REDFISH_MESSAGE_ARGS", std::to_string(fd.get())); 36 throw InternalFailure(); 37 } 38 return bytes; 39 } 40 41 } // namespace util 42 43 } // namespace estoraged 44