kasjer commented on code in PR #3365:
URL: https://github.com/apache/mynewt-core/pull/3365#discussion_r1985026864


##########
sys/log/full/src/log_fcb_bmark.c:
##########
@@ -61,74 +196,245 @@ log_fcb_rotate_bmarks(struct fcb_log *fcb_log)
             i--;
         }
         bset->lfs_size--;
-        bset->lfs_next = bset->lfs_size;
     }
 }
 
 void
 log_fcb_clear_bmarks(struct fcb_log *fcb_log)
 {
     fcb_log->fl_bset.lfs_size = 0;
-    fcb_log->fl_bset.lfs_next = 0;
+    fcb_log->fl_bset.lfs_next_non_sect = 0;
+    fcb_log->fl_bset.lfs_non_sect_size = 0;
+    memset(fcb_log->fl_bset.lfs_bmarks, 0,
+           sizeof(struct log_fcb_bmark) *
+           fcb_log->fl_bset.lfs_cap);
+}
+
+struct log_fcb_bmark *
+log_fcb_get_bmarks(struct log *log, uint32_t *bmarks_size)
+{
+    struct fcb_log *fcb_log = (struct fcb_log *)log->l_arg;
+
+    *bmarks_size = fcb_log->fl_bset.lfs_cap;
+
+    return fcb_log->fl_bset.lfs_bmarks;
 }
 
-const struct log_fcb_bmark *
-log_fcb_closest_bmark(const struct fcb_log *fcb_log, uint32_t index)
+struct log_fcb_bmark *
+log_fcb_closest_bmark(struct fcb_log *fcb_log, uint32_t index,
+                      int *min_diff)
 {
-    const struct log_fcb_bmark *closest;
-    const struct log_fcb_bmark *bmark;
-    uint32_t min_diff;
+    struct log_fcb_bmark *closest;
+    struct log_fcb_bmark *bmark;
     uint32_t diff;
     int i;
 
-    min_diff = UINT32_MAX;
+    *min_diff = -1;
     closest = NULL;
 
+    /* This works for both sector as well as non-sector bmarks
+     * because we calculate the min diff and iterate to the end
+     * of the bmarks array keeping track of min diff
+     */
     for (i = 0; i < fcb_log->fl_bset.lfs_size; i++) {
         bmark = &fcb_log->fl_bset.lfs_bmarks[i];
+#if MYNEWT_VAL(LOG_FCB)

Review Comment:
   To see that this does not work simply clear half of you logs then reboot. Or 
clear all logs and generate only some entries so log is not full.
   Then measure log walk starting from any index that is in sector bookmarks.
   If everything works fine, after displaying log starting from index that is 
present in bookmarks there should not be any additional entry in non-sector 
bookmarks.
   Here is output from log that has 333 sectors and 6 absolute bookmark space
   ```
   ...
   002870 327: index:493 fa_off: 26e000 fe_elem_off: 32
   002870 328: index:396 fa_off: 26d000 fe_elem_off: 32
   002870 329: index:299 fa_off: 26c000 fe_elem_off: 32
   002871 330: index:202 fa_off: 26b000 fe_elem_off: 32
   002871 331: index:105 fa_off: 26a000 fe_elem_off: 32
   002871 332: index:8 fa_off: 269000 fe_elem_off: 8
   002871 333: index:0 fa_off: 20000311 fe_elem_off: 0
   002872 334: index:0 fa_off: 20000311 fe_elem_off: 0
   002872 335: index:0 fa_off: 20000311 fe_elem_off: 0
   002873 336: index:0 fa_off: 20000311 fe_elem_off: 0
   002873 337: index:0 fa_off: 20000311 fe_elem_off: 0
   002873 338: index:0 fa_off: 20000311 fe_elem_off: 0
   compat> log -i 105 -n 2 -t datarec_dbg
   009706 Log datarec_dbg 2 entries walked in 46 ms
   compat> log -b datarec_dbg
   ...
   010990 327: index:493 fa_off: 26e000 fe_elem_off: 32
   010990 328: index:396 fa_off: 26d000 fe_elem_off: 32
   010991 329: index:299 fa_off: 26c000 fe_elem_off: 32
   010991 330: index:202 fa_off: 26b000 fe_elem_off: 32
   010991 331: index:105 fa_off: 26a000 fe_elem_off: 32
   010992 332: index:8 fa_off: 269000 fe_elem_off: 8
   010992 333: index:105 fa_off: 26a000 fe_elem_off: 32
   010992 334: index:0 fa_off: 20000311 fe_elem_off: 0
   010993 335: index:0 fa_off: 20000311 fe_elem_off: 0
   010993 336: index:0 fa_off: 20000311 fe_elem_off: 0
   010994 337: index:0 fa_off: 20000311 fe_elem_off: 0
   010994 338: index:0 fa_off: 20000311 fe_elem_off: 0
   compat> log -i 105 -n 2 -t datarec_dbg
   012411 Log datarec_dbg 2 entries walked in 46 ms
   ```
   Absolute bookmark is added here even though it's duplicate of existing 
sector bookmark.
   When second walk starts, no bookmark is found due to how lfs_size is used to 
limit number of iterations.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to