blob: 5de96d6d3f493737de624bf192d9759419df717b [file] [log] [blame]
John Edward Broadbente6ffe702021-10-14 14:03:11 -07001#include "erase.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>
John Wedig972c3fa2021-12-29 17:30:41 -08009#include <xyz/openbmc_project/Common/error.hpp>
John Edward Broadbente6ffe702021-10-14 14:03:11 -070010
John Wedig972c3fa2021-12-29 17:30:41 -080011using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
John Edward Broadbente6ffe702021-10-14 14:03:11 -070012using stdplus::fd::ManagedFd;
13
14uint64_t Erase::findSizeOfBlockDevice()
15{
16 ManagedFd fd;
17 uint64_t bytes;
18 try
19 {
20 // open block dev
21 fd = stdplus::fd::open(devPath, stdplus::fd::OpenAccess::ReadOnly);
22 // get block size
23 fd.ioctl(BLKGETSIZE64, &bytes);
24 }
25 catch (...)
26 {
27 lg2::error("erase unable to open blockdev", "REDFISH_MESSAGE_ID",
28 std::string("OpenBMC.0.1.DriveEraseFailure"),
29 "REDFISH_MESSAGE_ARGS", std::to_string(fd.get()));
John Wedig972c3fa2021-12-29 17:30:41 -080030 throw InternalFailure();
John Edward Broadbente6ffe702021-10-14 14:03:11 -070031 }
32 return bytes;
33}