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

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

commit 13df1677b04c2781724877820fb2ede8002503a0
Author: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl>
AuthorDate: Wed Aug 7 13:39:57 2024 +0200

    fs/fcb: Add fcb_write function
    
    Previously fcb sequence to write FCB entry was:
    fcb_append(fcb, len, loc)
    flash_area_write(fa,...)
    fcb_finish(fcb, loc)
    
    This adds function fcb_write() that should be used instead
    of direct call to flash_area_write to make it more consistent.
    
    Signed-off-by: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl>
---
 fs/fcb/include/fcb/fcb.h | 15 +++++++++++++++
 fs/fcb/src/fcb_append.c  | 13 +++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/fs/fcb/include/fcb/fcb.h b/fs/fcb/include/fcb/fcb.h
index d382521fe..7f97b9ee1 100644
--- a/fs/fcb/include/fcb/fcb.h
+++ b/fs/fcb/include/fcb/fcb.h
@@ -141,6 +141,21 @@ int fcb_init(struct fcb *fcb);
 int fcb_append(struct fcb *, uint16_t len, struct fcb_entry *loc);
 int fcb_append_finish(struct fcb *, struct fcb_entry *append_loc);
 
+/**
+ * Write to flash user data.
+ *
+ * Function should be called after fcb_append is called and before fcb_finish
+ * This is wrapper for flash_area_write() function and uses loc for starting
+ * location. loc is modified and can be used for subsequent writes.
+ *
+ * @param fcb - fcb to write entry to
+ * @param loc - location of the entry
+ * @param buf - data to write
+ * @param len - number of bytes to write to fcb
+ * @return 0 on success, non-zero on failure
+ */
+int fcb_write(struct fcb *fcb, struct fcb_entry *loc, const uint8_t *buf, 
size_t len);
+
 /**
  * Walk over all entries in FCB.
  * cb gets called for every entry. If cb wants to stop the walk, it should
diff --git a/fs/fcb/src/fcb_append.c b/fs/fcb/src/fcb_append.c
index b23f43a60..444fda25b 100644
--- a/fs/fcb/src/fcb_append.c
+++ b/fs/fcb/src/fcb_append.c
@@ -66,6 +66,19 @@ fcb_append_to_scratch(struct fcb *fcb)
     return FCB_OK;
 }
 
+int
+fcb_write(struct fcb *fcb, struct fcb_entry *loc, const uint8_t *buf, size_t 
len)
+{
+    int rc;
+
+    rc = flash_area_write(loc->fe_area, loc->fe_data_off, buf, len);
+    if (rc == 0) {
+        loc->fe_data_off += len;
+    }
+
+    return rc;
+}
+
 int
 fcb_append(struct fcb *fcb, uint16_t len, struct fcb_entry *append_loc)
 {

Reply via email to