Virgil IoT KIT
storage_hal.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2020 Virgil Security, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // (1) Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // (2) Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in
14 // the documentation and/or other materials provided with the
15 // distribution.
16 //
17 // (3) Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
22 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 // DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
34 
59 #ifndef VS_STORAGE_HAL_H
60 #define VS_STORAGE_HAL_H
61 
63 #include <sys/types.h>
64 
65 #ifdef __cplusplus
66 namespace VirgilIoTKit {
67 extern "C" {
68 #endif
69 
70 #define VS_STORAGE_ELEMENT_ID_MAX (32)
71 
73 
79 
84 typedef void *vs_storage_file_t;
85 
95  vs_storage_impl_data_ctx_t storage_ctx);
96 
105  const vs_storage_impl_data_ctx_t storage_ctx,
106  const vs_storage_element_id_t id);
107 
118  const vs_storage_impl_data_ctx_t storage_ctx,
119  const vs_storage_file_t file);
120 
131  const vs_storage_impl_data_ctx_t storage_ctx,
132  vs_storage_file_t file);
133 
145  const vs_storage_impl_data_ctx_t storage_ctx,
146  const vs_storage_file_t file,
147  size_t offset,
148  const uint8_t *in_data,
149  size_t data_sz);
150 
162  const vs_storage_impl_data_ctx_t storage_ctx,
163  const vs_storage_file_t file,
164  size_t offset,
165  uint8_t *out_data,
166  size_t data_sz);
167 
175 typedef ssize_t (*vs_storage_file_size_hal_t)(
176  const vs_storage_impl_data_ctx_t storage_ctx,
177  const vs_storage_element_id_t id);
178 
187  const vs_storage_impl_data_ctx_t storage_ctx,
188  const vs_storage_element_id_t id);
189 
197 vs_impl_own_firmware_descriptor(void *descriptor);
198 
203 typedef struct {
216 
221 typedef struct {
224  size_t file_sz_limit;
227 
228 #ifdef __cplusplus
229 } // extern "C"
230 } // namespace VirgilIoTKit
231 #endif
232 
233 #endif //VS_STORAGE_HAL_H
vs_status_e
vs_status_e
Status code.
Definition: status_code.h:77
vs_storage_file_t
void * vs_storage_file_t
File descriptor.
Definition: storage_hal.h:84
vs_rpi_storage_sync_t
vs_status_e(* vs_rpi_storage_sync_t)(const vs_storage_impl_data_ctx_t storage_ctx, const vs_storage_file_t file)
Synchronise storage element.
Definition: storage_hal.h:117
VS_STORAGE_ELEMENT_ID_MAX
#define VS_STORAGE_ELEMENT_ID_MAX
Definition: storage_hal.h:70
vs_storage_impl_func_t::open
vs_storage_open_hal_t open
Open storage element.
Definition: storage_hal.h:206
vs_storage_open_hal_t
vs_storage_file_t(* vs_storage_open_hal_t)(const vs_storage_impl_data_ctx_t storage_ctx, const vs_storage_element_id_t id)
Open storage element.
Definition: storage_hal.h:104
vs_storage_impl_func_t::deinit
vs_storage_deinit_hal_t deinit
Destroy storage context.
Definition: storage_hal.h:204
vs_storage_file_size_hal_t
ssize_t(* vs_storage_file_size_hal_t)(const vs_storage_impl_data_ctx_t storage_ctx, const vs_storage_element_id_t id)
Get storage element size.
Definition: storage_hal.h:175
vs_impl_own_firmware_descriptor
vs_status_e vs_impl_own_firmware_descriptor(void *descriptor)
Load currently executed firmware descriptor.
vs_storage_op_ctx_t::impl_data
vs_storage_impl_data_ctx_t impl_data
Storage element specific data.
Definition: storage_hal.h:223
vs_storage_element_id_t
uint8_t vs_storage_element_id_t[VS_STORAGE_ELEMENT_ID_MAX]
Definition: storage_hal.h:72
vs_storage_impl_data_ctx_t
void * vs_storage_impl_data_ctx_t
File context.
Definition: storage_hal.h:78
vs_storage_op_ctx_t::impl_func
vs_storage_impl_func_t impl_func
Implementations.
Definition: storage_hal.h:222
vs_storage_del_hal_t
vs_status_e(* vs_storage_del_hal_t)(const vs_storage_impl_data_ctx_t storage_ctx, const vs_storage_element_id_t id)
Delete storage element.
Definition: storage_hal.h:186
vs_storage_load_hal_t
vs_status_e(* vs_storage_load_hal_t)(const vs_storage_impl_data_ctx_t storage_ctx, const vs_storage_file_t file, size_t offset, uint8_t *out_data, size_t data_sz)
Load storage element.
Definition: storage_hal.h:161
status_code.h
Status codes and macroses.
vs_storage_impl_func_t::size
vs_storage_file_size_hal_t size
Get storage element size.
Definition: storage_hal.h:212
vs_storage_op_ctx_t::file_sz_limit
size_t file_sz_limit
Maximum size of storage element.
Definition: storage_hal.h:224
vs_storage_impl_func_t::sync
vs_rpi_storage_sync_t sync
Synchronize storage element cache with storage.
Definition: storage_hal.h:207
vs_storage_impl_func_t::save
vs_storage_save_hal_t save
Save storage element.
Definition: storage_hal.h:210
vs_storage_impl_func_t::del
vs_storage_del_hal_t del
Delete storage element.
Definition: storage_hal.h:214
vs_storage_op_ctx_t
Storage element context.
Definition: storage_hal.h:221
vs_storage_deinit_hal_t
vs_status_e(* vs_storage_deinit_hal_t)(vs_storage_impl_data_ctx_t storage_ctx)
Destroy storage context.
Definition: storage_hal.h:94
vs_storage_save_hal_t
vs_status_e(* vs_storage_save_hal_t)(const vs_storage_impl_data_ctx_t storage_ctx, const vs_storage_file_t file, size_t offset, const uint8_t *in_data, size_t data_sz)
Save storage element.
Definition: storage_hal.h:144
vs_storage_close_hal_t
vs_status_e(* vs_storage_close_hal_t)(const vs_storage_impl_data_ctx_t storage_ctx, vs_storage_file_t file)
Close storage element.
Definition: storage_hal.h:130
vs_storage_impl_func_t::load
vs_storage_load_hal_t load
Load storage element.
Definition: storage_hal.h:211
vs_storage_impl_func_t::close
vs_storage_close_hal_t close
Close storage element.
Definition: storage_hal.h:208
vs_storage_impl_func_t
Storage implementation.
Definition: storage_hal.h:203