blob: 1aaa1fb38dea13eb4e0e7d261b81411abf358e0c [file] [log] [blame]
Andrew Jeffery812923d2018-02-22 11:59:52 +10301// SPDX-License-Identifier: Apache-2.0
2// Copyright (C) 2018 IBM Corp.
3
Andrew Jeffery30bcf842018-03-26 12:13:20 +10304#include "vpnor/test/tmpd.hpp"
Andrew Jeffery812923d2018-02-22 11:59:52 +10305
6namespace openpower
7{
8namespace virtual_pnor
9{
10namespace test
11{
12
13namespace fs = std::experimental::filesystem;
14
15size_t VpnorRoot::write(const std::string &name, const void *data, size_t len)
16{
Andrew Jeffery097495c2018-02-22 11:36:13 +103017 // write() is for test environment setup - always write to ro section
18 fs::path path = root / "ro" / name;
Andrew Jeffery812923d2018-02-22 11:59:52 +103019
20 if (!fs::exists(path))
21 /* It's not in the ToC */
22 throw std::invalid_argument(name);
23
Andrew Jeffery097495c2018-02-22 11:36:13 +103024 std::ofstream(path).write((const char *)data, len);
Andrew Jeffery812923d2018-02-22 11:59:52 +103025
26 return len;
27}
28
Andrew Jeffery2a4bee72018-03-01 15:49:17 +103029size_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 Jeffery7a03b072018-09-05 17:34:49 +093040} // namespace test
41} // namespace virtual_pnor
42} // namespace openpower