blob: 6cd45f212cbf630b6c182d71713428f7f53244d6 [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 Edward Broadbentd3bfa7b2022-01-13 17:41:32 -080011namespace estoraged
12{
13
John Wedig972c3fa2021-12-29 17:30:41 -080014using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
John Edward Broadbente6ffe702021-10-14 14:03:11 -070015using stdplus::fd::ManagedFd;
16
17uint64_t Erase::findSizeOfBlockDevice()
18{
19 ManagedFd fd;
20 uint64_t bytes;
21 try
22 {
23 // open block dev
24 fd = stdplus::fd::open(devPath, stdplus::fd::OpenAccess::ReadOnly);
25 // get block size
26 fd.ioctl(BLKGETSIZE64, &bytes);
27 }
28 catch (...)
29 {
30 lg2::error("erase unable to open blockdev", "REDFISH_MESSAGE_ID",
31 std::string("OpenBMC.0.1.DriveEraseFailure"),
32 "REDFISH_MESSAGE_ARGS", std::to_string(fd.get()));
John Wedig972c3fa2021-12-29 17:30:41 -080033 throw InternalFailure();
John Edward Broadbente6ffe702021-10-14 14:03:11 -070034 }
35 return bytes;
36}
John Edward Broadbentd3bfa7b2022-01-13 17:41:32 -080037
38} // namespace estoraged