Andrew Jeffery | 812923d | 2018-02-22 11:59:52 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
| 3 | |
Andrew Jeffery | 30bcf84 | 2018-03-26 12:13:20 +1030 | [diff] [blame] | 4 | #include "vpnor/test/tmpd.hpp" |
Andrew Jeffery | 812923d | 2018-02-22 11:59:52 +1030 | [diff] [blame] | 5 | |
| 6 | namespace openpower |
| 7 | { |
| 8 | namespace virtual_pnor |
| 9 | { |
| 10 | namespace test |
| 11 | { |
| 12 | |
| 13 | namespace fs = std::experimental::filesystem; |
| 14 | |
| 15 | size_t VpnorRoot::write(const std::string &name, const void *data, size_t len) |
| 16 | { |
Andrew Jeffery | 097495c | 2018-02-22 11:36:13 +1030 | [diff] [blame] | 17 | // write() is for test environment setup - always write to ro section |
| 18 | fs::path path = root / "ro" / name; |
Andrew Jeffery | 812923d | 2018-02-22 11:59:52 +1030 | [diff] [blame] | 19 | |
| 20 | if (!fs::exists(path)) |
| 21 | /* It's not in the ToC */ |
| 22 | throw std::invalid_argument(name); |
| 23 | |
Andrew Jeffery | 097495c | 2018-02-22 11:36:13 +1030 | [diff] [blame] | 24 | std::ofstream(path).write((const char *)data, len); |
Andrew Jeffery | 812923d | 2018-02-22 11:59:52 +1030 | [diff] [blame] | 25 | |
| 26 | return len; |
| 27 | } |
| 28 | |
Andrew Jeffery | 2a4bee7 | 2018-03-01 15:49:17 +1030 | [diff] [blame] | 29 | size_t VpnorRoot::patch(const std::string &name, const void *data, size_t len) |
| 30 | { |
| 31 | if (!fs::exists(root / "ro" / name)) |
| 32 | /* It's not in the ToC */ |
| 33 | throw std::invalid_argument(name); |
| 34 | |
| 35 | std::ofstream(root / "patch" / name).write((const char *)data, len); |
| 36 | |
| 37 | return len; |
| 38 | } |
| 39 | |
Andrew Jeffery | 7a03b07 | 2018-09-05 17:34:49 +0930 | [diff] [blame] | 40 | } // namespace test |
| 41 | } // namespace virtual_pnor |
| 42 | } // namespace openpower |