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


##########
sys/log/full/src/log_fcb_bmark.c:
##########
@@ -22,17 +22,151 @@
 #include "os/mynewt.h"
 
 #if MYNEWT_VAL(LOG_FCB_BOOKMARKS)
-
+#include "log/log.h"
 #include "log/log_fcb.h"
 
-void
+#if MYNEWT_VAL(LOG_FCB_SECTOR_BOOKMARKS)
+static int
+log_fcb_init_sector_bmarks(struct fcb_log *fcb_log)
+{
+    int rc = 0;
+    int i = 0;
+    int j = 0;
+    struct log_fcb_bset *bset = &fcb_log->fl_bset;
+    struct log_entry_hdr ueh = {0};
+#if MYNEWT_VAL(LOG_FCB)
+    struct fcb_entry loc = {0};
+    struct flash_area *fa = NULL;
+
+    rc = fcb_getnext(&fcb_log->fl_fcb, &loc);
+    if (rc) {
+        return -1;
+    }
+#else
+    struct flash_sector_range *range = NULL;
+    struct fcb2_entry loc = {0};
+
+    rc = fcb2_getnext(&fcb_log->fl_fcb, &loc);
+    if (rc) {
+        return -1;
+    }
+#endif
+
+    /* Start adding a bookmark from the end of array just before
+     * non-sector bookmarks
+     */
+    bset->lfs_next_sect = bset->lfs_sect_cap - 1;
+    for (i = 0; i < bset->lfs_sect_cap; i++) {
+        rc = log_read_hdr(fcb_log->fl_log, &loc, &ueh);
+        if (rc) {
+            /* Read failed, don't add a bookmark, done adding bookmarks */
+            rc = SYS_EOK;
+            break;
+        }
+
+        rc = log_fcb_add_bmark(fcb_log, &loc, ueh.ue_index, true);
+        if (rc) {
+            return rc;
+        }
+
+#if MYNEWT_VAL(LOG_FCB)
+        j = 0;
+
+        /* Keep skipping sectors until lfs_sect_bmark_itvl is reached */
+        do {
+            fa = fcb_getnext_area(&fcb_log->fl_fcb, loc.fe_area);
+            if (!fa) {
+                break;
+            }
+            j++;
+        } while (j < bset->lfs_sect_bmark_itvl);
+
+        if (!fa) {
+            break;
+        }
+
+        /* First entry in the next area */
+        rc = fcb_getnext_in_area(&fcb_log->fl_fcb, fa, &loc);
+        if (rc) {
+            break;
+        }
+#else
+        j = 0;
+
+        /* Keep skipping rangess until lfs_sect_bmark_itvl is reached */
+        do {
+            /* Get next range */
+            range = fcb2_getnext_range(&fcb_log->fl_fcb, &loc);
+            if (!range) {
+                break;
+            }
+            j++;
+        } while (j < bset->lfs_sect_bmark_itvl);
+
+        if (!range) {
+            break;
+        }
+
+        /* First entry in the next area */
+        rc = fcb2_getnext_in_area(&fcb_log->fl_fcb, range, &loc);
+        if (rc) {
+            break;
+        }
+#endif
+    }
+
+    return rc;
+}
+#endif
+
+int
 log_fcb_init_bmarks(struct fcb_log *fcb_log,
-                    struct log_fcb_bmark *buf, int bmark_count)
+                    struct log_fcb_bmark *buf, int avl_bmark_cnt,

Review Comment:
   It is for understanding the code better, the comparison between required 
bookmark count and available bookmark count is performed below. Hence, the name 
change. I will update the description to reflect the same and add a comment as 
well.



-- 
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