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> |
John Wedig | 972c3fa | 2021-12-29 17:30:41 -0800 | [diff] [blame] | 9 | #include <xyz/openbmc_project/Common/error.hpp> |
John Edward Broadbent | e6ffe70 | 2021-10-14 14:03:11 -0700 | [diff] [blame] | 10 | |
John Edward Broadbent | d3bfa7b | 2022-01-13 17:41:32 -0800 | [diff] [blame] | 11 | namespace estoraged |
| 12 | { |
| 13 | |
John Wedig | 972c3fa | 2021-12-29 17:30:41 -0800 | [diff] [blame] | 14 | using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
John Edward Broadbent | e6ffe70 | 2021-10-14 14:03:11 -0700 | [diff] [blame] | 15 | using stdplus::fd::ManagedFd; |
| 16 | |
| 17 | uint64_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 Wedig | 972c3fa | 2021-12-29 17:30:41 -0800 | [diff] [blame] | 33 | throw InternalFailure(); |
John Edward Broadbent | e6ffe70 | 2021-10-14 14:03:11 -0700 | [diff] [blame] | 34 | } |
| 35 | return bytes; |
| 36 | } |
John Edward Broadbent | d3bfa7b | 2022-01-13 17:41:32 -0800 | [diff] [blame] | 37 | |
| 38 | } // namespace estoraged |