blob: 5de96d6d3f493737de624bf192d9759419df717b [file] [log] [blame]
#include "erase.hpp"
#include <linux/fs.h>
#include <phosphor-logging/lg2.hpp>
#include <stdplus/fd/create.hpp>
#include <stdplus/fd/managed.hpp>
#include <stdplus/handle/managed.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
using stdplus::fd::ManagedFd;
uint64_t Erase::findSizeOfBlockDevice()
{
ManagedFd fd;
uint64_t bytes;
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;
}