sys/log: Add append_mbuf handler to log_fcb
@@ -32,18 +32,17 @@ static struct flash_area sector;
static int log_fcb_rtr_erase(struct log *log, void *arg);
static int
-log_fcb_append(struct log *log, void *buf, int len)
+log_fcb_start_append(struct log *log, int len, struct fcb_entry *loc)
{
struct fcb *fcb;
- struct fcb_entry loc;
struct fcb_log *fcb_log;
- int rc;
+ int rc = 0;
fcb_log = (struct fcb_log *)log->l_arg;
fcb = &fcb_log->fl_fcb;
while (1) {
- rc = fcb_append(fcb, len, &loc);
+ rc = fcb_append(fcb, len, loc);
if (rc == 0) {
break;
}
@@ -66,6 +65,26 @@ log_fcb_append(struct log *log, void *buf, int len)
}
}
+err:
+ return (rc);
+}
+
+static int
+log_fcb_append(struct log *log, void *buf, int len)
+{
+ struct fcb *fcb;
+ struct fcb_entry loc;
+ struct fcb_log *fcb_log;
+ int rc;
+
+ fcb_log = (struct fcb_log *)log->l_arg;
+ fcb = &fcb_log->fl_fcb;
+
+ rc = log_fcb_start_append(log, len, &loc);
+ if (rc) {
+ goto err;
+ }
+
rc = flash_area_write(loc.fe_area, loc.fe_data_off, buf, len);
if (rc) {
goto err;
@@ -77,6 +96,49 @@ err:
return (rc);
}
+static int
+log_fcb_append_mbuf(struct log *log, struct os_mbuf *om)
+{
+ struct fcb *fcb;
+ struct fcb_entry loc;
+ struct fcb_log *fcb_log;
+ struct os_mbuf *om_tmp;
+ int len;
+ int rc;
+
+ fcb_log = (struct fcb_log *)log->l_arg;
+ fcb = &fcb_log->fl_fcb;
+
+ len = 0;
+
+ om_tmp = om;
+ while (om_tmp) {
+ len += om_tmp->om_len;
+ om_tmp = SLIST_NEXT(om_tmp, om_next);
+ }
+
+ rc = log_fcb_start_append(log, len, &loc);
+ if (rc) {
+ goto err;
+ }
+
+ while (om) {
+ rc = flash_area_write(loc.fe_area, loc.fe_data_off, om->om_data,
+ om->om_len);
+ if (rc) {
+ goto err;
+ }
+
+ loc.fe_data_off += om->om_len;
+ om = SLIST_NEXT(om, om_next);
+ }
+
+ rc = fcb_append_finish(fcb, &loc);
+
+err:
+ return (rc);
+}
+
static int
log_fcb_read(struct log *log, void *dptr, void *buf, uint16_t offset,
uint16_t len)
@@ -275,6 +337,7 @@ const struct log_handler log_fcb_handler = {
.log_type = LOG_TYPE_STORAGE,
.log_read = log_fcb_read,
.log_append = log_fcb_append,
+ .log_append_mbuf = log_fcb_append_mbuf,
.log_walk = log_fcb_walk,
.log_flush = log_fcb_flush,
};
