| 155 | } |
| 156 | |
| 157 | bool initFileSystem() |
| 158 | { |
| 159 | fileFreeFileSystem(); |
| 160 | |
| 161 | auto initialFreeheap = system_get_free_heap_size(); |
| 162 | debug_i("Initial freeheap = %u", initialFreeheap); |
| 163 | |
| 164 | #ifdef ENABLE_FLASHSTRING_IMAGE |
| 165 | // Create a partition wrapping some flashstring data |
| 166 | auto part = |
| 167 | Storage::progMem.editablePartitions().add(F("fwfsMem"), fwfsImage, Storage::Partition::SubType::Data::fwfs); |
| 168 | #else |
| 169 | auto part = Storage::findDefaultPartition(Storage::Partition::SubType::Data::fwfs); |
| 170 | #endif |
| 171 | |
| 172 | // Read-only |
| 173 | auto fs = IFS::createFirmwareFilesystem(part); |
| 174 | |
| 175 | if(fs == nullptr) { |
| 176 | debug_e("Failed to created filesystem object"); |
| 177 | return false; |
| 178 | } |
| 179 | |
| 180 | auto mount = [&](IFS::FileSystem* fs) { |
| 181 | int res = fs->mount(); |
| 182 | debug_i("heap used: %u, mount() returned %d (%s)", initialFreeheap - system_get_free_heap_size(), res, |
| 183 | fs->getErrorString(res).c_str()); |
| 184 | return res == FS_OK; |
| 185 | }; |
| 186 | |
| 187 | if(!mount(fs)) { |
| 188 | delete fs; |
| 189 | return false; |
| 190 | } |
| 191 | |
| 192 | // Make this the default filesystem |
| 193 | fileSetFileSystem(fs); |
| 194 | |
| 195 | // Let's mount an LFS volume as well |
| 196 | initialFreeheap = system_get_free_heap_size(); |
| 197 | part = Storage::findDefaultPartition(Storage::Partition::SubType::Data::littlefs); |
| 198 | auto lfs = IFS::createLfsFilesystem(part); |
| 199 | if(lfs == nullptr) { |
| 200 | debug_e("Failed to create LFS filesystem"); |
| 201 | } else if(mount(lfs)) { |
| 202 | // Place the root of this volume at index #0 (the corresponding directory is given in `fwimage.fwfs`) |
| 203 | fs->setVolume(0, lfs); |
| 204 | } else { |
| 205 | delete lfs; |
| 206 | } |
| 207 | |
| 208 | // And we'll mount a SPIFFS volume too |
| 209 | initialFreeheap = system_get_free_heap_size(); |
| 210 | part = Storage::findDefaultPartition(Storage::Partition::SubType::Data::spiffs); |
| 211 | auto spiffs = IFS::createSpiffsFilesystem(part); |
| 212 | if(spiffs == nullptr) { |
| 213 | debug_e("Failed to create SPIFFS filesystem"); |
| 214 | } else if(mount(spiffs)) { |
no test coverage detected