components/nvs: add erase function

This change exposes functions to erase single key and to erase all keys from namespace.
TW6769, TW6839
This commit is contained in:
Ivan Grokhotkov
2016-09-23 00:36:53 +08:00
parent e87d80d478
commit 2a68f60874
7 changed files with 125 additions and 30 deletions

View File

@@ -103,6 +103,36 @@ extern "C" void nvs_close(nvs_handle handle)
s_nvs_handles.erase(it);
}
extern "C" esp_err_t nvs_erase_key(nvs_handle handle, const char* key)
{
Lock lock;
NVS_DEBUGV("%s %s\r\n", __func__, key);
HandleEntry entry;
auto err = nvs_find_ns_handle(handle, entry);
if (err != ESP_OK) {
return err;
}
if (entry.mReadOnly) {
return ESP_ERR_NVS_READ_ONLY;
}
return s_nvs_storage.eraseItem(entry.mNsIndex, key);
}
extern "C" esp_err_t nvs_erase_all(nvs_handle handle)
{
Lock lock;
NVS_DEBUGV("%s\r\n", __func__);
HandleEntry entry;
auto err = nvs_find_ns_handle(handle, entry);
if (err != ESP_OK) {
return err;
}
if (entry.mReadOnly) {
return ESP_ERR_NVS_READ_ONLY;
}
return s_nvs_storage.eraseNamespace(entry.mNsIndex);
}
template<typename T>
static esp_err_t nvs_set(nvs_handle handle, const char* key, T value)
{