John Edward Broadbent | e6ffe70 | 2021-10-14 14:03:11 -0700 | [diff] [blame^] | 1 | #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 | |
| 11 | using sdbusplus::xyz::openbmc_project::eStoraged::Error::EraseError; |
| 12 | using stdplus::fd::ManagedFd; |
| 13 | |
| 14 | uint64_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 | } |