diff options
author | Damien George <damien.p.george@gmail.com> | 2018-06-08 04:27:27 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2018-07-18 02:32:18 +0300 |
commit | 961fab70c37e28f57e1f731cbe19717e7eb6c651 (patch) | |
tree | 52d9204c8dbebc886b51fb0e89ac916b778c36d1 /lfs.c | |
parent | f94d233deb494bbe1cb5488d69539607d354b2ac (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.c | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -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); } |