summaryrefslogtreecommitdiffstats
path: root/mboxd_pnor_partition_table.cpp
blob: 2464e6c6efde7432379520a94d02fa57951391ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "mboxd_pnor_partition_table.h"
#include "mbox.h"
#include "pnor_partition_table.hpp"
#include <experimental/filesystem>

struct vpnor_partition_table
{
    openpower::virtual_pnor::partition::Table* table = nullptr;
};

void vpnor_create_partition_table(struct mbox_context *context)
{
    if (context && !context->vpnor)
    {
        context->vpnor = new vpnor_partition_table;
        context->vpnor->table =
            new openpower::virtual_pnor::partition::Table(
                    1 << context->erase_size_shift,
                    context->flash_size);
    }
}

void vpnor_create_partition_table_from_path(struct mbox_context *context,
                                            const char *path)
{
    std::experimental::filesystem::path dir(path);

    if (context && !context->vpnor)
    {
        context->vpnor = new vpnor_partition_table;
        context->vpnor->table =
            new openpower::virtual_pnor::partition::Table(
                    std::move(dir),
                    1 << context->erase_size_shift,
                    context->flash_size);
    }
}

size_t vpnor_get_partition_table_size(const struct mbox_context *context)
{
    return context && context->vpnor ?
        context->vpnor->table->size() : 0;
}

const struct pnor_partition_table* vpnor_get_partition_table(
                                       const struct mbox_context *context)
{
    return context && context->vpnor ?
        &(context->vpnor->table->getHostTable()) : nullptr;
}

const struct pnor_partition* vpnor_get_partition(
                                 const struct mbox_context *context,
                                 const size_t offset)
{
    return context && context->vpnor ?
        &(context->vpnor->table->partition(offset)) : nullptr;
}

void vpnor_destroy_partition_table(struct mbox_context *context)
{
    if(context && context->vpnor)
    {
        delete context->vpnor->table;
        delete context->vpnor;
        context->vpnor = nullptr;
    }
}
OpenPOWER on IntegriCloud