arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
VFS_LittleFS.h
1#pragma once
2#include <string.h>
3#include <sys/stat.h>
4#include <sys/unistd.h>
5
6#include "AudioTools/Disk/VFS.h"
7#include "esp_err.h"
8#include "esp_littlefs.h"
9#include "esp_system.h"
10
11namespace audio_tools {
12
22class VFS_LittleFS : public VFS {
23 public:
24 VFS_LittleFS(const char* mountPoint = "/littlefs") {
25 mount_point = mountPoint;
26 };
27 void setMountPoint(const char* mp) { mount_point = mp; }
28 bool begin() {
29 LOGI("Initializing LittleFS");
30
31 esp_vfs_littlefs_conf_t conf = {
32 .base_path = mount_point,
33 .partition_label = "storage",
34 .format_if_mount_failed = format_if_mount_failed,
35 .dont_mount = false,
36 };
37
38 // Use settings defined above to initialize and mount LittleFS filesystem.
39 // Note: esp_vfs_littlefs_register is an all-in-one convenience function.
40 esp_err_t ret = esp_vfs_littlefs_register(&conf);
41
42 if (ret != ESP_OK) {
43 if (ret == ESP_FAIL) {
44 LOGE("Failed to mount or format filesystem");
45 } else if (ret == ESP_ERR_NOT_FOUND) {
46 LOGE("Failed to find LittleFS partition");
47 } else {
48 LOGE("Failed to initialize LittleFS (%s)", esp_err_to_name(ret));
49 }
50 return false;
51 }
52
53 size_t total = 0, used = 0;
54 ret = esp_littlefs_info(conf.partition_label, &total, &used);
55 if (ret != ESP_OK) {
56 LOGE("Failed to get LittleFS partition information (%s)",
57 esp_err_to_name(ret));
58 // esp_littlefs_format(conf.partition_label);
59 return false;
60 } else {
61 LOGI("Partition size: total: %d, used: %d", total, used);
62 }
63
64 return true;
65 }
66
67 void end() {
68 // All done, unmount partition and disable SPIFFS
69 // All done, unmount partition and disable LittleFS
70 esp_vfs_littlefs_unregister(conf.partition_label);
71 LOGI("LittleFS unmounted");
72 }
73
74 protected:
75 esp_vfs_littlefs_conf_t conf;
76 int max_files = 5;
77 bool format_if_mount_failed = true;
78};
79} // namespace audio_tools
ESP32 Virtual File System for the LittleFS. The default mount point is "/littlefs" DRAFT implementati...
Definition VFS_LittleFS.h:22
bool begin()
mount the file systems
Definition VFS_LittleFS.h:28
void setMountPoint(const char *mp)
provide the mount point (root directory for the file system)
Definition VFS_LittleFS.h:27
void end()
unmount the file system
Definition VFS_LittleFS.h:67
Definition VFS.h:16
const char * mountPoint()
provides the actual mount point
Definition VFS.h:55
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10