17#ifndef MBED_TDBSTORE_H
18#define MBED_TDBSTORE_H
22#include "kvstore/KVStore.h"
23#include "blockdevice/BlockDevice.h"
24#include "blockdevice/BufferedBlockDevice.h"
25#include "rtos/Mutex.h"
26#include "mbed_error.h"
48 static const uint32_t RESERVED_AREA_SIZE = 64;
107 virtual int set(
const char *key,
const void *buffer,
size_t size, uint32_t create_flags);
126 virtual int get(
const char *key,
void *buffer,
size_t buffer_size,
size_t *actual_size = NULL,
179 virtual int set_start(set_handle_t *handle,
const char *key,
size_t final_data_size, uint32_t create_flags);
195 virtual int set_add_data(set_handle_t handle,
const void *value_data,
size_t data_size);
284 size_t *actual_data_size = 0);
286#if !defined(DOXYGEN_ONLY)
292 } tdbstore_area_data_t;
294 static const int _num_areas = 2;
295 static const int _max_open_iterators = 16;
304 uint32_t _free_space_offset;
305 uint32_t _master_record_offset;
306 uint32_t _master_record_size;
307 bool _is_initialized;
309 uint16_t _active_area_version;
311 tdbstore_area_data_t _area_params[_num_areas];
314 size_t _work_buf_size;
316 void *_inc_set_handle;
317 void *_iterator_table[_max_open_iterators];
329 int read_area(uint8_t area, uint32_t offset, uint32_t size,
void *buf);
341 int write_area(uint8_t area, uint32_t offset, uint32_t size,
const void *buf);
352 int reset_area(uint8_t area);
363 int erase_area(uint8_t area, uint32_t offset, uint32_t size);
368 void calc_area_params();
390 int read_record(uint8_t area, uint32_t offset,
char *key,
391 void *data_buf, uint32_t data_buf_size,
392 uint32_t &actual_data_size,
size_t data_offset,
bool copy_key,
393 bool copy_data,
bool check_expected_key,
bool calc_hash,
394 uint32_t &hash, uint32_t &flags, uint32_t &next_offset);
405 int write_master_record(uint8_t area, uint16_t version, uint32_t &next_offset);
417 int copy_record(uint8_t from_area, uint32_t from_offset, uint32_t to_offset,
418 uint32_t &to_next_offset);
425 int garbage_collection();
435 uint32_t record_size(
const char *key, uint32_t data_size);
448 int find_record(uint8_t area,
const char *key, uint32_t &offset,
449 uint32_t &ram_table_ind, uint32_t &hash);
462 int do_get(
const char *key,
bool copy_data,
463 void *data_buf, uint32_t data_buf_size, uint32_t &actual_data_size,
476 int do_set(
const char *key,
const void *data_buf, uint32_t data_buf_size, uint32_t flags);
483 int build_ram_table();
492 int increment_max_keys(
void **ram_table = 0);
504 void offset_in_erase_unit(uint8_t area, uint32_t offset, uint32_t &offset_from_start,
505 uint32_t &dist_to_end);
518 int check_erase_before_write(uint8_t area, uint32_t offset, uint32_t size,
519 bool force_check =
false);
537 int do_reserved_data_get(
void *reserved_data,
size_t reserved_data_buf_size,
538 size_t *actual_data_size = 0,
void *copy_trailer = 0);
548 void update_all_iterators(
bool added, uint32_t ram_table_ind);
A hardware device capable of writing and reading blocks.
Block device which allows minimal read and program sizes (of 1) for the underlying BD using a buffer ...
Tiny Database Storage (TDBStore) is a lightweight module that stores data on flash storage.
TDBStore(BlockDevice *bd)
Class constructor.
virtual int get_info(const char *key, info_t *info)
Get information of a given key.
virtual int iterator_open(iterator_t *it, const char *prefix=NULL)
Start an iteration over KVStore keys.
virtual int remove(const char *key)
Remove a TDBStore item by given key.
virtual int iterator_next(iterator_t it, char *key, size_t key_size)
Get next key in iteration.
virtual ~TDBStore()
Class destructor.
virtual int set_finalize(set_handle_t handle)
Finalize an incremental KVStore set sequence.
virtual int set(const char *key, const void *buffer, size_t size, uint32_t create_flags)
Set one TDBStore item, given key and value.
virtual int iterator_close(iterator_t it)
Close iteration.
virtual int set_start(set_handle_t *handle, const char *key, size_t final_data_size, uint32_t create_flags)
Start an incremental TDBStore set sequence.
virtual int deinit()
Deinitialize TDBStore, release and free resources.
virtual int reset()
Reset TDBStore contents (clear all keys) and reserved data.
virtual int get(const char *key, void *buffer, size_t buffer_size, size_t *actual_size=NULL, size_t offset=0)
Get one TDBStore item by given key.
virtual int reserved_data_get(void *reserved_data, size_t reserved_data_buf_size, size_t *actual_data_size=0)
Get data from reserved area, which is a special location for special data, such as ROT.
virtual int set_add_data(set_handle_t handle, const void *value_data, size_t data_size)
Add data to incremental TDBStore set sequence.
virtual int init()
Initialize TDBStore.
virtual int reserved_data_set(const void *reserved_data, size_t reserved_data_buf_size)
Set data in reserved area, which is a special location for special data, such as ROT.
The Mutex class is used to synchronize the execution of threads.