Andrew Jeffery | d083efd | 2018-02-21 21:19:00 +1030 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: Apache-2.0 */ |
| 2 | /* Copyright (C) 2018 IBM Corp. */ |
| 3 | |
| 4 | #include <assert.h> |
| 5 | #include <string.h> |
| 6 | #include <vector> |
| 7 | #include <fstream> |
| 8 | #include <experimental/filesystem> |
| 9 | |
| 10 | #include "config.h" |
| 11 | #include "pnor_partition_table.hpp" |
| 12 | |
| 13 | namespace fs = std::experimental::filesystem; |
| 14 | |
| 15 | namespace openpower |
| 16 | { |
| 17 | namespace virtual_pnor |
| 18 | { |
| 19 | namespace test |
| 20 | { |
| 21 | |
| 22 | template <std::size_t N> |
| 23 | void createVpnorTree(fs::path &root, const std::string (&toc)[N], |
| 24 | size_t blockSize) |
| 25 | { |
| 26 | fs::path tocFilePath{root}; |
| 27 | tocFilePath /= PARTITION_TOC_FILE; |
| 28 | std::ofstream tocFile(tocFilePath.c_str()); |
| 29 | |
| 30 | for (const std::string &line : toc) |
| 31 | { |
| 32 | pnor_partition part; |
| 33 | |
| 34 | openpower::virtual_pnor::parseTocLine(line, blockSize, part); |
| 35 | |
| 36 | /* Populate the partition in the tree */ |
| 37 | fs::path partitionFilePath{root}; |
| 38 | partitionFilePath /= part.data.name; |
| 39 | std::ofstream partitionFile(partitionFilePath.c_str()); |
| 40 | std::vector<char> empty(part.data.size, 0); |
| 41 | partitionFile.write(empty.data(), empty.size()); |
| 42 | partitionFile.close(); |
| 43 | |
| 44 | /* Update the ToC if the partition file was created */ |
| 45 | tocFile.write(line.c_str(), line.length()); |
| 46 | tocFile.write("\n", 1); |
| 47 | } |
| 48 | |
| 49 | tocFile.close(); |
| 50 | } |
| 51 | |
| 52 | } // test |
| 53 | } // virtual_pnor |
| 54 | } // openpower |