MCPcopy Create free account
hub / github.com/SmingHub/Sming / initFileSystem

Function initFileSystem

samples/Basic_IFS/app/application.cpp:157–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155}
156
157bool 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)) {

Callers 1

fstestFunction · 0.85

Calls 14

fileFreeFileSystemFunction · 0.85
findDefaultPartitionFunction · 0.85
fileSetFileSystemFunction · 0.85
createSpiffsFilesystemFunction · 0.85
registerDeviceFunction · 0.85
getFileSystemFunction · 0.85
mountMethod · 0.80
FFunction · 0.50
addMethod · 0.45
c_strMethod · 0.45
getErrorStringMethod · 0.45

Tested by

no test coverage detected