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

Method open

Sming/Libraries/Spiffs/src/FileSystem.cpp:268–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266}
267
268FileHandle FileSystem::open(const char* path, OpenFlags flags)
269{
270 if(isRootPath(path)) {
271 return Error::BadParam;
272 }
273
274 /*
275 * The file may be marked 'read-only' in its metadata, so avoid modifications
276 * (truncate) during the open phase until this has been checked.
277 */
278
279 spiffs_flags sflags;
280 if(mapFileOpenFlags(flags - OpenFlag::Truncate, sflags).any()) {
281 return FileHandle(Error::NotSupported);
282 }
283
284 auto file = SPIFFS_open(handle(), path, sflags, 0);
285 if(file < 0) {
286 int err = translateSpiffsError(file);
287 debug_ifserr(err, "open('%s')", path);
288 return err;
289 }
290
291 auto smb = initMetaBuffer(file);
292 // If file is marked read-only, fail write requests
293 if(smb != nullptr) {
294 if(flags[OpenFlag::Write] && smb->meta.attr[FileAttribute::ReadOnly]) {
295 SPIFFS_close(handle(), file);
296 return Error::ReadOnly;
297 }
298 }
299
300 // Now truncate the file if so requested
301 if(flags[OpenFlag::Truncate]) {
302 int err = SPIFFS_ftruncate(handle(), file, 0);
303 if(err < 0) {
304 SPIFFS_close(handle(), file);
305 return translateSpiffsError(err);
306 }
307
308 // Update modification timestamp
309 touch(file);
310 }
311
312 return file;
313}
314
315int FileSystem::close(FileHandle file)
316{

Callers 15

handleCommandFunction · 0.45
listSpiffsPartitionsFunction · 0.45
jquery.jsFile · 0.45
jquery.jsFile · 0.45
jquery.jsFile · 0.45
onFileFunction · 0.45
printDirectoryFunction · 0.45
copySomeFilesFunction · 0.45
isVolumeEmptyFunction · 0.45
listAttributesFunction · 0.45
readFileFunction · 0.45
gdb_on_attachFunction · 0.45

Calls 3

mapFileOpenFlagsFunction · 0.85
translateSpiffsErrorFunction · 0.85
anyMethod · 0.80

Tested by

no test coverage detected