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:21 UTC

[mynewt-core] branch master updated (3520b9a -> 96db945)

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

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


    from 3520b9a  muc/stm32: Add workaround for STM32F4x5/7 WFI error
     new daf09ee  Added capability to recognize when a fcb sector is about to rotate and provide the application an opportunity to read logs before the rotation.
     new 3530e75  Update function & variable names to be more descriptive.
     new 6797742  Fixed renaming issue with apache-mynewt-core.
     new 4080423  Ensuring if fcb->scratch is initialized to NULL, it stays that way.
     new cd27ba8  Fixed spacing issue.
     new d85f5e5  Updated comment.
     new aaad145  Added handling around function if func_ptrs are not set.
     new b6f1acb  Added newline for better readability.
     new 70f3762  Updated comment.
     new 008eb93  Updated function name to correct naming convention.
     new 5f42e38  Removed un-necessary return check.
     new f2c3e2d  Updating spacing.
     new 3b20eb4  Fixed spacing.
     new b5c67e6  Fixed build issues.
     new 189989a  Fix?
     new c4074ba  WIP.
     new 8804528  Removing scratch sector from fcb struct.
     new 09c6a69  Created common function for walking full logs or area.
     new f116a27  Consolidating functionality.
     new db7fbc9  Fixed spacing.
     new 900da6e  Removed white space.
     new dd2a018  Using fcb->f_scratch_cnt as opposed to checking for past newest sector.
     new 96db945  Removed unused function prototype.

The 23 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 fs/fcb/include/fcb/fcb.h                       | 19 +++----
 sys/log/common/include/log_common/log_common.h |  7 +++
 sys/log/full/include/log/log.h                 | 27 ++++++++++
 sys/log/full/src/log.c                         | 29 +++++++++++
 sys/log/full/src/log_fcb.c                     | 70 +++++++++++++++++++-------
 5 files changed, 126 insertions(+), 26 deletions(-)


[mynewt-core] 17/23: Removing scratch sector from fcb struct.

Posted by ma...@apache.org.
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 8804528db9a2a02242c5e5bf5b0b45752ef2f4bc
Author: Nolan Lau <no...@juul.com>
AuthorDate: Thu Oct 17 14:59:36 2019 -0700

    Removing scratch sector from fcb struct.
---
 fs/fcb/include/fcb/fcb.h |  1 -
 fs/fcb/src/fcb.c         | 23 +----------------------
 fs/fcb/src/fcb_rotate.c  |  4 +---
 3 files changed, 2 insertions(+), 26 deletions(-)

diff --git a/fs/fcb/include/fcb/fcb.h b/fs/fcb/include/fcb/fcb.h
index d06a705..2a8ab98 100644
--- a/fs/fcb/include/fcb/fcb.h
+++ b/fs/fcb/include/fcb/fcb.h
@@ -60,7 +60,6 @@ struct fcb {
     /* Flash circular buffer internal state */
     struct os_mutex f_mtx;	/* Locking for accessing the FCB data */
     struct flash_area *f_oldest;
-    struct flash_area *f_scratch;
     struct fcb_entry f_active;
     uint16_t f_active_id;
     uint8_t f_align;		/* writes to flash have to aligned to this */
diff --git a/fs/fcb/src/fcb.c b/fs/fcb/src/fcb.c
index 40b218b..0fe7e1f 100644
--- a/fs/fcb/src/fcb.c
+++ b/fs/fcb/src/fcb.c
@@ -32,7 +32,7 @@ fcb_init(struct fcb *fcb)
     int max_align = 1;
     int align;
     int oldest = -1, newest = -1;
-    struct flash_area *oldest_fap = NULL, *newest_fap = NULL, *scratch_fap = NULL;
+    struct flash_area *oldest_fap = NULL, *newest_fap = NULL;
     struct fcb_disk_area fda;
 
     if (!fcb->f_sectors || fcb->f_sector_cnt - fcb->f_scratch_cnt < 1) {
@@ -56,26 +56,11 @@ fcb_init(struct fcb *fcb)
         if (oldest < 0) {
             oldest = newest = fda.fd_id;
             oldest_fap = newest_fap = fap;
-
-            fap++;
-            if (fap >= &fcb->f_sectors[fcb->f_sector_cnt]) {
-                scratch_fap = &fcb->f_sectors[0];
-            } else {
-                scratch_fap = fap;
-            }
             continue;
         }
         if (FCB_ID_GT(fda.fd_id, newest)) {
             newest = fda.fd_id;
             newest_fap = fap;
-           
-            fap++;
-            if (fap >= &fcb->f_sectors[fcb->f_sector_cnt]) {
-                scratch_fap = &fcb->f_sectors[0];
-            } else {
-                scratch_fap = fap;
-            }
-
         } else if (FCB_ID_GT(oldest, fda.fd_id)) {
             oldest = fda.fd_id;
             oldest_fap = fap;
@@ -91,13 +76,7 @@ fcb_init(struct fcb *fcb)
             return rc;
         }
         newest = oldest = 0;
-        scratch_fap = &fcb->f_sectors[fcb->f_sector_cnt-1];
     }
-
-    if (fcb->f_scratch) {
-        fcb->f_scratch = scratch_fap;
-    }
-
     fcb->f_align = max_align;
     fcb->f_oldest = oldest_fap;
     fcb->f_active.fe_area = newest_fap;
diff --git a/fs/fcb/src/fcb_rotate.c b/fs/fcb/src/fcb_rotate.c
index 729535f..7135fa6 100644
--- a/fs/fcb/src/fcb_rotate.c
+++ b/fs/fcb/src/fcb_rotate.c
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 #include "fcb/fcb.h"
 #include "fcb_priv.h"
 
@@ -48,9 +49,6 @@ fcb_rotate(struct fcb *fcb)
         fcb->f_active.fe_elem_off = sizeof(struct fcb_disk_area);
         fcb->f_active_id++;
     }
-    if (fcb->f_scratch) {
-        fcb->f_scratch = fcb->f_oldest;
-    }
     fcb->f_oldest = fcb_getnext_area(fcb, fcb->f_oldest);
 out:
     os_mutex_release(&fcb->f_mtx);


[mynewt-core] 21/23: Removed white space.

