Virgil IoT KIT
Data Structures | Macros | Typedefs | Functions
storage_hal.h File Reference

Storage HAL interface. More...

#include <virgil/iot/status_code/status_code.h>
#include <sys/types.h>

Go to the source code of this file.

Data Structures

struct  vs_storage_impl_func_t
 Storage implementation. More...
 
struct  vs_storage_op_ctx_t
 Storage element context. More...
 

Macros

#define VS_STORAGE_ELEMENT_ID_MAX   (32)
 

Typedefs

typedef uint8_t vs_storage_element_id_t[VS_STORAGE_ELEMENT_ID_MAX]
 
typedef void * vs_storage_impl_data_ctx_t
 File context. More...
 
typedef void * vs_storage_file_t
 File descriptor. More...
 
typedef vs_status_e(* vs_storage_deinit_hal_t) (vs_storage_impl_data_ctx_t storage_ctx)
 Destroy storage context. More...
 
typedef 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. More...
 
typedef 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. More...
 
typedef 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. More...
 
typedef 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. More...
 
typedef 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. More...
 
typedef 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. More...
 
typedef 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. More...
 

Functions

vs_status_e vs_impl_own_firmware_descriptor (void *descriptor)
 Load currently executed firmware descriptor. More...
 

Detailed Description

Storage HAL interface.

Storage is the base helper for communication with file system. Cache mechanism can be used.

Storage HAL Usage

Storage context vs_storage_op_ctx_t has storage specific data and calls implementation.

Warning
vs_storage_op_ctx_t has to be implemented by user. You can see an example of Storage context implementation for *NIX systems in vs_nix_storage_impl_func() in storage-nix-impl.c

Implementation has members listed below :

Macro Definition Documentation

◆ VS_STORAGE_ELEMENT_ID_MAX

#define VS_STORAGE_ELEMENT_ID_MAX   (32)

Typedef Documentation

◆ vs_rpi_storage_sync_t

typedef 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.

Synchronizes storage element cache with storage.

Parameters
[in]storage_ctxStorage context. Cannot be NULL.
[in]fileStorage file context.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_storage_close_hal_t

typedef 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.

Warning
After this call the file is rendered unavailable and must be reopened.
Parameters
[in]storage_ctxStorage context. Cannot be NULL.
[in]fileStorage file context.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_storage_deinit_hal_t

typedef vs_status_e(* vs_storage_deinit_hal_t) (vs_storage_impl_data_ctx_t storage_ctx)

Destroy storage context.

This function is called during current storage context destruction. After this call storage_ctx is rendered unavailable and must be zeroed.

Parameters
[in]storage_ctxStorage context. Cannot be NULL.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_storage_del_hal_t

typedef 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.

Parameters
[in]storage_ctxStorage context. Cannot be NULL.
[in]idStorage element identifier.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_storage_element_id_t

typedef uint8_t vs_storage_element_id_t[VS_STORAGE_ELEMENT_ID_MAX]

◆ vs_storage_file_size_hal_t

typedef 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.

Parameters
[in]storage_ctxStorage context. Cannot be NULL.
[in]idStorage element identifier.
Returns
File size if not negative, vs_status_e code if any error

◆ vs_storage_file_t

typedef void* vs_storage_file_t

File descriptor.

File descriptor depends on storage implementation

◆ vs_storage_impl_data_ctx_t

File context.

This context is generated by user call of vs_storage_hal_ctx_t vs_storage_xxx_init.

◆ vs_storage_load_hal_t

typedef 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.

Parameters
[in]storage_ctxStorage context. Cannot be NULL.
[in]fileStorage file context.
[in]offsetData offset.
[out]out_dataOutput storage for loaded data. Cannot be NULL.
[in]data_szData size to be loaded. Cannot be zero.
Returns
VS_CODE_OK in case of success or error code.

◆ vs_storage_open_hal_t

typedef 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.

Parameters
[in]storage_ctxStorage context. Cannot be NULL.
[in]id
Returns
Storage specific file descriptor

◆ vs_storage_save_hal_t

typedef 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.

Parameters
[in]storage_ctxStorage context. Cannot be NULL.
[in]fileStorage file context.
[in]offsetSave data offset.
[in]in_dataData to be saved. Cannot be NULL.
[in]data_szData size.
Returns
VS_CODE_OK in case of success or error code.

Function Documentation

◆ vs_impl_own_firmware_descriptor()

vs_status_e vs_impl_own_firmware_descriptor ( void *  descriptor)

Load currently executed firmware descriptor.

Parameters
[out]descriptorOutput buffer to store firmware descriptor. Cannot be NULL.
Returns
VS_CODE_OK in case of success or error code.