blob: 3b6ce172c29e3d3c9e6b81c0593ece6b04439d2a [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>
9#include <xyz/openbmc_project/eStoraged/error.hpp>
10
11using sdbusplus::xyz::openbmc_project::eStoraged::Error::EraseError;
12using 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()));
30 throw EraseError();
31 }
32 return bytes;
33}