Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lfs.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-06-08 04:27:27 +0300
committerChristopher Haster <chaster@utexas.edu>2018-07-18 02:32:18 +0300
commit961fab70c37e28f57e1f731cbe19717e7eb6c651 (patch)
tree52d9204c8dbebc886b51fb0e89ac916b778c36d1 /lfs.c
parentf94d233deb494bbe1cb5488d69539607d354b2ac (diff)
Added file config structure and lfs_file_opencfg
The optional config structure options up the possibility of adding file-level configuration in a backwards compatible manner. Also adds possibility to open multiple files with LFS_NO_MALLOC enabled thanks to dpgeorge Also bumped minor version to v1.5
Diffstat (limited to 'lfs.c')
-rw-r--r--lfs.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/lfs.c b/lfs.c
index 7f721f7..cb05879 100644
--- a/lfs.c
+++ b/lfs.c
@@ -1282,8 +1282,9 @@ 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) {
+int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
+ const char *path, int flags,
+ const struct lfs_file_config *cfg) {
// 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);
@@ -1323,6 +1324,7 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
}
// setup file struct
+ file->cfg = cfg;
file->pair[0] = cwd.pair[0];
file->pair[1] = cwd.pair[1];
file->poff = entry.off;
@@ -1340,7 +1342,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->cfg && file->cfg->buffer) {
+ file->cache.buffer = file->cfg->buffer;
+ } else if (lfs->cfg->file_buffer) {
if (lfs->files) {
// already in use
return LFS_ERR_NOMEM;
@@ -1368,6 +1373,11 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
return 0;
}
+int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
+ const char *path, int flags) {
+ return lfs_file_opencfg(lfs, file, path, flags, NULL);
+}
+
int lfs_file_close(lfs_t *lfs, lfs_file_t *file) {
int err = lfs_file_sync(lfs, file);
@@ -1380,7 +1390,7 @@ int lfs_file_close(lfs_t *lfs, lfs_file_t *file) {
}
// clean up memory
- if (!lfs->cfg->file_buffer) {
+ if (!(file->cfg && file->cfg->buffer) && !lfs->cfg->file_buffer) {
lfs_free(file->cache.buffer);
}