Adopted lfsr_data_from* pattern for internal data encoding

Taking advantage of the fact that these functions should never error,
changing the return type to lfsr_data_t allows all of the encoding
information to be passed around quite easily.

And, by giving each lfsr_data_from* function an LFSR_DATA_FROM* macro,
these functions can participate in our attr-list generating macros:

  LFSR_ATTR(-1, MTREE, 0, FROMBTREE(lfs, mtree, mtree_buf))

Though one thing to watch out for is the borrowed buffer that stores the
actual data. This might welcome use-after-free bugs since it's not super
clear the buffer remains borrowed. Will need to watch out for this.
This commit is contained in:
Christopher Haster
2023-09-14 13:17:27 -05:00
parent e4032de089
commit d0c5bf1210
2 changed files with 102 additions and 179 deletions
+4 -4
View File
@@ -4243,11 +4243,11 @@ code = '''
lfsr_mount(&lfs, CFG) => 0;
lfs_alloc_ack(&lfs);
uint8_t buffer[LFSR_MDIR_DSIZE];
lfs_ssize_t d = lfsr_mblocks_todisk(&lfs, LFSR_MBLOCKS_MROOTANCHOR, buffer);
assert(d >= 0);
uint8_t buf[LFSR_MDIR_DSIZE];
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
LFSR_ATTR(-1, MROOT, 0, BUF(buffer, d)))) => 0;
LFSR_ATTR(-1,
MROOT, 0, FROMMBLOCKS(&lfs, LFSR_MBLOCKS_MROOTANCHOR,
buf)))) => 0;
// technically, cycle detection only needs to work when we're validating
lfsr_mtree_traversal_t traversal = LFSR_MTREE_TRAVERSAL(