Posted by ma...@apache.org.
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 900da6e269cf942768e0a675a01aa8b0eaf96510
Author: Nolan Lau <no...@juul.com>
AuthorDate: Fri Oct 18 13:28:20 2019 -0700

    Removed white space.
---
 sys/log/full/src/log_fcb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index e32d80f..40b0be2 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -542,7 +542,7 @@ log_fcb_walk_impl(struct log *log, log_walk_func_t walk_func,
                 return 0;
             }
         }
-    } while (fcb_getnext(fcb, &loc) == 0); 
+    } while (fcb_getnext(fcb, &loc) == 0);
 
     return 0;
 }


[mynewt-core] 23/23: Removed unused function prototype.

Posted by ma...@apache.org.
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 96db945f227522df20e9cd2531648fe912dc4226
Author: Nolan Lau <no...@juul.com>
AuthorDate: Mon Oct 21 01:50:00 2019 -0700

    Removed unused function prototype.
---
 fs/fcb/include/fcb/fcb.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fs/fcb/include/fcb/fcb.h b/fs/fcb/include/fcb/fcb.h
index 2a8ab98..5b854d9 100644
--- a/fs/fcb/include/fcb/fcb.h
+++ b/fs/fcb/include/fcb/fcb.h
@@ -101,7 +101,6 @@ int fcb_append_finish(struct fcb *, struct fcb_entry *append_loc);
 typedef int (*fcb_walk_cb)(struct fcb_entry *loc, void *arg);
 int fcb_walk(struct fcb *, struct flash_area *, fcb_walk_cb cb, void *cb_arg);
 int fcb_getnext(struct fcb *, struct fcb_entry *loc);
-int fcb_getnext_sector(struct fcb *fcb, struct fcb_entry *loc);
 
 /**
  * Erases the data from oldest sector.


[mynewt-core] 07/23: Added handling around function if func_ptrs are not set.

Posted by ma...@apache.org.
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 aaad14593cb08cba34ffdc0034215df99c33781d
Author: Nolan Lau <no...@juul.com>
AuthorDate: Thu Oct 17 11:20:48 2019 -0700

    Added handling around function if func_ptrs are not set.
---
 sys/log/full/src/log.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/sys/log/full/src/log.c b/sys/log/full/src/log.c
index 29b56c8..8a7c15f 100644
--- a/sys/log/full/src/log.c
+++ b/sys/log/full/src/log.c
@@ -932,9 +932,17 @@ log_walk_body_section(struct log *log, log_walk_body_func_t walk_body_func,
     int rc;
 
     log_offset->lo_arg = &lwba;
+
+    if (!log->l_log->log-walk_sector)
+    {
+        rc = ENOTSUP;
+        goto err;
+    }
+
     rc = log->l_log->log_walk_sector(log, log_walk_body_fn, log_offset);
     log_offset->lo_arg = lwba.arg;
 
+err:
     return rc;
 }
 


[mynewt-core] 03/23: Fixed renaming issue with apache-mynewt-core.

Posted by ma...@apache.org.
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 679774201f3b590d407a1e8e97de6f6d02c902d9
Author: Nolan Lau <no...@juul.com>
AuthorDate: Mon Oct 14 22:31:19 2019 -0700

    Fixed renaming issue with apache-mynewt-core.
---
 sys/log/full/src/log_fcb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index fc7809f..e1ab06e 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -558,7 +558,7 @@ log_fcb_walk_sector(struct log *log, log_walk_func_t walk_func,
      * last entry), add a bookmark pointing to this walk's start location.
      */
     if (log_offset->lo_ts >= 0) {
-        fcb_log_add_bmark(fcb_log, &loc, log_offset->lo_index);
+        log_fcb_add_bmark(fcb_log, &loc, log_offset->lo_index);
     }
 #endif
     do {


[mynewt-core] 05/23: Fixed spacing issue.

Posted by ma...@apache.org.
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 cd27ba82f9e6f6eb272b034ec8fe4a1340041b22
Author: Nolan Lau <no...@juul.com>
AuthorDate: Wed Oct 16 18:55:35 2019 -0700

    Fixed spacing issue.
---
 fs/fcb/src/fcb_rotate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/fcb/src/fcb_rotate.c b/fs/fcb/src/fcb_rotate.c
index ba2ab96..729535f 100644
--- a/fs/fcb/src/fcb_rotate.c
+++ b/fs/fcb/src/fcb_rotate.c
@@ -48,7 +48,7 @@ fcb_rotate(struct fcb *fcb)
         fcb->f_active.fe_elem_off = sizeof(struct fcb_disk_area);
         fcb->f_active_id++;
     }
