Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 1 | #include "mboxd_pnor_partition_table.h" |
| 2 | #include "mbox.h" |
| 3 | #include "pnor_partition_table.hpp" |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 4 | #include <experimental/filesystem> |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 5 | |
| 6 | struct vpnor_partition_table |
| 7 | { |
| 8 | openpower::virtual_pnor::partition::Table* table = nullptr; |
| 9 | }; |
| 10 | |
| 11 | void vpnor_create_partition_table(struct mbox_context *context) |
| 12 | { |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 13 | if (context && !context->vpnor) |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 14 | { |
Ratan Gupta | 3214b51 | 2017-05-11 08:58:19 +0530 | [diff] [blame] | 15 | context->vpnor = new vpnor_partition_table; |
| 16 | context->vpnor->table = |
| 17 | new openpower::virtual_pnor::partition::Table; |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | void vpnor_create_partition_table_from_path(struct mbox_context *context, |
| 22 | const char *path) |
| 23 | { |
| 24 | std::experimental::filesystem::path dir(path); |
| 25 | |
| 26 | if (context && !context->vpnor) |
| 27 | { |
| 28 | context->vpnor = new vpnor_partition_table; |
| 29 | context->vpnor->table = |
| 30 | new openpower::virtual_pnor::partition::Table(std::move(dir)); |
Deepak Kodihalli | b6a446f | 2017-04-29 13:01:49 -0500 | [diff] [blame] | 31 | } |
| 32 | } |
| 33 | |
| 34 | size_t vpnor_get_partition_table_size(const struct mbox_context *context) |
| 35 | { |
| 36 | return context && context->vpnor ? |
| 37 | context->vpnor->table->size() : 0; |
| 38 | } |
| 39 | |
| 40 | const struct pnor_partition_table* vpnor_get_partition_table( |
| 41 | const struct mbox_context *context) |
| 42 | { |
| 43 | return context && context->vpnor ? |
| 44 | &(context->vpnor->table->getHostTable()) : nullptr; |
| 45 | } |
| 46 | |
| 47 | const struct pnor_partition* vpnor_get_partition( |
| 48 | const struct mbox_context *context, |
| 49 | const size_t offset) |
| 50 | { |
| 51 | return context && context->vpnor ? |
| 52 | &(context->vpnor->table->partition(offset)) : nullptr; |
| 53 | } |
| 54 | |
| 55 | void vpnor_destroy_partition_table(struct mbox_context *context) |
| 56 | { |
| 57 | if(context && context->vpnor) |
| 58 | { |
| 59 | delete context->vpnor->table; |
| 60 | delete context->vpnor; |
| 61 | context->vpnor = nullptr; |
| 62 | } |
| 63 | } |