From 97711d78c4a7469de8fc9f418623aa8ac7ba4b42 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 8 Jun 2018 11:27:27 +1000 Subject: [PATCH] Added possibility to open multiple files with LFS_NO_MALLOC enabled. --- lfs.c | 7 +++++-- lfs.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lfs.c b/lfs.c index 7f721f7..cdfbd4a 100644 --- a/lfs.c +++ b/lfs.c @@ -1283,7 +1283,7 @@ static int lfs_ctz_traverse(lfs_t *lfs, /// Top level file operations /// int lfs_file_open(lfs_t *lfs, lfs_file_t *file, - const char *path, int flags) { + const char *path, int flags, void *file_buffer) { // deorphan if we haven't yet, needed at most once after poweron if ((flags & 3) != LFS_O_RDONLY && !lfs->deorphaned) { int err = lfs_deorphan(lfs); @@ -1340,7 +1340,10 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file, } // allocate buffer if needed - if (lfs->cfg->file_buffer) { + file->cache.block = 0xffffffff; + if (file_buffer) { + file->cache.buffer = file_buffer; + } else if (lfs->cfg->file_buffer) { if (lfs->files) { // already in use return LFS_ERR_NOMEM; diff --git a/lfs.h b/lfs.h index 1b1be19..ef0e1e8 100644 --- a/lfs.h +++ b/lfs.h @@ -334,7 +334,7 @@ int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info); // // Returns a negative error code on failure. int lfs_file_open(lfs_t *lfs, lfs_file_t *file, - const char *path, int flags); + const char *path, int flags, void *file_buffer); // Close a file //