-    if(fcb->f_scratch) {
+    if (fcb->f_scratch) {
         fcb->f_scratch = fcb->f_oldest;
     }
     fcb->f_oldest = fcb_getnext_area(fcb, fcb->f_oldest);


[mynewt-core] 01/23: Added capability to recognize when a fcb sector is about to rotate and provide the application an opportunity to read logs before the rotation.

Posted by ma...@apache.org.
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 daf09ee90c17f32dd2528b07ed8b77227d8b63f4
Author: Nolan Lau <no...@juul.com>
AuthorDate: Wed Sep 25 21:56:17 2019 -0700

    Added capability to recognize when a fcb sector is about to rotate and
    provide the application an opportunity to read logs before the rotation.
---
 fs/fcb/include/fcb/fcb.h                       | 21 ++++----
 fs/fcb/src/fcb.c                               | 23 +++++++-
 fs/fcb/src/fcb_append.c                        | 10 +++-
 fs/fcb/src/fcb_getnext.c                       | 57 ++++++++++++++++++++
 fs/fcb/src/fcb_rotate.c                        |  3 +-
 sys/log/common/include/log_common/log_common.h |  7 +++
 sys/log/full/include/log/log.h                 | 28 ++++++++++
 sys/log/full/src/log.c                         | 22 ++++++++
 sys/log/full/src/log_fcb.c                     | 75 ++++++++++++++++++++------
 9 files changed, 217 insertions(+), 29 deletions(-)

diff --git a/fs/fcb/include/fcb/fcb.h b/fs/fcb/include/fcb/fcb.h
index f198e18..d06a705 100644
--- a/fs/fcb/include/fcb/fcb.h
+++ b/fs/fcb/include/fcb/fcb.h
@@ -60,6 +60,7 @@ struct fcb {
     /* Flash circular buffer internal state */
     struct os_mutex f_mtx;	/* Locking for accessing the FCB data */
     struct flash_area *f_oldest;
+    struct flash_area *f_scratch;
     struct fcb_entry f_active;
     uint16_t f_active_id;
     uint8_t f_align;		/* writes to flash have to aligned to this */
@@ -68,15 +69,16 @@ struct fcb {
 /**
  * Error codes.
  */
-#define FCB_OK		0
-#define FCB_ERR_ARGS	-1
-#define FCB_ERR_FLASH	-2
-#define FCB_ERR_NOVAR   -3
-#define FCB_ERR_NOSPACE	-4
-#define FCB_ERR_NOMEM	-5
-#define FCB_ERR_CRC	-6
-#define FCB_ERR_MAGIC   -7
-#define FCB_ERR_VERSION -8
+#define FCB_OK             0
+#define FCB_ERR_ARGS      -1
+#define FCB_ERR_FLASH     -2
+#define FCB_ERR_NOVAR     -3
+#define FCB_ERR_NOSPACE   -4
+#define FCB_ERR_NOMEM     -5
+#define FCB_ERR_CRC       -6
+#define FCB_ERR_MAGIC     -7
+#define FCB_ERR_VERSION   -8
+#define FCB_ERR_NEXT_SECT -9
 
 int fcb_init(struct fcb *fcb);
 
@@ -100,6 +102,7 @@ int fcb_append_finish(struct fcb *, struct fcb_entry *append_loc);
 typedef int (*fcb_walk_cb)(struct fcb_entry *loc, void *arg);
 int fcb_walk(struct fcb *, struct flash_area *, fcb_walk_cb cb, void *cb_arg);
 int fcb_getnext(struct fcb *, struct fcb_entry *loc);
+int fcb_getnext_sector(struct fcb *fcb, struct fcb_entry *loc);
 
 /**
  * Erases the data from oldest sector.
diff --git a/fs/fcb/src/fcb.c b/fs/fcb/src/fcb.c
index 0fe7e1f..40b218b 100644
--- a/fs/fcb/src/fcb.c
+++ b/fs/fcb/src/fcb.c
@@ -32,7 +32,7 @@ fcb_init(struct fcb *fcb)
     int max_align = 1;
     int align;
     int oldest = -1, newest = -1;
-    struct flash_area *oldest_fap = NULL, *newest_fap = NULL;
+    struct flash_area *oldest_fap = NULL, *newest_fap = NULL, *scratch_fap = NULL;
     struct fcb_disk_area fda;
 
     if (!fcb->f_sectors || fcb->f_sector_cnt - fcb->f_scratch_cnt < 1) {
@@ -56,11 +56,26 @@ fcb_init(struct fcb *fcb)
         if (oldest < 0) {
             oldest = newest = fda.fd_id;
             oldest_fap = newest_fap = fap;
+
+            fap++;
+            if (fap >= &fcb->f_sectors[fcb->f_sector_cnt]) {
+                scratch_fap = &fcb->f_sectors[0];
+            } else {
+                scratch_fap = fap;
+            }
             continue;
         }
         if (FCB_ID_GT(fda.fd_id, newest)) {
             newest = fda.fd_id;
             newest_fap = fap;
+           
+            fap++;
+            if (fap >= &fcb->f_sectors[fcb->f_sector_cnt]) {
+                scratch_fap = &fcb->f_sectors[0];
+            } else {
+                scratch_fap = fap;
+            }
+
         } else if (FCB_ID_GT(oldest, fda.fd_id)) {
             oldest = fda.fd_id;
             oldest_fap = fap;
@@ -76,7 +91,13 @@ fcb_init(struct fcb *fcb)
             return rc;
         }
         newest = oldest = 0;
+        scratch_fap = &fcb->f_sectors[fcb->f_sector_cnt-1];
     }
+
+    if (fcb->f_scratch) {
+        fcb->f_scratch = scratch_fap;
+    }
+
     fcb->f_align = max_align;
     fcb->f_oldest = oldest_fap;
     fcb->f_active.fe_area = newest_fap;
diff --git a/fs/fcb/src/fcb_append.c b/fs/fcb/src/fcb_append.c
index 6d1bc86..dcdf2a7 100644
--- a/fs/fcb/src/fcb_append.c
+++ b/fs/fcb/src/fcb_append.c
@@ -36,8 +36,14 @@ fcb_new_area(struct fcb *fcb, int cnt)
         if (!rfa) {
             rfa = fa;
         }
-        if (fa == fcb->f_oldest) {
-            return NULL;
+        if (fcb->f_scratch) {
+            if (fa == fcb->f_scratch) {
+                return NULL;
+            }
+        } else {
+            if (fa == fcb->f_oldest) {
+                return NULL;
+            }
         }
     } while (i++ < cnt);
     return rfa;
diff --git a/fs/fcb/src/fcb_getnext.c b/fs/fcb/src/fcb_getnext.c
index 6ca08ce..931432d 100644
--- a/fs/fcb/src/fcb_getnext.c
+++ b/fs/fcb/src/fcb_getnext.c
@@ -111,6 +111,48 @@ next_sector:
 }
 
 int
+fcb_getnext_nolock_sector(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;
+        }
+
+        if (rc != FCB_ERR_CRC) {
+            return FCB_ERR_NEXT_SECT;
+        }
+    }
+
+    return FCB_ERR_NEXT_SECT;
+}
+
+int
 fcb_getnext(struct fcb *fcb, struct fcb_entry *loc)
 {
     int rc;
@@ -124,3 +166,18 @@ 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_nolock_sector(fcb, loc);
+    os_mutex_release(&fcb->f_mtx);
+
+    return rc;
+}
diff --git a/fs/fcb/src/fcb_rotate.c b/fs/fcb/src/fcb_rotate.c
index 7135fa6..d9c7bf2 100644
--- a/fs/fcb/src/fcb_rotate.c
+++ b/fs/fcb/src/fcb_rotate.c
@@ -16,7 +16,6 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 #include "fcb/fcb.h"
 #include "fcb_priv.h"
 
@@ -49,6 +48,8 @@ fcb_rotate(struct fcb *fcb)
         fcb->f_active.fe_elem_off = sizeof(struct fcb_disk_area);
         fcb->f_active_id++;
     }
+    fcb->f_scratch = fcb->f_oldest;
+
     fcb->f_oldest = fcb_getnext_area(fcb, fcb->f_oldest);
 out:
     os_mutex_release(&fcb->f_mtx);
diff --git a/sys/log/common/include/log_common/log_common.h b/sys/log/common/include/log_common/log_common.h
index 9a42354..356d170 100644
--- a/sys/log/common/include/log_common/log_common.h
+++ b/sys/log/common/include/log_common/log_common.h
@@ -134,6 +134,13 @@ extern struct log_info g_log_info;
  */
 typedef void log_append_cb(struct log *log, uint32_t idx);
 
+/** @typdef log_notify_rotate_cb
+ * @brief Callback that is executed each time we are about to rotate a log.
+ * 
+ * @param log                   The log that is about to rotate 
+ */
+typedef void log_notify_rotate_cb(struct log *log);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/sys/log/full/include/log/log.h b/sys/log/full/include/log/log.h
index 4cf3240..853446f 100644
--- a/sys/log/full/include/log/log.h
+++ b/sys/log/full/include/log/log.h
@@ -114,6 +114,7 @@ struct log_handler {
     lh_append_mbuf_func_t log_append_mbuf;
     lh_append_mbuf_body_func_t log_append_mbuf_body;
     lh_walk_func_t log_walk;
+    lh_walk_func_t log_walk_sector;
     lh_flush_func_t log_flush;
 #if MYNEWT_VAL(LOG_STORAGE_INFO)
     lh_storage_info_func_t log_storage_info;
@@ -213,6 +214,7 @@ struct log {
     void *l_arg;
     STAILQ_ENTRY(log) l_next;
     log_append_cb *l_append_cb;
+    log_notify_rotate_cb *l_notify_erase_done_cb;
     uint8_t l_level;
     uint16_t l_max_entry_len;   /* Log body length; if 0 disables check. */
 #if !MYNEWT_VAL(LOG_GLOBAL_IDX)
@@ -597,6 +599,21 @@ int log_walk_body(struct log *log, log_walk_body_func_t walk_body_func,
         struct log_offset *log_offset);
 int log_flush(struct log *log);
 
+/**
+ * @brief      Walking a section of FCB.
+ *
+ * @param log                   The log to iterate.
+ * @param walk_body_func        The function to apply to each log entry.
+ * @param log_offset            Specifies the range of entries to process.
+ *                                  Entries not matching these criteria are
+ *                                  skipped during the walk.
+ *
+ * @return                      0 if the walk completed successfully;
+ *                              nonzero on error or if the walk was aborted.
+ */
+int log_walk_body_section(struct log *log, log_walk_body_func_t walk_body_func,
+              struct log_offset *log_offset);
+
 #if MYNEWT_VAL(LOG_MODULE_LEVELS)
 /**
  * @brief Retrieves the globally configured minimum log level for the specified
@@ -680,6 +697,17 @@ void log_set_max_entry_len(struct log *log, uint16_t max_entry_len);
  */
 int log_storage_info(struct log *log, struct log_storage_info *info);
 #endif
+
+/**
+ * Assign a callback function to be notified once the log deletes the oldest
+ * data to write in new data.
+ *
+ * @param log   The log
+ * @param cb    The callback function to be executed.
+ */
+void
+log_set_rotate_done_cb(struct log *log, log_notify_rotate_cb *cb);
+
 #if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
 /**
  * Set watermark on log
diff --git a/sys/log/full/src/log.c b/sys/log/full/src/log.c
index 3b992e7..32bd7ff 100644
--- a/sys/log/full/src/log.c
+++ b/sys/log/full/src/log.c
@@ -458,6 +458,11 @@ log_hdr_len(const struct log_entry_hdr *hdr)
     return LOG_BASE_ENTRY_HDR_SIZE;
 }
 
+void
+log_set_rotate_done_cb(struct log *log, log_notify_rotate_cb *cb)
+{
+    log->l_notify_erase_done_cb = cb;
+}
 
 static int
 log_chk_type(uint8_t etype)
@@ -916,6 +921,23 @@ log_walk_body(struct log *log, log_walk_body_func_t walk_body_func,
     return rc;
 }
 
+int
+log_walk_body_section(struct log *log, log_walk_body_func_t walk_body_func,
+              struct log_offset *log_offset)
+{
+    struct log_walk_body_arg lwba = {
+        .fn = walk_body_func,
+        .arg = log_offset->lo_arg,
+    };
+    int rc;
+
+    log_offset->lo_arg = &lwba;
+    rc = log->l_log->log_walk_sector(log, log_walk_body_fn, log_offset);
+    log_offset->lo_arg = lwba.arg;
+
+    return rc;
+}
+
 /**
  * Reads from the specified log.
  *
diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index c2ffcef..e708b65 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -159,6 +159,11 @@ log_fcb_start_append(struct log *log, int len, struct fcb_entry *loc)
         }
 #endif
 
+        /* Check to see if the active region is in the scratch region */
+        if (log->l_notify_erase_done_cb != NULL) {
+            log->l_notify_erase_done_cb(log);
+        }
+
 #if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
         /* The FCB needs to be rotated.  Invalidate all bookmarks. */
         log_fcb_clear_bmarks(fcb_log);
@@ -180,8 +185,6 @@ log_fcb_start_append(struct log *log, int len, struct fcb_entry *loc)
             fcb_log->fl_watermark_off = fcb->f_oldest->fa_off;
         }
 #endif
-
-
     }
 
 err:
@@ -465,7 +468,6 @@ log_fcb_read_mbuf(struct log *log, const void *dptr, struct os_mbuf *om,
         if (rc) {
             goto done;
         }
-
         rc = os_mbuf_append(om, data, read_len);
         if (rc) {
             goto done;
@@ -528,6 +530,48 @@ log_fcb_walk(struct log *log, log_walk_func_t walk_func,
 }
 
 static int
+log_fcb_walk_sector(struct log *log, log_walk_func_t walk_func,
+             struct log_offset *log_offset)
+{
+    struct fcb *fcb;
+    struct fcb_log *fcb_log;
+    struct fcb_entry loc;
+    int rc;
+
+    fcb_log = log->l_arg;
+    fcb = &fcb_log->fl_fcb;
+
+    /* Locate the starting point of the walk. */
+    rc = log_fcb_find_gte(log, log_offset, &loc);
+    switch (rc) {
+    case 0:
+        /* Found a starting point. */
+        break;
+    case SYS_ENOENT:
+        /* No entries match the offset criteria; nothing to walk. */
+        return 0;
+    default:
+        return rc;
+    }
+#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
+    /* If a minimum index was specified (i.e., we are not just retrieving the
+     * last entry), add a bookmark pointing to this walk's start location.
+     */
+    if (log_offset->lo_ts >= 0) {
+        fcb_log_add_bmark(fcb_log, &loc, log_offset->lo_index);
+    }
+#endif
+    do {
+        rc = walk_func(log, log_offset, &loc, loc.fe_data_len);
+        if (rc != 0) {
+            return rc;
+        }
+    } while (fcb_getnext_sector(fcb, &loc) == 0);
+
+    return 0;
+}
+
+static int
 log_fcb_flush(struct log *log)
 {
     struct fcb_log *fcb_log;
@@ -772,9 +816,7 @@ log_fcb_copy(struct log *log, struct fcb *src_fcb, struct fcb *dst_fcb,
 {
     struct fcb_entry entry;
     int rc;
-
     rc = 0;
-
     memset(&entry, 0, sizeof(entry));
     while (!fcb_getnext(src_fcb, &entry)) {
         if (entry.fe_elem_off < offset) {
@@ -860,22 +902,23 @@ err:
 }
 
 const struct log_handler log_fcb_handler = {
-    .log_type = LOG_TYPE_STORAGE,
-    .log_read = log_fcb_read,
-    .log_read_mbuf = log_fcb_read_mbuf,
-    .log_append = log_fcb_append,
-    .log_append_body = log_fcb_append_body,
-    .log_append_mbuf = log_fcb_append_mbuf,
+    .log_type             = LOG_TYPE_STORAGE,
+    .log_read             = log_fcb_read,
+    .log_read_mbuf        = log_fcb_read_mbuf,
+    .log_append           = log_fcb_append,
+    .log_append_body      = log_fcb_append_body,
+    .log_append_mbuf      = log_fcb_append_mbuf,
     .log_append_mbuf_body = log_fcb_append_mbuf_body,
-    .log_walk = log_fcb_walk,
-    .log_flush = log_fcb_flush,
+    .log_walk             = log_fcb_walk,
+    .log_walk_sector      = log_fcb_walk_sector,
+    .log_flush            = log_fcb_flush,
 #if MYNEWT_VAL(LOG_STORAGE_INFO)
-    .log_storage_info = log_fcb_storage_info,
+    .log_storage_info     = log_fcb_storage_info,
 #endif
 #if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
-    .log_set_watermark = log_fcb_set_watermark,
+    .log_set_watermark    = log_fcb_set_watermark,
 #endif
-    .log_registered = log_fcb_registered,
+    .log_registered       = log_fcb_registered,
 };
 
 #endif


[mynewt-core] 20/23: Fixed spacing.

Posted by ma...@apache.org.
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 db7fbc9710c0d4a3bed9a79d4c1cfea8c01b501e
Author: Nolan Lau <no...@juul.com>
AuthorDate: Thu Oct 17 17:01:41 2019 -0700

    Fixed spacing.
---
 fs/fcb/src/fcb_getnext.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/fcb/src/fcb_getnext.c b/fs/fcb/src/fcb_getnext.c
index 8075ba2..6ca08ce 100644
--- a/fs/fcb/src/fcb_getnext.c
+++ b/fs/fcb/src/fcb_getnext.c
@@ -111,7 +111,7 @@ next_sector:
 }
 
 int
- fcb_getnext(struct fcb *fcb, struct fcb_entry *loc)
+fcb_getnext(struct fcb *fcb, struct fcb_entry *loc)
 {
     int rc;
 


[mynewt-core] 06/23: Updated comment.

Posted by ma...@apache.org.
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 d85f5e5e7fa3861ac1d3599c0ac63cbde3dc8de0
Author: Nolan Lau <no...@juul.com>
AuthorDate: Thu Oct 17 10:55:27 2019 -0700

    Updated comment.
---
 sys/log/full/include/log/log.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/sys/log/full/include/log/log.h b/sys/log/full/include/log/log.h
index dd0666e..94ec227 100644
--- a/sys/log/full/include/log/log.h
+++ b/sys/log/full/include/log/log.h
@@ -699,8 +699,7 @@ int log_storage_info(struct log *log, struct log_storage_info *info);
 #endif
 
 /**
- * Assign a callback function to be notified once the log deletes the oldest
- * data to write in new data.
+ * Assign a callback function to be notified when the log is about to be rotated.
  *
  * @param log   The log
  * @param cb    The callback function to be executed.


[mynewt-core] 12/23: Updating spacing.

Posted by ma...@apache.org.
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 f2c3e2dee83271f04a6cb785846d5752fd4f8d08
Author: Nolan Lau <no...@juul.com>
AuthorDate: Thu Oct 17 13:40:19 2019 -0700

    Updating spacing.
---
 sys/log/full/src/log.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/sys/log/full/src/log.c b/sys/log/full/src/log.c
index 8a7c15f..33a850c 100644
--- a/sys/log/full/src/log.c
+++ b/sys/log/full/src/log.c
@@ -933,8 +933,7 @@ log_walk_body_section(struct log *log, log_walk_body_func_t walk_body_func,
 
     log_offset->lo_arg = &lwba;
 
-    if (!log->l_log->log-walk_sector)
-    {
+    if (!log->l_log->log-walk_sector) {
         rc = ENOTSUP;
         goto err;
     }


[mynewt-core] 22/23: Using fcb->f_scratch_cnt as opposed to checking for past newest sector.

Posted by ma...@apache.org.
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 dd2a0180066357a50032a65c63c96a1f794ba0f7
Author: Nolan Lau <no...@juul.com>
AuthorDate: Fri Oct 18 14:30:36 2019 -0700

    Using fcb->f_scratch_cnt as opposed to checking for past newest sector.
---
 fs/fcb/src/fcb_append.c    | 23 +----------------------
 sys/log/full/src/log_fcb.c |  1 +
 2 files changed, 2 insertions(+), 22 deletions(-)

diff --git a/fs/fcb/src/fcb_append.c b/fs/fcb/src/fcb_append.c
index 59beafa..6d1bc86 100644
--- a/fs/fcb/src/fcb_append.c
+++ b/fs/fcb/src/fcb_append.c
@@ -21,27 +21,6 @@
 #include "fcb/fcb.h"
 #include "fcb_priv.h"
 
-/**
- * Check to see if area is at the newest point
- *
- * @param fcb
- *
- * @return fap area
- */
-struct flash_area *
-fcb_area_past_newest(struct fcb *fcb)
-{
-    struct flash_area *fap;
-
-    fap = fcb->f_active.fe_area;
-    fap++;
-    if (fap >= &fcb->f_sectors[fcb->f_sector_cnt]) {
-        return &fcb->f_sectors[0];
-    } else {
-        return fap;
-    }
-}
-
 static struct flash_area *
 fcb_new_area(struct fcb *fcb, int cnt)
 {
@@ -57,7 +36,7 @@ fcb_new_area(struct fcb *fcb, int cnt)
         if (!rfa) {
             rfa = fa;
         }
-        if (fcb->f_oldest == fcb_area_past_newest(fcb)) {
+        if (fa == fcb->f_oldest) {
             return NULL;
         }
     } while (i++ < cnt);
diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index 40b0be2..7c3205e 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -161,6 +161,7 @@ log_fcb_start_append(struct log *log, int len, struct fcb_entry *loc)
 
         /* Notify upper layer that a rotation is about to occur */
         if (log->l_rotate_notify_cb != NULL) {
+            fcb_append_to_scratch(fcb);
             log->l_rotate_notify_cb(log);
         }
 


[mynewt-core] 13/23: Fixed spacing.

Posted by ma...@apache.org.
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 3b20eb4dca598912f3a4b81a6b47d5aef7c3a69c
Author: Nolan Lau <no...@juul.com>
AuthorDate: Thu Oct 17 13:45:53 2019 -0700

    Fixed spacing.
---
 sys/log/full/src/log_fcb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index 662a17d..e861093 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -817,6 +817,7 @@ log_fcb_copy(struct log *log, struct fcb *src_fcb, struct fcb *dst_fcb,
 {
     struct fcb_entry entry;
     int rc;
+
     rc = 0;
     memset(&entry, 0, sizeof(entry));
     while (!fcb_getnext(src_fcb, &entry)) {


[mynewt-core] 09/23: Updated comment.

Posted by ma...@apache.org.
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 70f376242292c77266926726c0ee31cbdffe7510
Author: Nolan Lau <no...@juul.com>
AuthorDate: Thu Oct 17 11:26:15 2019 -0700

    Updated comment.
---
 sys/log/full/src/log_fcb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index 8164779..662a17d 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -159,7 +159,7 @@ log_fcb_start_append(struct log *log, int len, struct fcb_entry *loc)
         }
 #endif
 
-        /* Check to see if the active region is in the scratch region */
+        /* Notify upper layer that a rotation is about to occur */
         if (log->l_rotate_notify_cb != NULL) {
             log->l_rotate_notify_cb(log);
         }


[mynewt-core] 02/23: Update function & variable names to be more descriptive.

Posted by ma...@apache.org.
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 3530e75990ec7e95ecb66c396c3620812a0827c7
Author: Nolan Lau <no...@juul.com>
AuthorDate: Mon Oct 14 19:11:46 2019 -0700

    Update function & variable names to be more descriptive.
---
 sys/log/full/include/log/log.h | 4 ++--
 sys/log/full/src/log.c         | 4 ++--
 sys/log/full/src/log_fcb.c     | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/sys/log/full/include/log/log.h b/sys/log/full/include/log/log.h
index 853446f..dd0666e 100644
--- a/sys/log/full/include/log/log.h
+++ b/sys/log/full/include/log/log.h
@@ -214,7 +214,7 @@ struct log {
     void *l_arg;
     STAILQ_ENTRY(log) l_next;
     log_append_cb *l_append_cb;
-    log_notify_rotate_cb *l_notify_erase_done_cb;
+    log_notify_rotate_cb *l_rotate_notify_cb;
     uint8_t l_level;
     uint16_t l_max_entry_len;   /* Log body length; if 0 disables check. */
 #if !MYNEWT_VAL(LOG_GLOBAL_IDX)
@@ -706,7 +706,7 @@ int log_storage_info(struct log *log, struct log_storage_info *info);
  * @param cb    The callback function to be executed.
  */
 void
-log_set_rotate_done_cb(struct log *log, log_notify_rotate_cb *cb);
+log_set_rotate_notify_cb(struct log *log, log_notify_rotate_cb *cb);
 
 #if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
 /**
diff --git a/sys/log/full/src/log.c b/sys/log/full/src/log.c
index 32bd7ff..29b56c8 100644
--- a/sys/log/full/src/log.c
+++ b/sys/log/full/src/log.c
@@ -459,9 +459,9 @@ log_hdr_len(const struct log_entry_hdr *hdr)
 }
 
 void
-log_set_rotate_done_cb(struct log *log, log_notify_rotate_cb *cb)
+log_set_rotate_notify_cb(struct log *log, log_notify_rotate_cb *cb)
 {
-    log->l_notify_erase_done_cb = cb;
+    log->l_rotate_notify_cb = cb;
 }
 
 static int
diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index e708b65..fc7809f 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -160,8 +160,8 @@ log_fcb_start_append(struct log *log, int len, struct fcb_entry *loc)
 #endif
 
         /* Check to see if the active region is in the scratch region */
-        if (log->l_notify_erase_done_cb != NULL) {
-            log->l_notify_erase_done_cb(log);
+        if (log->l_rotate_notify_cb != NULL) {
+            log->l_rotate_notify_cb(log);
         }
 
 #if MYNEWT_VAL(LOG_FCB_BOOKMARKS)


[mynewt-core] 04/23: Ensuring if fcb->scratch is initialized to NULL, it stays that way.

Posted by ma...@apache.org.
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 40804235ec271b2e53170d00de75f8459cb06575
Author: Nolan Lau <no...@juul.com>
AuthorDate: Wed Oct 16 15:39:04 2019 -0700

    Ensuring if fcb->scratch is initialized to NULL, it stays that way.
---
 fs/fcb/src/fcb_rotate.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/fcb/src/fcb_rotate.c b/fs/fcb/src/fcb_rotate.c
index d9c7bf2..ba2ab96 100644
--- a/fs/fcb/src/fcb_rotate.c
+++ b/fs/fcb/src/fcb_rotate.c
@@ -48,8 +48,9 @@ fcb_rotate(struct fcb *fcb)
         fcb->f_active.fe_elem_off = sizeof(struct fcb_disk_area);
         fcb->f_active_id++;
     }
-    fcb->f_scratch = fcb->f_oldest;
-
+    if(fcb->f_scratch) {
+        fcb->f_scratch = fcb->f_oldest;
+    }
     fcb->f_oldest = fcb_getnext_area(fcb, fcb->f_oldest);
 out:
     os_mutex_release(&fcb->f_mtx);


[mynewt-core] 08/23: Added newline for better readability.

Posted by ma...@apache.org.
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 b6f1acbfaa8d67553a1755c57d1d0ec95730e72c
Author: Nolan Lau <no...@juul.com>
AuthorDate: Thu Oct 17 11:22:09 2019 -0700

    Added newline for better readability.
---
 sys/log/full/src/log_fcb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index e1ab06e..8164779 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -772,6 +772,7 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
     struct fcb *fcb_tmp;
 
     rc = log_fcb_read(log, entry, &ueh, 0, LOG_BASE_ENTRY_HDR_SIZE);
+
     if (rc != LOG_BASE_ENTRY_HDR_SIZE) {
         goto err;
     }


[mynewt-core] 10/23: Updated function name to correct naming convention.

Posted by ma...@apache.org.
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 008eb930bc6dd942f989dfe901c6fdc6243ccb8a
Author: Nolan Lau <no...@juul.com>
AuthorDate: Thu Oct 17 11:38:10 2019 -0700

    Updated function name to correct naming convention.
---
 fs/fcb/src/fcb_getnext.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/fcb/src/fcb_getnext.c b/fs/fcb/src/fcb_getnext.c
index 931432d..2a85597 100644
--- a/fs/fcb/src/fcb_getnext.c
+++ b/fs/fcb/src/fcb_getnext.c
@@ -111,7 +111,7 @@ next_sector:
 }
 
 int
-fcb_getnext_nolock_sector(struct fcb *fcb, struct fcb_entry *loc)
+fcb_getnext_sector_nolock(struct fcb *fcb, struct fcb_entry *loc)
 {
     int rc;
 
@@ -176,7 +176,7 @@ fcb_getnext_sector(struct fcb *fcb, struct fcb_entry *loc)
     if (rc && rc != OS_NOT_STARTED) {
         return FCB_ERR_ARGS;
     }
-    rc = fcb_getnext_nolock_sector(fcb, loc);
+    rc = fcb_getnext_sector_nolock(fcb, loc);
     os_mutex_release(&fcb->f_mtx);
 
     return rc;


[mynewt-core] 14/23: Fixed build issues.

Posted by ma...@apache.org.
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 b5c67e67e5e471e362499bcf1ea0fd68472a9aab
Author: Nolan Lau <no...@juul.com>
AuthorDate: Thu Oct 17 14:02:23 2019 -0700

    Fixed build issues.
---
 sys/log/full/src/log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/log/full/src/log.c b/sys/log/full/src/log.c
index 33a850c..7cb45e5 100644
--- a/sys/log/full/src/log.c
+++ b/sys/log/full/src/log.c
@@ -933,7 +933,7 @@ log_walk_body_section(struct log *log, log_walk_body_func_t walk_body_func,
 
     log_offset->lo_arg = &lwba;
 
-    if (!log->l_log->log-walk_sector) {
+    if (!log->l_log->log->walk_sector) {
         rc = ENOTSUP;
         goto err;
     }


[mynewt-core] 18/23: Created common function for walking full logs or area.

Posted by ma...@apache.org.
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 09c6a691c2d771ccd7d70d02fd2ae3d0880ce85e
Author: Nolan Lau <no...@juul.com>
AuthorDate: Thu Oct 17 16:32:50 2019 -0700

    Created common function for walking full logs or area.
---
 sys/log/full/src/log_fcb.c | 86 +++++++++++++++++++++-------------------------
 1 file changed, 39 insertions(+), 47 deletions(-)

diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index e861093..23d9a96 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -481,9 +481,19 @@ done:
     return len - rem_len;
 }
 
+/**
+ * @brief Common function for walking a single area or the full logs
+ *
+ * @param      The log
+ * @param[in]  The walk function
+ * @param      The log offset
+ * @param[in]  Reading either a single area or the full log
+ *
+ * @return     { description_of_the_return_value }
+ */
 static int
-log_fcb_walk(struct log *log, log_walk_func_t walk_func,
-             struct log_offset *log_offset)
+log_fcb_walk_impl(struct log *log, log_walk_func_t walk_func,
+             struct log_offset *log_offset, bool area)
 {
     struct fcb *fcb;
     struct fcb_log *fcb_log;
@@ -515,60 +525,42 @@ log_fcb_walk(struct log *log, log_walk_func_t walk_func,
     }
 #endif
 
-    do {
-        rc = walk_func(log, log_offset, &loc, loc.fe_data_len);
-        if (rc != 0) {
-            if (rc < 0) {
+    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;
+                }
+            }
+        } while (fcb_getnext(fcb, &loc) == 0); 
+    } else {
+       do {
+            rc = walk_func(log, log_offset, &loc, loc.fe_data_len);
+            if (rc != 0) {
                 return rc;
-            } else {
-                return 0;
             }
-        }
-    } while (fcb_getnext(fcb, &loc) == 0);
+        } while (fcb_getnext_sector(fcb, &loc) == 0); 
+    }
 
     return 0;
 }
 
 static int
-log_fcb_walk_sector(struct log *log, log_walk_func_t walk_func,
+log_fcb_walk(struct log *log, log_walk_func_t walk_func,
              struct log_offset *log_offset)
 {
-    struct fcb *fcb;
-    struct fcb_log *fcb_log;
-    struct fcb_entry loc;
-    int rc;
-
-    fcb_log = log->l_arg;
-    fcb = &fcb_log->fl_fcb;
-
-    /* Locate the starting point of the walk. */
-    rc = log_fcb_find_gte(log, log_offset, &loc);
-    switch (rc) {
-    case 0:
-        /* Found a starting point. */
-        break;
-    case SYS_ENOENT:
-        /* No entries match the offset criteria; nothing to walk. */
-        return 0;
-    default:
-        return rc;
-    }
-#if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
-    /* If a minimum index was specified (i.e., we are not just retrieving the
-     * last entry), add a bookmark pointing to this walk's start location.
-     */
-    if (log_offset->lo_ts >= 0) {
-        log_fcb_add_bmark(fcb_log, &loc, log_offset->lo_index);
-    }
-#endif
-    do {
-        rc = walk_func(log, log_offset, &loc, loc.fe_data_len);
-        if (rc != 0) {
-            return rc;
-        }
-    } while (fcb_getnext_sector(fcb, &loc) == 0);
+    return log_fcb_walk_impl(log, walk_func, log_offset, false);
+}
 
-    return 0;
+static int
+log_fcb_walk_area(struct log *log, log_walk_func_t walk_func,
+             struct log_offset *log_offset)
+{
+    return log_fcb_walk_impl(log, walk_func, log_offset, true);
 }
 
 static int
@@ -912,7 +904,7 @@ const struct log_handler log_fcb_handler = {
     .log_append_mbuf      = log_fcb_append_mbuf,
     .log_append_mbuf_body = log_fcb_append_mbuf_body,
     .log_walk             = log_fcb_walk,
-    .log_walk_sector      = log_fcb_walk_sector,
+    .log_walk_sector      = log_fcb_walk_area,
     .log_flush            = log_fcb_flush,
 #if MYNEWT_VAL(LOG_STORAGE_INFO)
     .log_storage_info     = log_fcb_storage_info,


[mynewt-core] 15/23: Fix?

Posted by ma...@apache.org.
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 189989a7c1fd6e1da366143059c6388e412915f8
Author: Nolan Lau <no...@juul.com>
AuthorDate: Thu Oct 17 14:05:13 2019 -0700

    Fix?
---
 sys/log/full/src/log.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/log/full/src/log.c b/sys/log/full/src/log.c
index 7cb45e5..ba94856 100644
--- a/sys/log/full/src/log.c
+++ b/sys/log/full/src/log.c
@@ -933,8 +933,8 @@ log_walk_body_section(struct log *log, log_walk_body_func_t walk_body_func,
 
     log_offset->lo_arg = &lwba;
 
-    if (!log->l_log->log->walk_sector) {
-        rc = ENOTSUP;
+    if (!log->l_log->log_walk_sector) {
+        rc = SYS_ENOTSUP;
         goto err;
     }
 


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

Posted by ma...@apache.org.
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;
 }


[mynewt-core] 11/23: Removed un-necessary return check.

Posted by ma...@apache.org.
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 5f42e389029e0e8abfb6c425b16b2f99a325378b
Author: Nolan Lau <no...@juul.com>
AuthorDate: Thu Oct 17 13:34:14 2019 -0700

    Removed un-necessary return check.
---
 fs/fcb/src/fcb_getnext.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/fs/fcb/src/fcb_getnext.c b/fs/fcb/src/fcb_getnext.c
index 2a85597..f85c2f9 100644
--- a/fs/fcb/src/fcb_getnext.c
+++ b/fs/fcb/src/fcb_getnext.c
@@ -143,10 +143,6 @@ fcb_getnext_sector_nolock(struct fcb *fcb, struct fcb_entry *loc)
         if (rc == 0) {
             return 0;
         }
-
-        if (rc != FCB_ERR_CRC) {
-            return FCB_ERR_NEXT_SECT;
-        }
     }
 
     return FCB_ERR_NEXT_SECT;


[mynewt-core] 16/23: WIP.

Posted by ma...@apache.org.
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 c4074ba4ed05e78dcb26229e4e9931e0403e57df
Author: Nolan Lau <no...@juul.com>
AuthorDate: Thu Oct 17 14:48:18 2019 -0700

    WIP.
---
 fs/fcb/src/fcb_append.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/fs/fcb/src/fcb_append.c b/fs/fcb/src/fcb_append.c
index dcdf2a7..59beafa 100644
--- a/fs/fcb/src/fcb_append.c
+++ b/fs/fcb/src/fcb_append.c
@@ -21,6 +21,27 @@
 #include "fcb/fcb.h"
 #include "fcb_priv.h"
 
+/**
+ * Check to see if area is at the newest point
+ *
+ * @param fcb
+ *
+ * @return fap area
+ */
+struct flash_area *
+fcb_area_past_newest(struct fcb *fcb)
+{
+    struct flash_area *fap;
+
+    fap = fcb->f_active.fe_area;
+    fap++;
+    if (fap >= &fcb->f_sectors[fcb->f_sector_cnt]) {
+        return &fcb->f_sectors[0];
+    } else {
+        return fap;
+    }
+}
+
 static struct flash_area *
 fcb_new_area(struct fcb *fcb, int cnt)
 {
@@ -36,14 +57,8 @@ fcb_new_area(struct fcb *fcb, int cnt)
         if (!rfa) {
             rfa = fa;
         }
-        if (fcb->f_scratch) {
-            if (fa == fcb->f_scratch) {
-                return NULL;
-            }
-        } else {
-            if (fa == fcb->f_oldest) {
-                return NULL;
-            }
+        if (fcb->f_oldest == fcb_area_past_newest(fcb)) {
+            return NULL;
         }
     } while (i++ < cnt);
     return rfa;