xref: /openbmc/hiomapd/vpnor/test/tmpd.cpp (revision 150be912)
1 // SPDX-License-Identifier: Apache-2.0
2 // Copyright (C) 2018 IBM Corp.
3 
4 #include "vpnor/test/tmpd.hpp"
5 
6 namespace openpower
7 {
8 namespace virtual_pnor
9 {
10 namespace test
11 {
12 
13 namespace fs = std::filesystem;
14 
write(const std::string & name,const void * data,size_t len)15 size_t VpnorRoot::write(const std::string& name, const void* data, size_t len)
16 {
17     // write() is for test environment setup - always write to ro section
18     fs::path path = root / "ro" / name;
19 
20     if (!fs::exists(path))
21         /* It's not in the ToC */
22         throw std::invalid_argument(name);
23 
24     std::ofstream(path).write((const char*)data, len);
25 
26     return len;
27 }
28 
patch(const std::string & name,const void * data,size_t len)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 
40 } // namespace test
41 } // namespace virtual_pnor
42 } // namespace openpower
43