blob: 917fb71ffe33a8a000e00c01600fce54fcfed783 [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
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070015size_t VpnorRoot::write(const std::string& name, const void* data, size_t len)
Andrew Jeffery812923d2018-02-22 11:59:52 +103016{
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
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070024 std::ofstream(path).write((const char*)data, len);
Andrew Jeffery812923d2018-02-22 11:59:52 +103025
26 return len;
27}
28
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070029size_t VpnorRoot::patch(const std::string& name, const void* data, size_t len)
Andrew Jeffery2a4bee72018-03-01 15:49:17 +103030{
31 if (!fs::exists(root / "ro" / name))
32 /* It's not in the ToC */
33 throw std::invalid_argument(name);
34
William A. Kennington IIId5f1d402018-10-11 13:55:04 -070035 std::ofstream(root / "patch" / name).write((const char*)data, len);
Andrew Jeffery2a4bee72018-03-01 15:49:17 +103036
37 return len;
38}
39
Andrew Jeffery7a03b072018-09-05 17:34:49 +093040} // namespace test
41} // namespace virtual_pnor
42} // namespace openpower