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

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

commit 2c68a5280376e75832bb90745620533d1d9516af
Author: Vipul Rahane <[email protected]>
AuthorDate: Wed Jan 15 14:53:22 2025 -0800

    Fix build, export some APIs, add pointer to the log structure in fcb_log
---
 fs/fcb/include/fcb/fcb.h           | 20 ++++++++++
 sys/log/full/include/log/log_fcb.h | 27 ++++++++++++--
 sys/log/full/src/log_fcb.c         |  4 +-
 sys/log/full/src/log_fcb_bmark.c   | 75 +++++++++++++++++++++++++++++---------
 4 files changed, 102 insertions(+), 24 deletions(-)

diff --git a/fs/fcb/include/fcb/fcb.h b/fs/fcb/include/fcb/fcb.h
index 7f97b9ee1..710008a57 100644
--- a/fs/fcb/include/fcb/fcb.h
+++ b/fs/fcb/include/fcb/fcb.h
@@ -168,6 +168,26 @@ 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);
 
+/**
+ * Get next area pointer from the FCB pointer to by fcb pointer
+ *
+ * @param fcb Pointer to the FCB
+ * @param fap Pointer to the flash_area
+ *
+ * @return Pointer to the flash_area that comes next
+ */
+struct flash_area *fcb_getnext_area(struct fcb *fcb, struct flash_area *fap);
+
+/**
+ * Get next entry in the area
+ *
+ * @param fcb Pointer to FCB
+ * @param loc Pointer to FCB entry
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int fcb_getnext_in_area(struct fcb *fcb, struct fcb_entry *loc);
+
 #if MYNEWT_VAL_FCB_BIDIRECTIONAL
 /**
  * Call 'cb' for every element in flash circular buffer moving
diff --git a/sys/log/full/include/log/log_fcb.h 
b/sys/log/full/include/log/log_fcb.h
index ff81fcc28..74db52744 100644
--- a/sys/log/full/include/log/log_fcb.h
+++ b/sys/log/full/include/log/log_fcb.h
@@ -23,6 +23,8 @@
 extern "C" {
 #endif
 
+struct log_storage_info;
+
 #if MYNEWT_VAL(LOG_FCB)
 #include <fcb/fcb.h>
 #elif MYNEWT_VAL(LOG_FCB2)
@@ -39,6 +41,8 @@ struct log_fcb_bmark {
 #endif
     /* The index of the log entry that the FCB entry contains. */
     uint32_t lfb_index;
+    /* Is this a sector boundary bookmark */
+    bool lfb_sect_bmark;
 };
 
 /** A set of fcb log bookmarks. */
@@ -72,6 +76,7 @@ struct fcb_log {
 #if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
     struct log_fcb_bset fl_bset;
 #endif
+    struct log *fl_log;
 };
 
 #elif MYNEWT_VAL(LOG_FCB2)
@@ -113,9 +118,11 @@ struct fcb_log {
  * @param fcb_log               The log to configure.
  * @param buf                   The buffer to use for bookmarks.
  * @param bmark_count           The bookmark capacity of the supplied buffer.
+ *
+ * @return 0 on success, non-zero on failure
  */
-void log_fcb_init_bmarks(struct fcb_log *fcb_log,
-                         struct log_fcb_bmark *buf, int bmark_count);
+int log_fcb_init_bmarks(struct fcb_log *fcb_log,
+                        struct log_fcb_bmark *buf, int bmark_count);
 
 /**
  * @brief Erases all bookmarks from the supplied fcb_log.
@@ -145,19 +152,31 @@ void log_fcb_rotate_bmarks(struct fcb_log *fcb_log);
 const struct log_fcb_bmark *
 log_fcb_closest_bmark(const struct fcb_log *fcb_log, uint32_t index);
 
+/**
+ * @brief Return storage info providing fcb_log pointer
+ *
+ * @param fl Pointer to the fcb_log
+ * @param info Pointer to the log_storage_info to be filled up
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+log_fcb_storage_info_by_fcb(struct fcb_log *fl, struct log_storage_info *info);
+
 /**
  * Inserts a bookmark into the provided log.
  *
  * @param fcb_log               The log to insert a bookmark into.
  * @param entry                 The entry the bookmark should point to.
  * @param index                 The log entry index of the bookmark.
+ * @paran sect_bmark            Bool indicating it is a sector bookmark.
  */
 #if MYNEWT_VAL(LOG_FCB)
 void log_fcb_add_bmark(struct fcb_log *fcb_log, const struct fcb_entry *entry,
-                       uint32_t index);
+                       uint32_t index, bool sect_bmark);
 #elif MYNEWT_VAL(LOG_FCB2)
 void log_fcb_add_bmark(struct fcb_log *fcb_log, const struct fcb2_entry *entry,
-                       uint32_t index);
+                       uint32_t index, bool sect_bmark);
 #endif
 #endif
 
diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index 5b97b3fd0..83785c12b 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -285,7 +285,7 @@ log_fcb_start_append(struct log *log, int len, struct 
fcb_entry *loc)
 #else
             idx = log->l_idx;
 #endif
-            log_fcb_add_bmark(fcb_log, loc, idx);
+            log_fcb_add_bmark(fcb_log, loc, idx, true);
         }
     }
 
@@ -629,7 +629,7 @@ log_fcb_walk_impl(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) {
-        log_fcb_add_bmark(fcb_log, &loc, log_offset->lo_index);
+        log_fcb_add_bmark(fcb_log, &loc, log_offset->lo_index, false);
     }
 #endif
 
diff --git a/sys/log/full/src/log_fcb_bmark.c b/sys/log/full/src/log_fcb_bmark.c
index 614b4fd3c..1c950f2a9 100644
--- a/sys/log/full/src/log_fcb_bmark.c
+++ b/sys/log/full/src/log_fcb_bmark.c
@@ -22,45 +22,57 @@
 #include "os/mynewt.h"
 
 #if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
-
+#include <console/console.h>
+#include "log/log.h"
 #include "log/log_fcb.h"
 
 static int
 log_fcb_init_sector_bmarks(struct fcb_log *fcb_log)
 {
     int rc = 0;
+    int i = 0;
 #if MYNEWT_VAL(LOG_STORAGE_INFO)
     struct log_storage_info info = {0};
     struct fcb_entry loc = {0};
-    struct flash_area *fe_area = NULL;
     struct log_entry_hdr ueh;
+    struct flash_area *fa = NULL;
 
-    rc = log_storage_info(fcb_log, &info);
+    rc = log_storage_info(fcb_log->fl_log, &info);
     if (rc) {
         return SYS_ENOENT;
     }
 
-    rc = fcb_getnext(fcb_log->fl_fcb, &loc);
+    rc = fcb_getnext(&fcb_log->fl_fcb, &loc);
     if (rc) {
         return -1;
     }
 
-    for (i = 0; i < info.used/fcb_log->fl_fcb->f_sector_cnt; i++) {
-        rc = log_read_hdr(log, loc, &ueh);
+    for (i = 0; i < info.used/fcb_log->fl_fcb.f_sector_cnt; i++) {
+        rc = log_read_hdr(fcb_log->fl_log, &loc, &ueh);
         if (rc != sizeof(ueh)) {
             /* Read failed, don't add a bookmark, done adding bookmarks */
             rc = SYS_EOK;
             break;
         }
 
-        log_fcb_add_bmark(fcb_log, &loc, ueh.ue_index);
+        console_printf("Sect bmark: %u :: HEADER:\n", i);
+        console_printf("ue_ts: %lld \n", ueh.ue_ts);
+        console_printf("ue_index: %lu \n", ueh.ue_index);
+        console_printf("ue_module: %u \n", ueh.ue_module);
+        console_printf("ue_level: %u \n", ueh.ue_level);
+        console_printf("ue_etype: %u \n", ueh.ue_etype);
+        console_printf("ue_flags: %u \n", ueh.ue_flags);
+        console_printf("ue_imghash=0x%02x%02x%02x%02x\n", ueh.ue_imghash[0], 
ueh.ue_imghash[1],
+                       ueh.ue_imghash[2], ueh.ue_imghash[3]);
 
-        rc = fcb_getnext_area(fcb_log->fl_fcb, loc.fe_area);
-        if (rc) {
+        log_fcb_add_bmark(fcb_log, &loc, ueh.ue_index, true);
+
+        fa = fcb_getnext_area(&fcb_log->fl_fcb, loc.fe_area);
+        if (!fa) {
             break;
         }
 
-        rc = fcb_getnext_in_area(fcb_log->fl_fcb, &loc);
+        rc = fcb_getnext_in_area(&fcb_log->fl_fcb, &loc);
         if (rc) {
             break;
         }
@@ -69,7 +81,7 @@ log_fcb_init_sector_bmarks(struct fcb_log *fcb_log)
     return rc;
 }
 
-void
+int
 log_fcb_init_bmarks(struct fcb_log *fcb_log,
                     struct log_fcb_bmark *buf, int bmark_count)
 {
@@ -78,7 +90,7 @@ log_fcb_init_bmarks(struct fcb_log *fcb_log,
         .lfs_cap = bmark_count,
     };
 
-    log_fcb_init_sector_bmarks(fcb_log);
+    return log_fcb_init_sector_bmarks(fcb_log);
 }
 
 void
@@ -147,14 +159,16 @@ log_fcb_closest_bmark(const struct fcb_log *fcb_log, 
uint32_t index)
 #if MYNEWT_VAL(LOG_FCB)
 void
 log_fcb_add_bmark(struct fcb_log *fcb_log, const struct fcb_entry *entry,
-                  uint32_t index)
+                  uint32_t index, bool sect_bmark)
 #elif MYNEWT_VAL(LOG_FCB2)
 void
 log_fcb_add_bmark(struct fcb_log *fcb_log, const struct fcb2_entry *entry,
-                  uint32_t index)
+                  uint32_t index, bool sect_bmark)
 #endif
 {
     struct log_fcb_bset *bset;
+    int i = 0;
+    int pos = 0;
 
     bset = &fcb_log->fl_bset;
 
@@ -162,7 +176,34 @@ log_fcb_add_bmark(struct fcb_log *fcb_log, const struct 
fcb2_entry *entry,
         return;
     }
 
-    bset->lfs_bmarks[bset->lfs_next] = (struct log_fcb_bmark) {
+    console_printf("Add new bmark :: orig bmark array >\n");
+    for (i = 0; i < bset->lfs_cap; i++)
+    {
+        console_printf("%u: %lu\n", i, bset->lfs_bmarks[i].lfb_index);
+    }
+    console_printf("\n");
+
+    for (i = 0; i < bset->lfs_size; i++)
+    {
+        if (index > bset->lfs_bmarks[i].lfb_index) {
+            pos = i;
+        }
+    }
+
+    /* One index ahead of bset->lfs_size - 1 to account for new bmark */
+    for(i = bset->lfs_size; i >= pos; i--)
+    {
+        bset->lfs_bmarks[i%bset->lfs_cap - 1] = bset->lfs_bmarks[i - 1];
+    }
+    console_printf("new bmark array >\n");
+
+    for (i = 0; i < bset->lfs_cap; i++)
+    {
+        console_printf("%u: %lu\n", i, bset->lfs_bmarks[i].lfb_index);
+    }
+    console_printf("\n");
+
+    bset->lfs_bmarks[pos] = (struct log_fcb_bmark) {
         .lfb_entry = *entry,
         .lfb_index = index,
     };
@@ -172,9 +213,7 @@ log_fcb_add_bmark(struct fcb_log *fcb_log, const struct 
fcb2_entry *entry,
     }
 
     bset->lfs_next++;
-    if (bset->lfs_next >= bset->lfs_cap) {
-        bset->lfs_next = 0;
-    }
+    bset->lfs_next %= bset->lfs_cap;
 }
 
 #endif /* MYNEWT_VAL(LOG_FCB_BOOKMARKS) */

Reply via email to