int LittleFileSystem::file_close(fs_file_t file) { lfs_file_t *f = (lfs_file_t *)file; _mutex.lock(); LFS_INFO("file_close(%p)", file); int err = lfs_file_close(&_lfs, f); LFS_INFO("file_close -> %d", lfs_toerror(err)); _mutex.unlock(); delete f; return lfs_toerror(err); }
// TODO: Implement a couple functions to conveniently save/load a protobuf message to/from a file int loadConfig(Vector<WifiNetworkConfig>* networks) { // Get filesystem instance const auto fs = filesystem_get_instance(nullptr); CHECK_TRUE(fs, SYSTEM_ERROR_FILE); fs::FsLock lock(fs); CHECK(filesystem_mount(fs)); // Open configuration file lfs_file_t file = {}; CHECK(openFile(&file, CONFIG_FILE, LFS_O_RDONLY)); NAMED_SCOPE_GUARD(fileGuard, { lfs_file_close(&fs->instance, &file); });
static int _close(vfs_file_t *filp) { littlefs_desc_t *fs = filp->mp->private_data; lfs_file_t *fp = (lfs_file_t *)&filp->private_data.buffer; mutex_lock(&fs->lock); DEBUG("littlefs: close: filp=%p, fp=%p\n", (void *)filp, (void *)fp); int ret = lfs_file_close(&fs->fs, fp); mutex_unlock(&fs->lock); return littlefs_err_to_errno(ret); }