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:
authorNoah Gorny <noah@gittabags.com>2020-11-18 01:20:34 +0300
committerChristopher Haster <chaster@utexas.edu>2020-12-04 07:42:39 +0300
commit008ebc37dfe09c67b7b8b3b511f44399d3c3c684 (patch)
tree0e2fd15cc946aa5d8f44d13f37f1ab6709539f2d /lfs.c
parent6303558aee5c7ab9a5eb3ac495b3094647e962b4 (diff)
Add lfs_mlist_append/remove helper
Diffstat (limited to 'lfs.c')
-rw-r--r--lfs.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/lfs.c b/lfs.c
index 4b9fa6f..d20f6f1 100644
--- a/lfs.c
+++ b/lfs.c
@@ -422,6 +422,20 @@ static inline bool lfs_mlist_isopen(struct lfs_mlist *head,
return false;
}
+static inline void lfs_mlist_remove(lfs_t *lfs, struct lfs_mlist *mlist) {
+ for (struct lfs_mlist **p = &lfs->mlist; *p; p = &(*p)->next) {
+ if (*p == mlist) {
+ *p = (*p)->next;
+ break;
+ }
+ }
+}
+
+static inline void lfs_mlist_append(lfs_t *lfs, struct lfs_mlist *mlist) {
+ mlist->next = lfs->mlist;
+ lfs->mlist = mlist;
+}
+
/// Internal operations predeclared here ///
static int lfs_dir_commit(lfs_t *lfs, lfs_mdir_t *dir,
@@ -2062,8 +2076,7 @@ int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path) {
// add to list of mdirs
dir->type = LFS_TYPE_DIR;
- dir->next = (lfs_dir_t*)lfs->mlist;
- lfs->mlist = (struct lfs_mlist*)dir;
+ lfs_mlist_append(lfs, (struct lfs_mlist *)dir);
LFS_TRACE("lfs_dir_open -> %d", 0);
return 0;
@@ -2072,12 +2085,7 @@ int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path) {
int lfs_dir_close(lfs_t *lfs, lfs_dir_t *dir) {
LFS_TRACE("lfs_dir_close(%p, %p)", (void*)lfs, (void*)dir);
// remove from list of mdirs
- for (struct lfs_mlist **p = &lfs->mlist; *p; p = &(*p)->next) {
- if (*p == (struct lfs_mlist*)dir) {
- *p = (*p)->next;
- break;
- }
- }
+ lfs_mlist_remove(lfs, (struct lfs_mlist *)dir);
LFS_TRACE("lfs_dir_close -> %d", 0);
return 0;
@@ -2428,8 +2436,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
// get id, add to list of mdirs to catch update changes
file->type = LFS_TYPE_REG;
- file->next = (lfs_file_t*)lfs->mlist;
- lfs->mlist = (struct lfs_mlist*)file;
+ lfs_mlist_append(lfs, (struct lfs_mlist *)file);
if (tag == LFS_ERR_NOENT) {
if (!(flags & LFS_O_CREAT)) {
@@ -2565,12 +2572,7 @@ int lfs_file_close(lfs_t *lfs, lfs_file_t *file) {
int err = lfs_file_sync(lfs, file);
// remove from list of mdirs
- for (struct lfs_mlist **p = &lfs->mlist; *p; p = &(*p)->next) {
- if (*p == (struct lfs_mlist*)file) {
- *p = (*p)->next;
- break;
- }
- }
+ lfs_mlist_remove(lfs, (struct lfs_mlist*)file);
// clean up memory
if (!file->cfg->buffer) {