Mistake on this page?
Report an issue in GitHub or email us
kvstore_global_api.h
1 /*
2  * Copyright (c) 2018 ARM Limited. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  * Licensed under the Apache License, Version 2.0 (the License); you may
5  * not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef _KVSTORE_STATIC_API
17 #define _KVSTORE_STATIC_API
18 
19 #include "stddef.h"
20 #include "stdint.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 typedef struct _opaque_kv_key_iterator *kv_iterator_t;
27 
28 #define KV_WRITE_ONCE_FLAG (1 << 0)
29 #define KV_REQUIRE_CONFIDENTIALITY_FLAG (1 << 1)
30 #define KV_RESERVED_FLAG (1 << 2)
31 #define KV_REQUIRE_REPLAY_PROTECTION_FLAG (1 << 3)
32 
33 #define KV_MAX_KEY_LENGTH 128
34 
35 /**
36  * The key size
37  */
38 typedef struct info {
39  /**
40  * The key size
41  */
42  size_t size;
43  /*
44  * The Key flags, possible flags combination:
45  * WRITE_ONCE_FLAG,
46  * REQUIRE_CONFIDENTIALITY_FLAG,
47  * REQUIRE_REPLAY_PROTECTION_FLAG
48  */
49  uint32_t flags;
50 } kv_info_t;
51 
52 /**
53  * @brief Set one KVStore item, given key and value.
54  *
55  * @param[in] full_name_key /Partition_path/Key. Must not include '*' '/' '?' ':' ';' '\' '"' '|' ' ' '<' '>' '\'.
56  * @param[in] buffer Value data buffer.
57  * @param[in] size Value data size.
58  * @param[in] create_flags Flag mask.
59  *
60  * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
61  */
62 int kv_set(const char *full_name_key, const void *buffer, size_t size, uint32_t create_flags);
63 
64 /**
65  * @brief Get one KVStore item by given key.
66  *
67  * @param[in] full_name_key /Partition_path/Key. Must not include '*' '/' '?' ':' ';' '\' '"' '|' ' ' '<' '>' '\'.
68  * @param[in] buffer Value data buffer.
69  * @param[in] buffer_size Value data buffer size.
70  * @param[out] actual_size Actual read size.
71  *
72  * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
73  */
74 int kv_get(const char *full_name_key, void *buffer, size_t buffer_size, size_t *actual_size);
75 
76 /**
77  * @brief Get information of a given key.The returned info contains size and flags
78  *
79  * @param[in] full_name_key /Partition_path/Key. Must not include '*' '/' '?' ':' ';' '\' '"' '|' ' ' '<' '>' '\'.
80  * @param[out] info Returned information structure.
81  *
82  * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
83  */
84 int kv_get_info(const char *full_name_key, kv_info_t *info);
85 
86 /**
87  * @brief Remove a KVStore item by given key.
88  *
89  * @param[in] full_name_key /Partition_path/Key. Must not include '*' '/' '?' ':' ';' '\' '"' '|' ' ' '<' '>' '\'.
90  *
91  * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
92  */
93 int kv_remove(const char *full_name_key);
94 
95 /**
96  * @brief Start an iteration over KVStore keys to find all the entries
97  * that fit the full_prefix. There are no issues with any other operations while
98  * iterator is open.
99  *
100  * @param[out] it Allocating iterator handle.
101  * Do not forget to call kv_iterator_close
102  * to deallocate the memory.
103  * @param[in] full_prefix full_prefix Partition/Key prefix. If
104  * empty key or NULL pointer, all keys
105  * will match.
106  *
107  * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
108  */
109 int kv_iterator_open(kv_iterator_t *it, const char *full_prefix);
110 
111 /**
112  * @brief Get next key in iteration that matches the prefix. There are no issues with any
113  * other operations while iterator is open.
114  *
115  * @param[in] it Iterator handle.
116  * @param[in] key Buffer for returned key.
117  * @param[in] key_size Key buffer size.
118  *
119  * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
120  */
121 int kv_iterator_next(kv_iterator_t it, char *key, size_t key_size);
122 
123 /**
124  * @brief Close iteration and deallocate the iterator handle.
125  *
126  * @param[in] it Iterator handle.
127  *
128  * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
129  */
130 int kv_iterator_close(kv_iterator_t it);
131 
132 /**
133  * @brief Remove all keys and related data from a specified partition.
134  *
135  * @param[in] kvstore_path /Partition/
136  *
137  * @returns MBED_SUCCESS on success or an error code from underlying KVStore instances
138  */
139 int kv_reset(const char *kvstore_path);
140 
141 #ifdef __cplusplus
142 } // closing brace for extern "C"
143 #endif
144 #endif
size_t size
The key size.
The key size.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.