From 750818de72250ba394470ebbad3afbad0e57a843 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 23 Dec 2019 18:20:14 +0100 Subject: [PATCH] spiffs: clarify the usage of partition_label, fix the example * If esp_vfs_spiffs_register is called with an explicit partition label, other SPIFFS functions (info, format, unregister) must be called with the same label. * On the other hand, if label was NULL in the call to esp_vfs_spiffs_register and the first matching partition was used, calls to the rest of the SPIFFS functions should be done with NULL partition_label argument. Fix the Doxygen documentation. Update the example accordingly, in case a user modifies "partition_label" value in esp_vfs_spiffs_conf_t conf initializer. Closes https://github.com/espressif/esp-idf/issues/4450 --- components/spiffs/include/esp_spiffs.h | 9 +++------ examples/storage/spiffs/main/spiffs_example_main.c | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/components/spiffs/include/esp_spiffs.h b/components/spiffs/include/esp_spiffs.h index ae1b9ad43..bd733ac86 100644 --- a/components/spiffs/include/esp_spiffs.h +++ b/components/spiffs/include/esp_spiffs.h @@ -49,8 +49,7 @@ esp_err_t esp_vfs_spiffs_register(const esp_vfs_spiffs_conf_t * conf); /** * Unregister and unmount SPIFFS from VFS * - * @param partition_label Optional, label of the partition to unregister. - * If not specified, first partition with subtype=spiffs is used. + * @param partition_label Same label as passed to esp_vfs_spiffs_register. * * @return * - ESP_OK if successful @@ -73,8 +72,7 @@ bool esp_spiffs_mounted(const char* partition_label); /** * Format the SPIFFS partition * - * @param partition_label Optional, label of the partition to format. - * If not specified, first partition with subtype=spiffs is used. + * @param partition_label Same label as passed to esp_vfs_spiffs_register. * @return * - ESP_OK if successful * - ESP_FAIL on error @@ -84,8 +82,7 @@ esp_err_t esp_spiffs_format(const char* partition_label); /** * Get information for SPIFFS * - * @param partition_label Optional, label of the partition to get info for. - * If not specified, first partition with subtype=spiffs is used. + * @param partition_label Same label as passed to esp_vfs_spiffs_register * @param[out] total_bytes Size of the file system * @param[out] used_bytes Current used bytes in the file system * diff --git a/examples/storage/spiffs/main/spiffs_example_main.c b/examples/storage/spiffs/main/spiffs_example_main.c index 2148139a3..b2fd93bbd 100644 --- a/examples/storage/spiffs/main/spiffs_example_main.c +++ b/examples/storage/spiffs/main/spiffs_example_main.c @@ -43,7 +43,7 @@ void app_main(void) } size_t total = 0, used = 0; - ret = esp_spiffs_info(NULL, &total, &used); + ret = esp_spiffs_info(conf.partition_label, &total, &used); if (ret != ESP_OK) { ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret)); } else { @@ -94,6 +94,6 @@ void app_main(void) ESP_LOGI(TAG, "Read from file: '%s'", line); // All done, unmount partition and disable SPIFFS - esp_vfs_spiffs_unregister(NULL); + esp_vfs_spiffs_unregister(conf.partition_label); ESP_LOGI(TAG, "SPIFFS unmounted"); }