You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2019/10/21 09:30:40 UTC

[mynewt-core] 19/23: Consolidating functionality.

This is an automated email from the ASF dual-hosted git repository.

marko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit f116a27260d05baa27903febe204db765da308dc
Author: Nolan Lau <no...@juul.com>
AuthorDate: Thu Oct 17 17:01:24 2019 -0700

    Consolidating functionality.
---
 fs/fcb/src/fcb_getnext.c   | 55 +---------------------------------------------
 sys/log/full/src/log_fcb.c | 32 +++++++++++++--------------
 2 files changed, 16 insertions(+), 71 deletions(-)

diff --git a/fs/fcb/src/fcb_getnext.c b/fs/fcb/src/fcb_getnext.c
index f85c2f9..8075ba2 100644
--- a/fs/fcb/src/fcb_getnext.c
+++ b/fs/fcb/src/fcb_getnext.c
@@ -111,45 +111,7 @@ next_sector:
 }
 
 int
-fcb_getnext_sector_nolock(struct fcb *fcb, struct fcb_entry *loc)
-{
-    int rc;
-
-    if (loc->fe_area == NULL) {
-        /*
-         * Find the first one we have in flash.
-         */
-        loc->fe_area = fcb->f_oldest;
-    }
-    if (loc->fe_elem_off == 0) {
-        /*
-         * If offset is zero, we serve the first entry from the area.
-         */
-        loc->fe_elem_off = sizeof(struct fcb_disk_area);
-        rc = fcb_elem_info(fcb, loc);
-    } else {
-        rc = fcb_getnext_in_area(fcb, loc);
-    }
-    switch (rc) {
-    case 0:
-        return 0;
-    case FCB_ERR_CRC:
-        break;
-    default:
-        return FCB_ERR_NEXT_SECT;
-    }
-    while (rc == FCB_ERR_CRC) {
-        rc = fcb_getnext_in_area(fcb, loc);
-        if (rc == 0) {
-            return 0;
-        }
-    }
-
-    return FCB_ERR_NEXT_SECT;
-}
-
-int
-fcb_getnext(struct fcb *fcb, struct fcb_entry *loc)
+ fcb_getnext(struct fcb *fcb, struct fcb_entry *loc)
 {
     int rc;
 
@@ -162,18 +124,3 @@ fcb_getnext(struct fcb *fcb, struct fcb_entry *loc)
 
     return rc;
 }
-
-int
-fcb_getnext_sector(struct fcb *fcb, struct fcb_entry *loc)
-{
-    int rc;
-
-    rc = os_mutex_pend(&fcb->f_mtx, OS_WAIT_FOREVER);
-    if (rc && rc != OS_NOT_STARTED) {
-        return FCB_ERR_ARGS;
-    }
-    rc = fcb_getnext_sector_nolock(fcb, loc);
-    os_mutex_release(&fcb->f_mtx);
-
-    return rc;
-}
diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index 23d9a96..e32d80f 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -498,6 +498,7 @@ log_fcb_walk_impl(struct log *log, log_walk_func_t walk_func,
     struct fcb *fcb;
     struct fcb_log *fcb_log;
     struct fcb_entry loc;
+    struct flash_area *fap;
     int rc;
 
     fcb_log = log->l_arg;
@@ -515,6 +516,7 @@ log_fcb_walk_impl(struct log *log, log_walk_func_t walk_func,
     default:
         return rc;
     }
+    fap = loc.fe_area;
 
 #if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
     /* If a minimum index was specified (i.e., we are not just retrieving the
@@ -525,26 +527,22 @@ log_fcb_walk_impl(struct log *log, log_walk_func_t walk_func,
     }
 #endif
 
-    if (!area)
-    {
-       do {
-            rc = walk_func(log, log_offset, &loc, loc.fe_data_len);
-            if (rc != 0) {
-                if (rc < 0) {
-                    return rc;
-                } else {
-                    return 0;
-                }
+    do {
+        if (area) {
+            if (fap != loc.fe_area) {
+                return 0;
             }
-        } while (fcb_getnext(fcb, &loc) == 0); 
-    } else {
-       do {
-            rc = walk_func(log, log_offset, &loc, loc.fe_data_len);
-            if (rc != 0) {
+        }
+
+        rc = walk_func(log, log_offset, &loc, loc.fe_data_len);
+        if (rc != 0) {
+            if (rc < 0) {
                 return rc;
+            } else {
+                return 0;
             }
-        } while (fcb_getnext_sector(fcb, &loc) == 0); 
-    }
+        }
+    } while (fcb_getnext(fcb, &loc) == 0); 
 
     return 0;
 }