blob: 87de2b9e994afed089617bfeec3e0c07aafe1d04 [file] [log] [blame]
Deepak Kodihallib6a446f2017-04-29 13:01:49 -05001#include "mboxd_pnor_partition_table.h"
2#include "mbox.h"
3#include "pnor_partition_table.hpp"
Ratan Gupta3214b512017-05-11 08:58:19 +05304#include <experimental/filesystem>
Deepak Kodihallib6a446f2017-04-29 13:01:49 -05005
6struct vpnor_partition_table
7{
8 openpower::virtual_pnor::partition::Table* table = nullptr;
9};
10
11void vpnor_create_partition_table(struct mbox_context *context)
12{
Ratan Gupta3214b512017-05-11 08:58:19 +053013 if (context && !context->vpnor)
Deepak Kodihallib6a446f2017-04-29 13:01:49 -050014 {
Ratan Gupta3214b512017-05-11 08:58:19 +053015 context->vpnor = new vpnor_partition_table;
16 context->vpnor->table =
17 new openpower::virtual_pnor::partition::Table;
18 }
19}
20
21void 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 Kodihallib6a446f2017-04-29 13:01:49 -050031 }
32}
33
34size_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
40const 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
47const 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
55void 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}