Dropped lfs_*32/16 suffixed utils
We don't actually need these, all we need are utils defined for the
largest integer size we operate on, currently uint32_t.
Counterintuitively this should make it easier to adopt different integer
widths in the future.
Or maybe this will bite us when lfs_off_t >> lfs_size_t? Oh well, if
that's the case we can fix it then.
No code changes:
code stack
before: 33886 2560
after: 33886 (+0.0%) 2560 (+0.0%)
This commit is contained in:
@@ -1135,7 +1135,7 @@ static lfs_ssize_t lfsr_bd_readtag(lfs_t *lfs,
|
|||||||
uint32_t *cksum_) {
|
uint32_t *cksum_) {
|
||||||
// read the largest possible tag size
|
// read the largest possible tag size
|
||||||
uint8_t tag_buf[LFSR_TAG_DSIZE];
|
uint8_t tag_buf[LFSR_TAG_DSIZE];
|
||||||
lfs_size_t tag_dsize = lfs_min32(LFSR_TAG_DSIZE, lfs->cfg->block_size-off);
|
lfs_size_t tag_dsize = lfs_min(LFSR_TAG_DSIZE, lfs->cfg->block_size-off);
|
||||||
if (tag_dsize < 4) {
|
if (tag_dsize < 4) {
|
||||||
return LFS_ERR_CORRUPT;
|
return LFS_ERR_CORRUPT;
|
||||||
}
|
}
|
||||||
@@ -1277,10 +1277,10 @@ static lfsr_data_t lfsr_data_slice(lfsr_data_t data,
|
|||||||
lfs_ssize_t off, lfs_ssize_t size) {
|
lfs_ssize_t off, lfs_ssize_t size) {
|
||||||
// limit our off/size to data range, note the use of unsigned casts
|
// limit our off/size to data range, note the use of unsigned casts
|
||||||
// here to treat -1 as unbounded
|
// here to treat -1 as unbounded
|
||||||
lfs_size_t off_ = lfs_min32(
|
lfs_size_t off_ = lfs_min(
|
||||||
lfs_smax32(off, 0),
|
lfs_smax(off, 0),
|
||||||
lfsr_data_size(data));
|
lfsr_data_size(data));
|
||||||
lfs_size_t size_ = lfs_min32(
|
lfs_size_t size_ = lfs_min(
|
||||||
(lfs_size_t)size,
|
(lfs_size_t)size,
|
||||||
lfsr_data_size(data) - off_);
|
lfsr_data_size(data) - off_);
|
||||||
|
|
||||||
@@ -1304,7 +1304,7 @@ static lfsr_data_t lfsr_data_truncate(lfsr_data_t data, lfs_size_t size) {
|
|||||||
|
|
||||||
static lfsr_data_t lfsr_data_fruncate(lfsr_data_t data, lfs_size_t size) {
|
static lfsr_data_t lfsr_data_fruncate(lfsr_data_t data, lfs_size_t size) {
|
||||||
return lfsr_data_slice(data,
|
return lfsr_data_slice(data,
|
||||||
lfsr_data_size(data) - lfs_min32(
|
lfsr_data_size(data) - lfs_min(
|
||||||
size,
|
size,
|
||||||
lfsr_data_size(data)),
|
lfsr_data_size(data)),
|
||||||
-1);
|
-1);
|
||||||
@@ -1319,7 +1319,7 @@ static lfsr_data_t lfsr_data_fruncate(lfsr_data_t data, lfs_size_t size) {
|
|||||||
static lfs_ssize_t lfsr_data_read(lfs_t *lfs, lfsr_data_t *data,
|
static lfs_ssize_t lfsr_data_read(lfs_t *lfs, lfsr_data_t *data,
|
||||||
void *buffer, lfs_size_t size) {
|
void *buffer, lfs_size_t size) {
|
||||||
// limit our size to data range
|
// limit our size to data range
|
||||||
lfs_size_t d = lfs_min32(size, lfsr_data_size(*data));
|
lfs_size_t d = lfs_min(size, lfsr_data_size(*data));
|
||||||
|
|
||||||
// on-disk?
|
// on-disk?
|
||||||
if (lfsr_data_ondisk(*data)) {
|
if (lfsr_data_ondisk(*data)) {
|
||||||
@@ -1406,7 +1406,7 @@ static inline int lfsr_data_readlleb128(lfs_t *lfs, lfsr_data_t *data,
|
|||||||
static lfs_scmp_t lfsr_data_cmp(lfs_t *lfs, lfsr_data_t data,
|
static lfs_scmp_t lfsr_data_cmp(lfs_t *lfs, lfsr_data_t data,
|
||||||
const void *buffer, lfs_size_t size) {
|
const void *buffer, lfs_size_t size) {
|
||||||
// compare common prefix
|
// compare common prefix
|
||||||
lfs_size_t d = lfs_min32(size, lfsr_data_size(data));
|
lfs_size_t d = lfs_min(size, lfsr_data_size(data));
|
||||||
|
|
||||||
// on-disk?
|
// on-disk?
|
||||||
if (lfsr_data_ondisk(data)) {
|
if (lfsr_data_ondisk(data)) {
|
||||||
@@ -2407,7 +2407,7 @@ static int lfsr_rbyd_lookupnext(lfs_t *lfs, const lfsr_rbyd_t *rbyd,
|
|||||||
|
|
||||||
// make sure we never look up zero tags, the way we create
|
// make sure we never look up zero tags, the way we create
|
||||||
// unreachable tags has a hole here
|
// unreachable tags has a hole here
|
||||||
tag = lfs_max16(tag, 0x1);
|
tag = lfs_max(tag, 0x1);
|
||||||
|
|
||||||
// out of bounds? no trunk yet?
|
// out of bounds? no trunk yet?
|
||||||
if (rid >= (lfsr_srid_t)rbyd->weight || !lfsr_rbyd_trunk(rbyd)) {
|
if (rid >= (lfsr_srid_t)rbyd->weight || !lfsr_rbyd_trunk(rbyd)) {
|
||||||
@@ -2805,7 +2805,7 @@ static int lfsr_rbyd_appendattr(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
|||||||
// it's a bit ugly, but adjusting the rid here makes the following
|
// it's a bit ugly, but adjusting the rid here makes the following
|
||||||
// logic work out more consistently
|
// logic work out more consistently
|
||||||
rid += 1;
|
rid += 1;
|
||||||
a_rid = rid - lfs_smax32(-attr.weight, 0);
|
a_rid = rid - lfs_smax(-attr.weight, 0);
|
||||||
b_rid = rid;
|
b_rid = rid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2815,7 +2815,7 @@ static int lfsr_rbyd_appendattr(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
|||||||
} else {
|
} else {
|
||||||
LFS_ASSERT(rid < (lfsr_srid_t)rbyd->weight);
|
LFS_ASSERT(rid < (lfsr_srid_t)rbyd->weight);
|
||||||
|
|
||||||
a_rid = rid - lfs_smax32(-attr.weight, 0);
|
a_rid = rid - lfs_smax(-attr.weight, 0);
|
||||||
b_rid = rid;
|
b_rid = rid;
|
||||||
|
|
||||||
// note both normal and rm wide-tags have the same bounds, really it's
|
// note both normal and rm wide-tags have the same bounds, really it's
|
||||||
@@ -2834,8 +2834,8 @@ static int lfsr_rbyd_appendattr(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
|||||||
b_tag = lfsr_tag_key(attr.tag);
|
b_tag = lfsr_tag_key(attr.tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
a_tag = lfs_max16(a_tag, 0x1);
|
a_tag = lfs_max(a_tag, 0x1);
|
||||||
b_tag = lfs_max16(b_tag, 0x1);
|
b_tag = lfs_max(b_tag, 0x1);
|
||||||
|
|
||||||
// keep track of diverged state
|
// keep track of diverged state
|
||||||
//
|
//
|
||||||
@@ -3267,8 +3267,8 @@ stem:;
|
|||||||
lfsr_tag_t alt = 0;
|
lfsr_tag_t alt = 0;
|
||||||
lfsr_rid_t weight = 0;
|
lfsr_rid_t weight = 0;
|
||||||
if (tag_
|
if (tag_
|
||||||
&& (upper_rid-1 < rid-lfs_smax32(-attr.weight, 0)
|
&& (upper_rid-1 < rid-lfs_smax(-attr.weight, 0)
|
||||||
|| (upper_rid-1 == rid-lfs_smax32(-attr.weight, 0)
|
|| (upper_rid-1 == rid-lfs_smax(-attr.weight, 0)
|
||||||
&& ((!lfsr_tag_isgrow(attr.tag) && attr.weight > 0)
|
&& ((!lfsr_tag_isgrow(attr.tag) && attr.weight > 0)
|
||||||
|| (!lfsr_tag_issup(attr.tag)
|
|| (!lfsr_tag_issup(attr.tag)
|
||||||
&& lfsr_tag_supkey(tag_)
|
&& lfsr_tag_supkey(tag_)
|
||||||
@@ -3514,7 +3514,7 @@ static int lfsr_rbyd_appendattrs(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
|||||||
// is still included
|
// is still included
|
||||||
&& (lfs_size_t)(rid + 1) <= (lfs_size_t)end_rid) {
|
&& (lfs_size_t)(rid + 1) <= (lfs_size_t)end_rid) {
|
||||||
int err = lfsr_rbyd_appendattr(lfs, rbyd,
|
int err = lfsr_rbyd_appendattr(lfs, rbyd,
|
||||||
rid - lfs_smax32(start_rid, 0),
|
rid - lfs_smax(start_rid, 0),
|
||||||
attrs[i]);
|
attrs[i]);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
@@ -3571,7 +3571,7 @@ static lfs_ssize_t lfsr_rbyd_estimate(lfs_t *lfs, const lfsr_rbyd_t *rbyd,
|
|||||||
//
|
//
|
||||||
// TODO adopt this a/b naming scheme in lfsr_rbyd_appendattr?
|
// TODO adopt this a/b naming scheme in lfsr_rbyd_appendattr?
|
||||||
lfsr_srid_t a_rid = start_rid;
|
lfsr_srid_t a_rid = start_rid;
|
||||||
lfsr_srid_t b_rid = lfs_min32(rbyd->weight, end_rid);
|
lfsr_srid_t b_rid = lfs_min(rbyd->weight, end_rid);
|
||||||
lfs_size_t a_dsize = 0;
|
lfs_size_t a_dsize = 0;
|
||||||
lfs_size_t b_dsize = 0;
|
lfs_size_t b_dsize = 0;
|
||||||
lfs_size_t rbyd_dsize = 0;
|
lfs_size_t rbyd_dsize = 0;
|
||||||
@@ -3604,7 +3604,7 @@ static lfs_ssize_t lfsr_rbyd_estimate(lfs_t *lfs, const lfsr_rbyd_t *rbyd,
|
|||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
if (rid_ > a_rid+lfs_smax32(weight_-1, 0)) {
|
if (rid_ > a_rid+lfs_smax(weight_-1, 0)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3625,7 +3625,7 @@ static lfs_ssize_t lfsr_rbyd_estimate(lfs_t *lfs, const lfsr_rbyd_t *rbyd,
|
|||||||
if (a_rid < b_rid) {
|
if (a_rid < b_rid) {
|
||||||
a_rid += 1;
|
a_rid += 1;
|
||||||
} else {
|
} else {
|
||||||
a_rid -= lfs_smax32(weight-1, 0);
|
a_rid -= lfs_smax(weight-1, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3704,7 +3704,7 @@ static int lfsr_rbyd_appendcompaction(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// clamp offset to be after the revision count
|
// clamp offset to be after the revision count
|
||||||
off = lfs_max32(off, sizeof(uint32_t));
|
off = lfs_max(off, sizeof(uint32_t));
|
||||||
|
|
||||||
// empty rbyd? write a null tag so our trunk can still point to something
|
// empty rbyd? write a null tag so our trunk can still point to something
|
||||||
if (lfsr_rbyd_eoff(rbyd) == off) {
|
if (lfsr_rbyd_eoff(rbyd) == off) {
|
||||||
@@ -4314,7 +4314,7 @@ static int lfsr_btree_commit_(lfs_t *lfs, lfsr_btree_t *btree,
|
|||||||
if (btree->weight > 0) {
|
if (btree->weight > 0) {
|
||||||
lfsr_srid_t rid_;
|
lfsr_srid_t rid_;
|
||||||
int err = lfsr_btree_lookupnext_(lfs, btree,
|
int err = lfsr_btree_lookupnext_(lfs, btree,
|
||||||
lfs_min32(bid, btree->weight-1),
|
lfs_min(bid, btree->weight-1),
|
||||||
&bid, &rbyd, &rid_, NULL, NULL, NULL);
|
&bid, &rbyd, &rid_, NULL, NULL, NULL);
|
||||||
if (err) {
|
if (err) {
|
||||||
LFS_ASSERT(err != LFS_ERR_NOENT);
|
LFS_ASSERT(err != LFS_ERR_NOENT);
|
||||||
@@ -5096,13 +5096,13 @@ static inline int lfsr_mptr_cmp(
|
|||||||
const lfsr_mptr_t *a,
|
const lfsr_mptr_t *a,
|
||||||
const lfsr_mptr_t *b) {
|
const lfsr_mptr_t *b) {
|
||||||
// note these can be in either order
|
// note these can be in either order
|
||||||
if (lfs_max32(a->blocks[0], a->blocks[1])
|
if (lfs_max(a->blocks[0], a->blocks[1])
|
||||||
!= lfs_max32(b->blocks[0], b->blocks[1])) {
|
!= lfs_max(b->blocks[0], b->blocks[1])) {
|
||||||
return lfs_max32(a->blocks[0], a->blocks[1])
|
return lfs_max(a->blocks[0], a->blocks[1])
|
||||||
- lfs_max32(b->blocks[0], b->blocks[1]);
|
- lfs_max(b->blocks[0], b->blocks[1]);
|
||||||
} else {
|
} else {
|
||||||
return lfs_min32(a->blocks[0], a->blocks[1])
|
return lfs_min(a->blocks[0], a->blocks[1])
|
||||||
- lfs_min32(b->blocks[0], b->blocks[1]);
|
- lfs_min(b->blocks[0], b->blocks[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5577,7 +5577,7 @@ static int lfsr_data_readgrm(lfs_t *lfs, lfsr_data_t *data,
|
|||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
LFS_ASSERT((lfsr_mid_t)grm->mids[i] < lfs_max32(
|
LFS_ASSERT((lfsr_mid_t)grm->mids[i] < lfs_max(
|
||||||
lfsr_mtree_weight(&lfs->mtree),
|
lfsr_mtree_weight(&lfs->mtree),
|
||||||
1 << lfs->mdir_bits));
|
1 << lfs->mdir_bits));
|
||||||
}
|
}
|
||||||
@@ -5694,7 +5694,7 @@ static inline uint32_t lfsr_rev_init(lfs_t *lfs, uint32_t rev) {
|
|||||||
// increment revision
|
// increment revision
|
||||||
rev += 1 << 28;
|
rev += 1 << 28;
|
||||||
// xor in a pseudorandom nonce
|
// xor in a pseudorandom nonce
|
||||||
rev ^= ((1 << (28-lfs_smax32(lfs->recycle_bits, 0)))-1) & lfs->seed;
|
rev ^= ((1 << (28-lfs_smax(lfs->recycle_bits, 0)))-1) & lfs->seed;
|
||||||
return rev;
|
return rev;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5704,15 +5704,15 @@ static inline bool lfsr_rev_needsrelocation(lfs_t *lfs, uint32_t rev) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// does out recycle counter overflow?
|
// does out recycle counter overflow?
|
||||||
uint32_t rev_ = rev + (1 << (28-lfs_smax32(lfs->recycle_bits, 0)));
|
uint32_t rev_ = rev + (1 << (28-lfs_smax(lfs->recycle_bits, 0)));
|
||||||
return (rev_ >> 28) != (rev >> 28);
|
return (rev_ >> 28) != (rev >> 28);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t lfsr_rev_inc(lfs_t *lfs, uint32_t rev) {
|
static inline uint32_t lfsr_rev_inc(lfs_t *lfs, uint32_t rev) {
|
||||||
// increment recycle counter/revision
|
// increment recycle counter/revision
|
||||||
rev += 1 << (28-lfs_smax32(lfs->recycle_bits, 0));
|
rev += 1 << (28-lfs_smax(lfs->recycle_bits, 0));
|
||||||
// xor in a pseudorandom nonce
|
// xor in a pseudorandom nonce
|
||||||
rev ^= ((1 << (28-lfs_smax32(lfs->recycle_bits, 0)))-1) & lfs->seed;
|
rev ^= ((1 << (28-lfs_smax(lfs->recycle_bits, 0)))-1) & lfs->seed;
|
||||||
return rev;
|
return rev;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6177,7 +6177,7 @@ static int lfsr_mdir_commit__(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
|
|
||||||
uint8_t shrub_buf[LFSR_SHRUB_DSIZE];
|
uint8_t shrub_buf[LFSR_SHRUB_DSIZE];
|
||||||
int err = lfsr_rbyd_appendattr(lfs, &rbyd_,
|
int err = lfsr_rbyd_appendattr(lfs, &rbyd_,
|
||||||
rid - lfs_smax32(start_rid, 0),
|
rid - lfs_smax(start_rid, 0),
|
||||||
LFSR_ATTR(
|
LFSR_ATTR(
|
||||||
lfsr_tag_mode(attrs[i].tag) | LFSR_TAG_BSHRUB,
|
lfsr_tag_mode(attrs[i].tag) | LFSR_TAG_BSHRUB,
|
||||||
attrs[i].weight,
|
attrs[i].weight,
|
||||||
@@ -6212,7 +6212,7 @@ static int lfsr_mdir_commit__(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
// normal but we need to update any opened inlined files
|
// normal but we need to update any opened inlined files
|
||||||
if (tag == LFSR_TAG_DATA) {
|
if (tag == LFSR_TAG_DATA) {
|
||||||
err = lfsr_rbyd_appendattr(lfs, &rbyd_,
|
err = lfsr_rbyd_appendattr(lfs, &rbyd_,
|
||||||
rid - lfs_smax32(start_rid, 0),
|
rid - lfs_smax(start_rid, 0),
|
||||||
LFSR_ATTR_CAT_(tag, 0, &data, 1));
|
LFSR_ATTR_CAT_(tag, 0, &data, 1));
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
@@ -6244,7 +6244,7 @@ static int lfsr_mdir_commit__(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
// write our new shrub tag
|
// write our new shrub tag
|
||||||
uint8_t shrub_buf[LFSR_SHRUB_DSIZE];
|
uint8_t shrub_buf[LFSR_SHRUB_DSIZE];
|
||||||
err = lfsr_rbyd_appendattr(lfs, &rbyd_,
|
err = lfsr_rbyd_appendattr(lfs, &rbyd_,
|
||||||
rid - lfs_smax32(start_rid, 0),
|
rid - lfs_smax(start_rid, 0),
|
||||||
LFSR_ATTR(
|
LFSR_ATTR(
|
||||||
LFSR_TAG_BSHRUB, 0,
|
LFSR_TAG_BSHRUB, 0,
|
||||||
LFSR_DATA_SHRUB_(&shrub, shrub_buf)));
|
LFSR_DATA_SHRUB_(&shrub, shrub_buf)));
|
||||||
@@ -6255,7 +6255,7 @@ static int lfsr_mdir_commit__(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
// append the attr
|
// append the attr
|
||||||
} else {
|
} else {
|
||||||
err = lfsr_rbyd_appendattr(lfs, &rbyd_,
|
err = lfsr_rbyd_appendattr(lfs, &rbyd_,
|
||||||
rid - lfs_smax32(start_rid, 0),
|
rid - lfs_smax(start_rid, 0),
|
||||||
LFSR_ATTR_CAT_(tag, 0, &data, 1));
|
LFSR_ATTR_CAT_(tag, 0, &data, 1));
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
@@ -6315,7 +6315,7 @@ static int lfsr_mdir_commit__(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
LFS_ASSERT(!lfsr_tag_isinternal(attrs[i].tag));
|
LFS_ASSERT(!lfsr_tag_isinternal(attrs[i].tag));
|
||||||
|
|
||||||
int err = lfsr_rbyd_appendattr(lfs, &rbyd_,
|
int err = lfsr_rbyd_appendattr(lfs, &rbyd_,
|
||||||
rid - lfs_smax32(start_rid, 0),
|
rid - lfs_smax(start_rid, 0),
|
||||||
attrs[i]);
|
attrs[i]);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
@@ -6377,7 +6377,7 @@ static lfs_ssize_t lfsr_mdir_estimate__(lfs_t *lfs, const lfsr_mdir_t *mdir,
|
|||||||
// calculate dsize by starting from the outside ids and working inwards,
|
// calculate dsize by starting from the outside ids and working inwards,
|
||||||
// this naturally gives us a split rid
|
// this naturally gives us a split rid
|
||||||
lfsr_srid_t a_rid = start_rid;
|
lfsr_srid_t a_rid = start_rid;
|
||||||
lfsr_srid_t b_rid = lfs_min32(mdir->rbyd.weight, end_rid);
|
lfsr_srid_t b_rid = lfs_min(mdir->rbyd.weight, end_rid);
|
||||||
lfs_size_t a_dsize = 0;
|
lfs_size_t a_dsize = 0;
|
||||||
lfs_size_t b_dsize = 0;
|
lfs_size_t b_dsize = 0;
|
||||||
lfs_size_t mdir_dsize = 0;
|
lfs_size_t mdir_dsize = 0;
|
||||||
@@ -6908,7 +6908,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
split_relocate:;
|
split_relocate:;
|
||||||
// alloc and compact into new mdirs
|
// alloc and compact into new mdirs
|
||||||
err = lfsr_mdir_alloc__(lfs, &mdir_[i^left],
|
err = lfsr_mdir_alloc__(lfs, &mdir_[i^left],
|
||||||
lfs_smax32(mdir->mid, 0), all);
|
lfs_smax(mdir->mid, 0), all);
|
||||||
if (err) {
|
if (err) {
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
@@ -7135,7 +7135,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
// patch our grm
|
// patch our grm
|
||||||
for (int j = 0; j < 2; j++) {
|
for (int j = 0; j < 2; j++) {
|
||||||
if (lfsr_mid_bid(lfs, lfs->grm.mids[j])
|
if (lfsr_mid_bid(lfs, lfs->grm.mids[j])
|
||||||
== lfsr_mid_bid(lfs, lfs_smax32(mdir->mid, 0))) {
|
== lfsr_mid_bid(lfs, lfs_smax(mdir->mid, 0))) {
|
||||||
if (mdelta > 0
|
if (mdelta > 0
|
||||||
&& lfsr_mid_rid(lfs, lfs->grm.mids[j])
|
&& lfsr_mid_rid(lfs, lfs->grm.mids[j])
|
||||||
>= (lfsr_srid_t)mdir_[0].rbyd.weight) {
|
>= (lfsr_srid_t)mdir_[0].rbyd.weight) {
|
||||||
@@ -8756,7 +8756,7 @@ static int lfsr_formatinited(lfs_t *lfs) {
|
|||||||
// (rev=0), it's also useful for start with -1 and 0 in the upper
|
// (rev=0), it's also useful for start with -1 and 0 in the upper
|
||||||
// bits to help test overflow/sequence comparison
|
// bits to help test overflow/sequence comparison
|
||||||
uint32_t rev = (((uint32_t)i-1) << 28)
|
uint32_t rev = (((uint32_t)i-1) << 28)
|
||||||
| (((1 << (28-lfs_smax32(lfs->recycle_bits, 0)))-1)
|
| (((1 << (28-lfs_smax(lfs->recycle_bits, 0)))-1)
|
||||||
& 0x00216968);
|
& 0x00216968);
|
||||||
err = lfsr_rbyd_appendrev(lfs, &rbyd, rev);
|
err = lfsr_rbyd_appendrev(lfs, &rbyd, rev);
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -8973,7 +8973,7 @@ static int lfs_alloc(lfs_t *lfs, lfs_block_t *block, bool erase) {
|
|||||||
lfs->lookahead.start = (lfs->lookahead.start + lfs->lookahead.size)
|
lfs->lookahead.start = (lfs->lookahead.start + lfs->lookahead.size)
|
||||||
% lfs->block_count;
|
% lfs->block_count;
|
||||||
lfs->lookahead.next = 0;
|
lfs->lookahead.next = 0;
|
||||||
lfs->lookahead.size = lfs_min32(
|
lfs->lookahead.size = lfs_min(
|
||||||
8*lfs->cfg->lookahead_size,
|
8*lfs->cfg->lookahead_size,
|
||||||
lfs->lookahead.ckpoint);
|
lfs->lookahead.ckpoint);
|
||||||
lfs_memset(lfs->lookahead.buffer, 0, lfs->cfg->lookahead_size);
|
lfs_memset(lfs->lookahead.buffer, 0, lfs->cfg->lookahead_size);
|
||||||
@@ -9063,7 +9063,7 @@ static int lfsr_fs_fixgrm(lfs_t *lfs) {
|
|||||||
while (lfsr_grm_hasrm(&lfs->grm)) {
|
while (lfsr_grm_hasrm(&lfs->grm)) {
|
||||||
// find our mdir
|
// find our mdir
|
||||||
lfsr_mdir_t mdir;
|
lfsr_mdir_t mdir;
|
||||||
LFS_ASSERT(lfs->grm.mids[0] < lfs_smax32(
|
LFS_ASSERT(lfs->grm.mids[0] < lfs_smax(
|
||||||
lfsr_mtree_weight(&lfs->mtree),
|
lfsr_mtree_weight(&lfs->mtree),
|
||||||
1 << lfs->mdir_bits));
|
1 << lfs->mdir_bits));
|
||||||
int err = lfsr_mtree_lookup(lfs, &lfs->mtree, lfs->grm.mids[0],
|
int err = lfsr_mtree_lookup(lfs, &lfs->mtree, lfs->grm.mids[0],
|
||||||
@@ -9333,7 +9333,7 @@ int lfsr_mkdir(lfs_t *lfs, const char *path) {
|
|||||||
//
|
//
|
||||||
// Note we also need to be careful to catch integer overflow.
|
// Note we also need to be careful to catch integer overflow.
|
||||||
//
|
//
|
||||||
lfsr_did_t dmask = (1 << lfs_min32(
|
lfsr_did_t dmask = (1 << lfs_min(
|
||||||
lfs_nlog2(lfsr_mtree_weight(&lfs->mtree))
|
lfs_nlog2(lfsr_mtree_weight(&lfs->mtree))
|
||||||
+ lfs_nlog2(lfs->cfg->block_size/32),
|
+ lfs_nlog2(lfs->cfg->block_size/32),
|
||||||
31)) - 1;
|
31)) - 1;
|
||||||
@@ -10140,15 +10140,15 @@ static inline lfs_size_t lfsr_file_buffersize(lfs_t *lfs,
|
|||||||
|
|
||||||
static inline lfs_size_t lfsr_file_inlinesize(lfs_t *lfs,
|
static inline lfs_size_t lfsr_file_inlinesize(lfs_t *lfs,
|
||||||
const lfsr_file_t *file) {
|
const lfsr_file_t *file) {
|
||||||
return lfs_min32(
|
return lfs_min(
|
||||||
lfsr_file_buffersize(lfs, file),
|
lfsr_file_buffersize(lfs, file),
|
||||||
lfs_min32(
|
lfs_min(
|
||||||
lfs->cfg->inline_size,
|
lfs->cfg->inline_size,
|
||||||
lfs->cfg->fragment_size));
|
lfs->cfg->fragment_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline lfs_off_t lfsr_file_size_(const lfsr_file_t *file) {
|
static inline lfs_off_t lfsr_file_size_(const lfsr_file_t *file) {
|
||||||
return lfs_max32(
|
return lfs_max(
|
||||||
file->buffer.pos + file->buffer.size,
|
file->buffer.pos + file->buffer.size,
|
||||||
lfsr_bshrub_size(&file->bshrub));
|
lfsr_bshrub_size(&file->bshrub));
|
||||||
}
|
}
|
||||||
@@ -10613,7 +10613,7 @@ static lfs_ssize_t lfsr_bshrub_readnext(lfs_t *lfs, const lfsr_file_t *file,
|
|||||||
if (pos_ < bid-(weight-1) + lfsr_data_size(bptr.data)) {
|
if (pos_ < bid-(weight-1) + lfsr_data_size(bptr.data)) {
|
||||||
// note one important side-effect here is a strict
|
// note one important side-effect here is a strict
|
||||||
// data hint
|
// data hint
|
||||||
lfs_ssize_t d = lfs_min32(
|
lfs_ssize_t d = lfs_min(
|
||||||
size,
|
size,
|
||||||
lfsr_data_size(bptr.data)
|
lfsr_data_size(bptr.data)
|
||||||
- (pos_ - (bid-(weight-1))));
|
- (pos_ - (bid-(weight-1))));
|
||||||
@@ -10632,7 +10632,7 @@ static lfs_ssize_t lfsr_bshrub_readnext(lfs_t *lfs, const lfsr_file_t *file,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// found a hole? fill with zeros
|
// found a hole? fill with zeros
|
||||||
lfs_ssize_t d = lfs_min32(size, bid+1 - pos_);
|
lfs_ssize_t d = lfs_min(size, bid+1 - pos_);
|
||||||
lfs_memset(buffer, 0, d);
|
lfs_memset(buffer, 0, d);
|
||||||
|
|
||||||
pos_ += d;
|
pos_ += d;
|
||||||
@@ -10877,14 +10877,14 @@ static int lfsr_file_carve(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
if (pos > lfsr_bshrub_size(&file->bshrub)) {
|
if (pos > lfsr_bshrub_size(&file->bshrub)) {
|
||||||
// can we coalesce?
|
// can we coalesce?
|
||||||
if (lfsr_bshrub_size(&file->bshrub) > 0) {
|
if (lfsr_bshrub_size(&file->bshrub) > 0) {
|
||||||
bid = lfs_min32(bid, lfsr_bshrub_size(&file->bshrub)-1);
|
bid = lfs_min(bid, lfsr_bshrub_size(&file->bshrub)-1);
|
||||||
attrs[attr_count++] = LFSR_ATTR(
|
attrs[attr_count++] = LFSR_ATTR(
|
||||||
LFSR_TAG_GROW, +(pos - lfsr_bshrub_size(&file->bshrub)),
|
LFSR_TAG_GROW, +(pos - lfsr_bshrub_size(&file->bshrub)),
|
||||||
LFSR_DATA_NULL());
|
LFSR_DATA_NULL());
|
||||||
|
|
||||||
// new hole
|
// new hole
|
||||||
} else {
|
} else {
|
||||||
bid = lfs_min32(bid, lfsr_bshrub_size(&file->bshrub));
|
bid = lfs_min(bid, lfsr_bshrub_size(&file->bshrub));
|
||||||
attrs[attr_count++] = LFSR_ATTR(
|
attrs[attr_count++] = LFSR_ATTR(
|
||||||
LFSR_TAG_DATA, +(pos - lfsr_bshrub_size(&file->bshrub)),
|
LFSR_TAG_DATA, +(pos - lfsr_bshrub_size(&file->bshrub)),
|
||||||
LFSR_DATA_NULL());
|
LFSR_DATA_NULL());
|
||||||
@@ -11019,8 +11019,8 @@ static int lfsr_file_carve(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
attr.weight += lfs_min32(weight, bid+1 - pos);
|
attr.weight += lfs_min(weight, bid+1 - pos);
|
||||||
weight -= lfs_min32(weight, bid+1 - pos);
|
weight -= lfs_min(weight, bid+1 - pos);
|
||||||
attr_count = 0;
|
attr_count = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -11056,8 +11056,8 @@ static int lfsr_file_carve(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
attr.weight += lfs_min32(weight, bid+1 - pos);
|
attr.weight += lfs_min(weight, bid+1 - pos);
|
||||||
weight -= lfs_min32(weight, bid+1 - pos);
|
weight -= lfs_min(weight, bid+1 - pos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11065,21 +11065,21 @@ static int lfsr_file_carve(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
if (weight + attr.weight > 0) {
|
if (weight + attr.weight > 0) {
|
||||||
// can we coalesce a hole?
|
// can we coalesce a hole?
|
||||||
if (lfsr_attr_size(attr) == 0 && pos > 0) {
|
if (lfsr_attr_size(attr) == 0 && pos > 0) {
|
||||||
bid = lfs_min32(bid, lfsr_bshrub_size(&file->bshrub)-1);
|
bid = lfs_min(bid, lfsr_bshrub_size(&file->bshrub)-1);
|
||||||
attrs[attr_count++] = LFSR_ATTR(
|
attrs[attr_count++] = LFSR_ATTR(
|
||||||
LFSR_TAG_GROW, +(weight + attr.weight),
|
LFSR_TAG_GROW, +(weight + attr.weight),
|
||||||
LFSR_DATA_NULL());
|
LFSR_DATA_NULL());
|
||||||
|
|
||||||
// need a new hole?
|
// need a new hole?
|
||||||
} else if (lfsr_attr_size(attr) == 0) {
|
} else if (lfsr_attr_size(attr) == 0) {
|
||||||
bid = lfs_min32(bid, lfsr_bshrub_size(&file->bshrub));
|
bid = lfs_min(bid, lfsr_bshrub_size(&file->bshrub));
|
||||||
attrs[attr_count++] = LFSR_ATTR(
|
attrs[attr_count++] = LFSR_ATTR(
|
||||||
LFSR_TAG_DATA, +(weight + attr.weight),
|
LFSR_TAG_DATA, +(weight + attr.weight),
|
||||||
LFSR_DATA_NULL());
|
LFSR_DATA_NULL());
|
||||||
|
|
||||||
// append new fragment/bptr?
|
// append new fragment/bptr?
|
||||||
} else {
|
} else {
|
||||||
bid = lfs_min32(bid, lfsr_bshrub_size(&file->bshrub));
|
bid = lfs_min(bid, lfsr_bshrub_size(&file->bshrub));
|
||||||
attrs[attr_count++] = LFSR_ATTR_(
|
attrs[attr_count++] = LFSR_ATTR_(
|
||||||
attr.tag, +(weight + attr.weight),
|
attr.tag, +(weight + attr.weight),
|
||||||
attr.cat, attr.count);
|
attr.cat, attr.count);
|
||||||
@@ -11137,7 +11137,7 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
lfsr_tag_t tag;
|
lfsr_tag_t tag;
|
||||||
lfsr_bid_t weight;
|
lfsr_bid_t weight;
|
||||||
int err = lfsr_bshrub_lookupnext(lfs, file,
|
int err = lfsr_bshrub_lookupnext(lfs, file,
|
||||||
lfs_smax32(pos - (lfs->cfg->crystal_thresh-1), 0),
|
lfs_smax(pos - (lfs->cfg->crystal_thresh-1), 0),
|
||||||
&bid, &tag, &weight, &bptr);
|
&bid, &tag, &weight, &bptr);
|
||||||
if (err) {
|
if (err) {
|
||||||
LFS_ASSERT(err != LFS_ERR_NOENT);
|
LFS_ASSERT(err != LFS_ERR_NOENT);
|
||||||
@@ -11154,7 +11154,7 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
|
|
||||||
// otherwise our neighbor determines our crystal boundary
|
// otherwise our neighbor determines our crystal boundary
|
||||||
} else {
|
} else {
|
||||||
crystal_start = lfs_min32(bid+1, pos);
|
crystal_start = lfs_min(bid+1, pos);
|
||||||
|
|
||||||
// wait, found erased-state?
|
// wait, found erased-state?
|
||||||
if (tag == LFSR_TAG_BLOCK
|
if (tag == LFSR_TAG_BLOCK
|
||||||
@@ -11186,7 +11186,7 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
lfsr_tag_t tag;
|
lfsr_tag_t tag;
|
||||||
lfsr_bid_t weight;
|
lfsr_bid_t weight;
|
||||||
int err = lfsr_bshrub_lookupnext(lfs, file,
|
int err = lfsr_bshrub_lookupnext(lfs, file,
|
||||||
lfs_min32(
|
lfs_min(
|
||||||
crystal_start + (lfs->cfg->crystal_thresh-1),
|
crystal_start + (lfs->cfg->crystal_thresh-1),
|
||||||
lfsr_bshrub_size(&file->bshrub)-1),
|
lfsr_bshrub_size(&file->bshrub)-1),
|
||||||
&bid, &tag, &weight, &bptr);
|
&bid, &tag, &weight, &bptr);
|
||||||
@@ -11198,13 +11198,13 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
// if right crystal neighbor is a fragment, include as a part
|
// if right crystal neighbor is a fragment, include as a part
|
||||||
// of our crystal
|
// of our crystal
|
||||||
if (tag == LFSR_TAG_DATA) {
|
if (tag == LFSR_TAG_DATA) {
|
||||||
crystal_end = lfs_max32(
|
crystal_end = lfs_max(
|
||||||
bid-(weight-1)+lfsr_data_size(bptr.data),
|
bid-(weight-1)+lfsr_data_size(bptr.data),
|
||||||
pos + size);
|
pos + size);
|
||||||
|
|
||||||
// otherwise treat as crystal boundary
|
// otherwise treat as crystal boundary
|
||||||
} else {
|
} else {
|
||||||
crystal_end = lfs_max32(
|
crystal_end = lfs_max(
|
||||||
bid-(weight-1),
|
bid-(weight-1),
|
||||||
pos + size);
|
pos + size);
|
||||||
}
|
}
|
||||||
@@ -11231,7 +11231,7 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
lfsr_tag_t tag;
|
lfsr_tag_t tag;
|
||||||
lfsr_bid_t weight;
|
lfsr_bid_t weight;
|
||||||
int err = lfsr_bshrub_lookupnext(lfs, file,
|
int err = lfsr_bshrub_lookupnext(lfs, file,
|
||||||
lfs_min32(
|
lfs_min(
|
||||||
crystal_start-1,
|
crystal_start-1,
|
||||||
lfsr_bshrub_size(&file->bshrub)-1),
|
lfsr_bshrub_size(&file->bshrub)-1),
|
||||||
&bid, &tag, &weight, &bptr);
|
&bid, &tag, &weight, &bptr);
|
||||||
@@ -11291,24 +11291,24 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
// eagerly merge any right neighbors we see unless that would
|
// eagerly merge any right neighbors we see unless that would
|
||||||
// put us over our block size
|
// put us over our block size
|
||||||
lfs_off_t pos_ = block_start + lfsr_data_size(bptr.data);
|
lfs_off_t pos_ = block_start + lfsr_data_size(bptr.data);
|
||||||
while (pos_ < lfs_min32(
|
while (pos_ < lfs_min(
|
||||||
block_start
|
block_start
|
||||||
+ (lfs->cfg->block_size - bptr.data.u.disk.off),
|
+ (lfs->cfg->block_size - bptr.data.u.disk.off),
|
||||||
lfs_max32(
|
lfs_max(
|
||||||
pos + size,
|
pos + size,
|
||||||
lfsr_bshrub_size(&file->bshrub)))) {
|
lfsr_bshrub_size(&file->bshrub)))) {
|
||||||
// keep track of the next highest priority data offset
|
// keep track of the next highest priority data offset
|
||||||
lfs_ssize_t d = lfs_min32(
|
lfs_ssize_t d = lfs_min(
|
||||||
block_start
|
block_start
|
||||||
+ (lfs->cfg->block_size - bptr.data.u.disk.off),
|
+ (lfs->cfg->block_size - bptr.data.u.disk.off),
|
||||||
lfs_max32(
|
lfs_max(
|
||||||
pos + size,
|
pos + size,
|
||||||
lfsr_bshrub_size(&file->bshrub))) - pos_;
|
lfsr_bshrub_size(&file->bshrub))) - pos_;
|
||||||
|
|
||||||
// any data in our buffer?
|
// any data in our buffer?
|
||||||
if (pos_ < pos + size && size > 0) {
|
if (pos_ < pos + size && size > 0) {
|
||||||
if (pos_ >= pos) {
|
if (pos_ >= pos) {
|
||||||
lfs_ssize_t d_ = lfs_min32(
|
lfs_ssize_t d_ = lfs_min(
|
||||||
d,
|
d,
|
||||||
size - (pos_ - pos));
|
size - (pos_ - pos));
|
||||||
err = lfsr_bd_prog(lfs, bptr.data.u.disk.block,
|
err = lfsr_bd_prog(lfs, bptr.data.u.disk.block,
|
||||||
@@ -11330,7 +11330,7 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// buffered data takes priority
|
// buffered data takes priority
|
||||||
d = lfs_min32(d, pos - pos_);
|
d = lfs_min(d, pos - pos_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// any data on disk?
|
// any data on disk?
|
||||||
@@ -11365,7 +11365,7 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
if (pos_ < bid_-(weight_-1) + lfsr_data_size(bptr_.data)) {
|
if (pos_ < bid_-(weight_-1) + lfsr_data_size(bptr_.data)) {
|
||||||
// note one important side-effect here is a strict
|
// note one important side-effect here is a strict
|
||||||
// data hint
|
// data hint
|
||||||
lfs_ssize_t d_ = lfs_min32(
|
lfs_ssize_t d_ = lfs_min(
|
||||||
d,
|
d,
|
||||||
lfsr_data_size(bptr_.data)
|
lfsr_data_size(bptr_.data)
|
||||||
- (pos_ - (bid_-(weight_-1))));
|
- (pos_ - (bid_-(weight_-1))));
|
||||||
@@ -11390,7 +11390,7 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// found a hole? just make sure next leaf takes priority
|
// found a hole? just make sure next leaf takes priority
|
||||||
d = lfs_min32(d, bid_+1 - pos_);
|
d = lfs_min(d, bid_+1 - pos_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// found a hole? fill with zeros
|
// found a hole? fill with zeros
|
||||||
@@ -11456,10 +11456,10 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
|
|
||||||
// note compacting fragments -> blocks may not actually make any
|
// note compacting fragments -> blocks may not actually make any
|
||||||
// progress on flushing the buffer on the first pass
|
// progress on flushing the buffer on the first pass
|
||||||
d = lfs_max32(pos, block_end) - pos;
|
d = lfs_max(pos, block_end) - pos;
|
||||||
pos += d;
|
pos += d;
|
||||||
buffer += lfs_min32(d, size);
|
buffer += lfs_min(d, size);
|
||||||
size -= lfs_min32(d, size);
|
size -= lfs_min(d, size);
|
||||||
aligned = true;
|
aligned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11468,7 +11468,7 @@ fragment:;
|
|||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
// truncate to our fragment size
|
// truncate to our fragment size
|
||||||
lfs_off_t fragment_start = pos;
|
lfs_off_t fragment_start = pos;
|
||||||
lfs_off_t fragment_end = fragment_start + lfs_min32(
|
lfs_off_t fragment_end = fragment_start + lfs_min(
|
||||||
size,
|
size,
|
||||||
lfs->cfg->fragment_size);
|
lfs->cfg->fragment_size);
|
||||||
|
|
||||||
@@ -11500,7 +11500,7 @@ fragment:;
|
|||||||
fragment_start - (bid-(weight-1)));
|
fragment_start - (bid-(weight-1)));
|
||||||
|
|
||||||
fragment_start = bid-(weight-1);
|
fragment_start = bid-(weight-1);
|
||||||
fragment_end = fragment_start + lfs_min32(
|
fragment_end = fragment_start + lfs_min(
|
||||||
fragment_end - (bid-(weight-1)),
|
fragment_end - (bid-(weight-1)),
|
||||||
lfs->cfg->fragment_size);
|
lfs->cfg->fragment_size);
|
||||||
}
|
}
|
||||||
@@ -11538,7 +11538,7 @@ fragment:;
|
|||||||
bid-(weight-1) + lfsr_data_size(bptr.data)
|
bid-(weight-1) + lfsr_data_size(bptr.data)
|
||||||
- fragment_end);
|
- fragment_end);
|
||||||
|
|
||||||
fragment_end = fragment_start + lfs_min32(
|
fragment_end = fragment_start + lfs_min(
|
||||||
bid-(weight-1) + lfsr_data_size(bptr.data)
|
bid-(weight-1) + lfsr_data_size(bptr.data)
|
||||||
- fragment_start,
|
- fragment_start,
|
||||||
lfs->cfg->fragment_size);
|
lfs->cfg->fragment_size);
|
||||||
@@ -11562,8 +11562,8 @@ fragment:;
|
|||||||
// to next fragment
|
// to next fragment
|
||||||
lfs_ssize_t d = fragment_end - pos;
|
lfs_ssize_t d = fragment_end - pos;
|
||||||
pos += d;
|
pos += d;
|
||||||
buffer += lfs_min32(d, size);
|
buffer += lfs_min(d, size);
|
||||||
size -= lfs_min32(d, size);
|
size -= lfs_min(d, size);
|
||||||
aligned = true;
|
aligned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11583,13 +11583,13 @@ lfs_ssize_t lfsr_file_read(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
uint8_t *buffer_ = buffer;
|
uint8_t *buffer_ = buffer;
|
||||||
while (size > 0 && pos_ < lfsr_file_size_(file)) {
|
while (size > 0 && pos_ < lfsr_file_size_(file)) {
|
||||||
// keep track of the next highest priority data offset
|
// keep track of the next highest priority data offset
|
||||||
lfs_ssize_t d = lfs_min32(size, lfsr_file_size_(file) - pos_);
|
lfs_ssize_t d = lfs_min(size, lfsr_file_size_(file) - pos_);
|
||||||
|
|
||||||
// any data in our buffer?
|
// any data in our buffer?
|
||||||
if (pos_ < file->buffer.pos + file->buffer.size
|
if (pos_ < file->buffer.pos + file->buffer.size
|
||||||
&& file->buffer.size != 0) {
|
&& file->buffer.size != 0) {
|
||||||
if (pos_ >= file->buffer.pos) {
|
if (pos_ >= file->buffer.pos) {
|
||||||
lfs_ssize_t d_ = lfs_min32(
|
lfs_ssize_t d_ = lfs_min(
|
||||||
d,
|
d,
|
||||||
file->buffer.size - (pos_ - file->buffer.pos));
|
file->buffer.size - (pos_ - file->buffer.pos));
|
||||||
lfs_memcpy(buffer_,
|
lfs_memcpy(buffer_,
|
||||||
@@ -11604,7 +11604,7 @@ lfs_ssize_t lfsr_file_read(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// buffered data takes priority
|
// buffered data takes priority
|
||||||
d = lfs_min32(d, file->buffer.pos - pos_);
|
d = lfs_min(d, file->buffer.pos - pos_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// any data in our btree?
|
// any data in our btree?
|
||||||
@@ -11760,14 +11760,14 @@ lfs_ssize_t lfsr_file_write(lfs_t *lfs, lfsr_file_t *file,
|
|||||||
file->buffer.size = 0;
|
file->buffer.size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
lfs_size_t d = lfs_min32(
|
lfs_size_t d = lfs_min(
|
||||||
size,
|
size,
|
||||||
lfsr_file_buffersize(lfs, file)
|
lfsr_file_buffersize(lfs, file)
|
||||||
- (pos - file->buffer.pos));
|
- (pos - file->buffer.pos));
|
||||||
lfs_memcpy(&file->buffer.buffer[pos - file->buffer.pos],
|
lfs_memcpy(&file->buffer.buffer[pos - file->buffer.pos],
|
||||||
buffer_,
|
buffer_,
|
||||||
d);
|
d);
|
||||||
file->buffer.size = lfs_max32(
|
file->buffer.size = lfs_max(
|
||||||
file->buffer.size,
|
file->buffer.size,
|
||||||
pos+d - file->buffer.pos);
|
pos+d - file->buffer.pos);
|
||||||
|
|
||||||
@@ -12109,7 +12109,7 @@ int lfsr_file_truncate(lfs_t *lfs, lfsr_file_t *file, lfs_off_t size_) {
|
|||||||
// if our data is not already in our buffer we unfortunately
|
// if our data is not already in our buffer we unfortunately
|
||||||
// need to flush so our buffer is available to hold everything
|
// need to flush so our buffer is available to hold everything
|
||||||
if (file->buffer.pos > 0
|
if (file->buffer.pos > 0
|
||||||
|| file->buffer.size < lfs_min32(
|
|| file->buffer.size < lfs_min(
|
||||||
size_,
|
size_,
|
||||||
lfsr_bshrub_size(&file->bshrub))) {
|
lfsr_bshrub_size(&file->bshrub))) {
|
||||||
err = lfsr_file_flush(lfs, file);
|
err = lfsr_file_flush(lfs, file);
|
||||||
@@ -12146,7 +12146,7 @@ int lfsr_file_truncate(lfs_t *lfs, lfsr_file_t *file, lfs_off_t size_) {
|
|||||||
} else {
|
} else {
|
||||||
// truncate our btree
|
// truncate our btree
|
||||||
err = lfsr_file_carve(lfs, file,
|
err = lfsr_file_carve(lfs, file,
|
||||||
lfs_min32(size, size_), size - lfs_min32(size, size_),
|
lfs_min(size, size_), size - lfs_min(size, size_),
|
||||||
LFSR_ATTR(
|
LFSR_ATTR(
|
||||||
LFSR_TAG_DATA, +size_ - size,
|
LFSR_TAG_DATA, +size_ - size,
|
||||||
LFSR_DATA_NULL()));
|
LFSR_DATA_NULL()));
|
||||||
@@ -12155,10 +12155,10 @@ int lfsr_file_truncate(lfs_t *lfs, lfsr_file_t *file, lfs_off_t size_) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// truncate our buffer
|
// truncate our buffer
|
||||||
file->buffer.pos = lfs_min32(file->buffer.pos, size_);
|
file->buffer.pos = lfs_min(file->buffer.pos, size_);
|
||||||
file->buffer.size = lfs_min32(
|
file->buffer.size = lfs_min(
|
||||||
file->buffer.size,
|
file->buffer.size,
|
||||||
size_ - lfs_min32(file->buffer.pos, size_));
|
size_ - lfs_min(file->buffer.pos, size_));
|
||||||
}
|
}
|
||||||
|
|
||||||
// mark as unsynced
|
// mark as unsynced
|
||||||
@@ -12215,7 +12215,7 @@ int lfsr_file_fruncate(lfs_t *lfs, lfsr_file_t *file, lfs_off_t size_) {
|
|||||||
// need to flush so our buffer is available to hold everything
|
// need to flush so our buffer is available to hold everything
|
||||||
if (file->buffer.pos + file->buffer.size
|
if (file->buffer.pos + file->buffer.size
|
||||||
< lfsr_bshrub_size(&file->bshrub)
|
< lfsr_bshrub_size(&file->bshrub)
|
||||||
|| file->buffer.size < lfs_min32(
|
|| file->buffer.size < lfs_min(
|
||||||
size_,
|
size_,
|
||||||
lfsr_bshrub_size(&file->bshrub))) {
|
lfsr_bshrub_size(&file->bshrub))) {
|
||||||
err = lfsr_file_flush(lfs, file);
|
err = lfsr_file_flush(lfs, file);
|
||||||
@@ -12226,7 +12226,7 @@ int lfsr_file_fruncate(lfs_t *lfs, lfsr_file_t *file, lfs_off_t size_) {
|
|||||||
file->buffer.size = 0;
|
file->buffer.size = 0;
|
||||||
|
|
||||||
lfs_ssize_t d = lfsr_bshrub_read(lfs, file,
|
lfs_ssize_t d = lfsr_bshrub_read(lfs, file,
|
||||||
lfsr_bshrub_size(&file->bshrub) - lfs_min32(
|
lfsr_bshrub_size(&file->bshrub) - lfs_min(
|
||||||
size_,
|
size_,
|
||||||
lfsr_bshrub_size(&file->bshrub)),
|
lfsr_bshrub_size(&file->bshrub)),
|
||||||
file->buffer.buffer, size_);
|
file->buffer.buffer, size_);
|
||||||
@@ -12264,7 +12264,7 @@ int lfsr_file_fruncate(lfs_t *lfs, lfsr_file_t *file, lfs_off_t size_) {
|
|||||||
} else {
|
} else {
|
||||||
// fruncate our btree
|
// fruncate our btree
|
||||||
err = lfsr_file_carve(lfs, file,
|
err = lfsr_file_carve(lfs, file,
|
||||||
0, lfs_smax32(size - size_, 0),
|
0, lfs_smax(size - size_, 0),
|
||||||
LFSR_ATTR(
|
LFSR_ATTR(
|
||||||
LFSR_TAG_DATA, +size_ - size,
|
LFSR_TAG_DATA, +size_ - size,
|
||||||
LFSR_DATA_NULL()));
|
LFSR_DATA_NULL()));
|
||||||
@@ -12274,22 +12274,22 @@ int lfsr_file_fruncate(lfs_t *lfs, lfsr_file_t *file, lfs_off_t size_) {
|
|||||||
|
|
||||||
// fruncate our buffer
|
// fruncate our buffer
|
||||||
lfs_memmove(file->buffer.buffer,
|
lfs_memmove(file->buffer.buffer,
|
||||||
&file->buffer.buffer[lfs_min32(
|
&file->buffer.buffer[lfs_min(
|
||||||
lfs_smax32(
|
lfs_smax(
|
||||||
size - size_ - file->buffer.pos,
|
size - size_ - file->buffer.pos,
|
||||||
0),
|
0),
|
||||||
file->buffer.size)],
|
file->buffer.size)],
|
||||||
file->buffer.size - lfs_min32(
|
file->buffer.size - lfs_min(
|
||||||
lfs_smax32(
|
lfs_smax(
|
||||||
size - size_ - file->buffer.pos,
|
size - size_ - file->buffer.pos,
|
||||||
0),
|
0),
|
||||||
file->buffer.size));
|
file->buffer.size));
|
||||||
file->buffer.size -= lfs_min32(
|
file->buffer.size -= lfs_min(
|
||||||
lfs_smax32(
|
lfs_smax(
|
||||||
size - size_ - file->buffer.pos,
|
size - size_ - file->buffer.pos,
|
||||||
0),
|
0),
|
||||||
file->buffer.size);
|
file->buffer.size);
|
||||||
file->buffer.pos -= lfs_smin32(
|
file->buffer.pos -= lfs_smin(
|
||||||
size - size_,
|
size - size_,
|
||||||
file->buffer.pos);
|
file->buffer.pos);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-29
@@ -154,42 +154,16 @@ static inline uint32_t lfs_max(uint32_t a, uint32_t b) {
|
|||||||
return (a > b) ? a : b;
|
return (a > b) ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t lfs_min32(uint32_t a, uint32_t b) {
|
static inline int32_t lfs_smin(int32_t a, int32_t b) {
|
||||||
return (a < b) ? a : b;
|
return (a < b) ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t lfs_max32(uint32_t a, uint32_t b) {
|
static inline int32_t lfs_smax(int32_t a, int32_t b) {
|
||||||
return (a > b) ? a : b;
|
return (a > b) ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int32_t lfs_smin32(int32_t a, int32_t b) {
|
|
||||||
return (a < b) ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int32_t lfs_smax32(int32_t a, int32_t b) {
|
|
||||||
return (a > b) ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO other 16-bit ops?
|
|
||||||
static inline uint16_t lfs_min16(uint16_t a, uint16_t b) {
|
|
||||||
return (a < b) ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint16_t lfs_max16(uint16_t a, uint16_t b) {
|
|
||||||
return (a > b) ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clamp is useful as the logic for min/max when clamping can become confusing
|
|
||||||
static inline uint32_t lfs_clamp32(uint32_t a, uint32_t min, uint32_t max) {
|
|
||||||
return lfs_min32(lfs_max32(a, min), max);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int32_t lfs_sclamp32(int32_t a, int32_t min, int32_t max) {
|
|
||||||
return lfs_smin32(lfs_smax32(a, min), max);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Absolute value of signed numbers
|
// Absolute value of signed numbers
|
||||||
static inline int32_t lfs_abs32(int32_t a) {
|
static inline int32_t lfs_abs(int32_t a) {
|
||||||
return (a < 0) ? -a : a;
|
return (a < 0) ? -a : a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -817,7 +817,7 @@ code = '''
|
|||||||
// choose a random location
|
// choose a random location
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
// and a random size, up to the chunk size
|
// and a random size, up to the chunk size
|
||||||
lfs_size_t chunk = lfs_min32(
|
lfs_size_t chunk = lfs_min(
|
||||||
TEST_PRNG(&prng) % CHUNK,
|
TEST_PRNG(&prng) % CHUNK,
|
||||||
SIZE - off);
|
SIZE - off);
|
||||||
|
|
||||||
@@ -826,7 +826,7 @@ code = '''
|
|||||||
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
}
|
}
|
||||||
if (chunk != 0) {
|
if (chunk != 0) {
|
||||||
size = lfs_max32(size, off+chunk);
|
size = lfs_max(size, off+chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update file
|
// update file
|
||||||
@@ -2518,7 +2518,7 @@ code = '''
|
|||||||
// choose a random location
|
// choose a random location
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
// and a random size, up to the chunk size
|
// and a random size, up to the chunk size
|
||||||
lfs_size_t chunk = lfs_min32(
|
lfs_size_t chunk = lfs_min(
|
||||||
TEST_PRNG(&prng) % CHUNK,
|
TEST_PRNG(&prng) % CHUNK,
|
||||||
SIZE - off);
|
SIZE - off);
|
||||||
|
|
||||||
@@ -2527,7 +2527,7 @@ code = '''
|
|||||||
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
}
|
}
|
||||||
if (chunk != 0) {
|
if (chunk != 0) {
|
||||||
size = lfs_max32(size, off+chunk);
|
size = lfs_max(size, off+chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update file
|
// update file
|
||||||
@@ -4214,7 +4214,7 @@ code = '''
|
|||||||
// choose a random location
|
// choose a random location
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
// and a random size, up to the chunk size
|
// and a random size, up to the chunk size
|
||||||
lfs_size_t chunk = lfs_min32(
|
lfs_size_t chunk = lfs_min(
|
||||||
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
||||||
SIZE - off);
|
SIZE - off);
|
||||||
|
|
||||||
@@ -4222,7 +4222,7 @@ code = '''
|
|||||||
for (lfs_size_t j = 0; j < chunk; j++) {
|
for (lfs_size_t j = 0; j < chunk; j++) {
|
||||||
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
}
|
}
|
||||||
size = lfs_max32(size, off+chunk);
|
size = lfs_max(size, off+chunk);
|
||||||
|
|
||||||
// update file
|
// update file
|
||||||
lfsr_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
||||||
|
|||||||
@@ -580,7 +580,7 @@ code = '''
|
|||||||
// choose a random location
|
// choose a random location
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
// and a random size, up to the chunk size
|
// and a random size, up to the chunk size
|
||||||
lfs_size_t chunk = lfs_min32(
|
lfs_size_t chunk = lfs_min(
|
||||||
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
||||||
SIZE - off);
|
SIZE - off);
|
||||||
|
|
||||||
@@ -588,7 +588,7 @@ code = '''
|
|||||||
for (lfs_size_t j = 0; j < chunk; j++) {
|
for (lfs_size_t j = 0; j < chunk; j++) {
|
||||||
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
}
|
}
|
||||||
size = lfs_max32(size, off+chunk);
|
size = lfs_max(size, off+chunk);
|
||||||
|
|
||||||
// update file
|
// update file
|
||||||
lfsr_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
||||||
|
|||||||
+26
-26
@@ -573,7 +573,7 @@ code = '''
|
|||||||
for (lfs_size_t r = 0; r < R; r++) {
|
for (lfs_size_t r = 0; r < R; r++) {
|
||||||
// choose a random offset
|
// choose a random offset
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
lfsr_file_seek(&lfs, &readers[r], off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &readers[r], off, LFS_SEEK_SET) => off;
|
||||||
|
|
||||||
// read
|
// read
|
||||||
@@ -733,7 +733,7 @@ code = '''
|
|||||||
for (lfs_size_t i = 0; i < N; i++) {
|
for (lfs_size_t i = 0; i < N; i++) {
|
||||||
// choose a random offset
|
// choose a random offset
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
lfsr_file_seek(&lfs, &writer, off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &writer, off, LFS_SEEK_SET) => off;
|
||||||
|
|
||||||
// write
|
// write
|
||||||
@@ -753,7 +753,7 @@ code = '''
|
|||||||
for (lfs_size_t r = 0; r < R; r++) {
|
for (lfs_size_t r = 0; r < R; r++) {
|
||||||
// choose a random offset
|
// choose a random offset
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
lfsr_file_seek(&lfs, &readers[r], off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &readers[r], off, LFS_SEEK_SET) => off;
|
||||||
|
|
||||||
// read
|
// read
|
||||||
@@ -919,7 +919,7 @@ code = '''
|
|||||||
for (lfs_size_t w = 0; w < W; w++) {
|
for (lfs_size_t w = 0; w < W; w++) {
|
||||||
// choose a random offset
|
// choose a random offset
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
lfsr_file_seek(&lfs, &writers[w], off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &writers[w], off, LFS_SEEK_SET) => off;
|
||||||
|
|
||||||
// write
|
// write
|
||||||
@@ -1117,7 +1117,7 @@ code = '''
|
|||||||
for (lfs_size_t w = 0; w < W; w++) {
|
for (lfs_size_t w = 0; w < W; w++) {
|
||||||
// choose a random offset
|
// choose a random offset
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
lfsr_file_seek(&lfs, &writers[w], off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &writers[w], off, LFS_SEEK_SET) => off;
|
||||||
|
|
||||||
// write
|
// write
|
||||||
@@ -1143,7 +1143,7 @@ code = '''
|
|||||||
for (lfs_size_t r = 0; r < R; r++) {
|
for (lfs_size_t r = 0; r < R; r++) {
|
||||||
// choose a random offset
|
// choose a random offset
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
lfsr_file_seek(&lfs, &readers[r], off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &readers[r], off, LFS_SEEK_SET) => off;
|
||||||
|
|
||||||
// read
|
// read
|
||||||
@@ -1331,7 +1331,7 @@ code = '''
|
|||||||
for (lfs_size_t rw = 0; rw < RW; rw++) {
|
for (lfs_size_t rw = 0; rw < RW; rw++) {
|
||||||
// choose a random offset
|
// choose a random offset
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
||||||
|
|
||||||
// write
|
// write
|
||||||
@@ -1358,7 +1358,7 @@ code = '''
|
|||||||
for (lfs_size_t rw = 0; rw < RW; rw++) {
|
for (lfs_size_t rw = 0; rw < RW; rw++) {
|
||||||
// choose a random offset
|
// choose a random offset
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
||||||
|
|
||||||
// read
|
// read
|
||||||
@@ -1443,7 +1443,7 @@ code = '''
|
|||||||
lfs_off_t off = (between_size[rw] > 0)
|
lfs_off_t off = (between_size[rw] > 0)
|
||||||
? TEST_PRNG(&prng) % between_size[rw]
|
? TEST_PRNG(&prng) % between_size[rw]
|
||||||
: 0;
|
: 0;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
uint8_t wbuf[CHUNK];
|
uint8_t wbuf[CHUNK];
|
||||||
for (lfs_size_t j = 0; j < size; j++) {
|
for (lfs_size_t j = 0; j < size; j++) {
|
||||||
wbuf[j] = 'a' + (TEST_PRNG(&prng) % 26);
|
wbuf[j] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
@@ -1466,7 +1466,7 @@ code = '''
|
|||||||
off - between_size[rw]);
|
off - between_size[rw]);
|
||||||
}
|
}
|
||||||
memcpy(&between[rw][off], wbuf, size);
|
memcpy(&between[rw][off], wbuf, size);
|
||||||
between_size[rw] = lfs_max32(off + size, between_size[rw]);
|
between_size[rw] = lfs_max(off + size, between_size[rw]);
|
||||||
|
|
||||||
// reading?
|
// reading?
|
||||||
} else if (op == 1) {
|
} else if (op == 1) {
|
||||||
@@ -1474,7 +1474,7 @@ code = '''
|
|||||||
lfs_off_t off = (between_size[rw] > 0)
|
lfs_off_t off = (between_size[rw] > 0)
|
||||||
? TEST_PRNG(&prng) % between_size[rw]
|
? TEST_PRNG(&prng) % between_size[rw]
|
||||||
: 0;
|
: 0;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, between_size[rw] - off);
|
lfs_size_t size = lfs_min(CHUNK, between_size[rw] - off);
|
||||||
|
|
||||||
// read
|
// read
|
||||||
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
||||||
@@ -1578,7 +1578,7 @@ code = '''
|
|||||||
lfs_off_t off = (between_size[rw] > 0)
|
lfs_off_t off = (between_size[rw] > 0)
|
||||||
? TEST_PRNG(&prng) % between_size[rw]
|
? TEST_PRNG(&prng) % between_size[rw]
|
||||||
: 0;
|
: 0;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
uint8_t wbuf[CHUNK];
|
uint8_t wbuf[CHUNK];
|
||||||
for (lfs_size_t j = 0; j < size; j++) {
|
for (lfs_size_t j = 0; j < size; j++) {
|
||||||
wbuf[j] = 'a' + (TEST_PRNG(&prng) % 26);
|
wbuf[j] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
@@ -1601,7 +1601,7 @@ code = '''
|
|||||||
off - between_size[rw]);
|
off - between_size[rw]);
|
||||||
}
|
}
|
||||||
memcpy(&between[rw][off], wbuf, size);
|
memcpy(&between[rw][off], wbuf, size);
|
||||||
between_size[rw] = lfs_max32(off + size, between_size[rw]);
|
between_size[rw] = lfs_max(off + size, between_size[rw]);
|
||||||
|
|
||||||
// reading?
|
// reading?
|
||||||
} else if (op == 1) {
|
} else if (op == 1) {
|
||||||
@@ -1609,7 +1609,7 @@ code = '''
|
|||||||
lfs_off_t off = (between_size[rw] > 0)
|
lfs_off_t off = (between_size[rw] > 0)
|
||||||
? TEST_PRNG(&prng) % between_size[rw]
|
? TEST_PRNG(&prng) % between_size[rw]
|
||||||
: 0;
|
: 0;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, between_size[rw] - off);
|
lfs_size_t size = lfs_min(CHUNK, between_size[rw] - off);
|
||||||
|
|
||||||
// read
|
// read
|
||||||
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
||||||
@@ -2479,7 +2479,7 @@ code = '''
|
|||||||
for (lfs_size_t i = 0; i < N; i++) {
|
for (lfs_size_t i = 0; i < N; i++) {
|
||||||
// choose a random offset
|
// choose a random offset
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
lfsr_file_seek(&lfs, &writer, off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &writer, off, LFS_SEEK_SET) => off;
|
||||||
|
|
||||||
// write
|
// write
|
||||||
@@ -2499,7 +2499,7 @@ code = '''
|
|||||||
for (lfs_size_t r = 0; r < R; r++) {
|
for (lfs_size_t r = 0; r < R; r++) {
|
||||||
// choose a random offset
|
// choose a random offset
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
lfsr_file_seek(&lfs, &readers[r], off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &readers[r], off, LFS_SEEK_SET) => off;
|
||||||
|
|
||||||
// read
|
// read
|
||||||
@@ -2673,7 +2673,7 @@ code = '''
|
|||||||
for (lfs_size_t i = 0; i < N; i++) {
|
for (lfs_size_t i = 0; i < N; i++) {
|
||||||
// choose a random offset
|
// choose a random offset
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
lfsr_file_seek(&lfs, &writer, off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &writer, off, LFS_SEEK_SET) => off;
|
||||||
|
|
||||||
// write
|
// write
|
||||||
@@ -2693,7 +2693,7 @@ code = '''
|
|||||||
for (lfs_size_t r = 0; r < R; r++) {
|
for (lfs_size_t r = 0; r < R; r++) {
|
||||||
// choose a random offset
|
// choose a random offset
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
lfsr_file_seek(&lfs, &readers[r], off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &readers[r], off, LFS_SEEK_SET) => off;
|
||||||
|
|
||||||
// read
|
// read
|
||||||
@@ -2885,7 +2885,7 @@ code = '''
|
|||||||
for (lfs_size_t rw = 0; rw < RW; rw++) {
|
for (lfs_size_t rw = 0; rw < RW; rw++) {
|
||||||
// choose a random offset
|
// choose a random offset
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
||||||
|
|
||||||
// write
|
// write
|
||||||
@@ -2916,7 +2916,7 @@ code = '''
|
|||||||
for (lfs_size_t rw = 0; rw < RW; rw++) {
|
for (lfs_size_t rw = 0; rw < RW; rw++) {
|
||||||
// choose a random offset
|
// choose a random offset
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
||||||
|
|
||||||
// read
|
// read
|
||||||
@@ -3004,7 +3004,7 @@ code = '''
|
|||||||
lfs_off_t off = (between_size[rw] > 0)
|
lfs_off_t off = (between_size[rw] > 0)
|
||||||
? TEST_PRNG(&prng) % between_size[rw]
|
? TEST_PRNG(&prng) % between_size[rw]
|
||||||
: 0;
|
: 0;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
uint8_t wbuf[CHUNK];
|
uint8_t wbuf[CHUNK];
|
||||||
for (lfs_size_t j = 0; j < size; j++) {
|
for (lfs_size_t j = 0; j < size; j++) {
|
||||||
wbuf[j] = 'a' + (TEST_PRNG(&prng) % 26);
|
wbuf[j] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
@@ -3024,7 +3024,7 @@ code = '''
|
|||||||
off - between_size[rw]);
|
off - between_size[rw]);
|
||||||
}
|
}
|
||||||
memcpy(&between[rw][off], wbuf, size);
|
memcpy(&between[rw][off], wbuf, size);
|
||||||
between_size[rw] = lfs_max32(off + size, between_size[rw]);
|
between_size[rw] = lfs_max(off + size, between_size[rw]);
|
||||||
|
|
||||||
// reading?
|
// reading?
|
||||||
} else if (op == 1) {
|
} else if (op == 1) {
|
||||||
@@ -3032,7 +3032,7 @@ code = '''
|
|||||||
lfs_off_t off = (between_size[rw] > 0)
|
lfs_off_t off = (between_size[rw] > 0)
|
||||||
? TEST_PRNG(&prng) % between_size[rw]
|
? TEST_PRNG(&prng) % between_size[rw]
|
||||||
: 0;
|
: 0;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, between_size[rw] - off);
|
lfs_size_t size = lfs_min(CHUNK, between_size[rw] - off);
|
||||||
|
|
||||||
// read
|
// read
|
||||||
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
||||||
@@ -3154,7 +3154,7 @@ code = '''
|
|||||||
lfs_off_t off = (between_size[rw] > 0)
|
lfs_off_t off = (between_size[rw] > 0)
|
||||||
? TEST_PRNG(&prng) % between_size[rw]
|
? TEST_PRNG(&prng) % between_size[rw]
|
||||||
: 0;
|
: 0;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, SIZE - off);
|
lfs_size_t size = lfs_min(CHUNK, SIZE - off);
|
||||||
uint8_t wbuf[CHUNK];
|
uint8_t wbuf[CHUNK];
|
||||||
for (lfs_size_t j = 0; j < size; j++) {
|
for (lfs_size_t j = 0; j < size; j++) {
|
||||||
wbuf[j] = 'a' + (TEST_PRNG(&prng) % 26);
|
wbuf[j] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
@@ -3174,7 +3174,7 @@ code = '''
|
|||||||
off - between_size[rw]);
|
off - between_size[rw]);
|
||||||
}
|
}
|
||||||
memcpy(&between[rw][off], wbuf, size);
|
memcpy(&between[rw][off], wbuf, size);
|
||||||
between_size[rw] = lfs_max32(off + size, between_size[rw]);
|
between_size[rw] = lfs_max(off + size, between_size[rw]);
|
||||||
|
|
||||||
// reading?
|
// reading?
|
||||||
} else if (op == 1) {
|
} else if (op == 1) {
|
||||||
@@ -3182,7 +3182,7 @@ code = '''
|
|||||||
lfs_off_t off = (between_size[rw] > 0)
|
lfs_off_t off = (between_size[rw] > 0)
|
||||||
? TEST_PRNG(&prng) % between_size[rw]
|
? TEST_PRNG(&prng) % between_size[rw]
|
||||||
: 0;
|
: 0;
|
||||||
lfs_size_t size = lfs_min32(CHUNK, between_size[rw] - off);
|
lfs_size_t size = lfs_min(CHUNK, between_size[rw] - off);
|
||||||
|
|
||||||
// read
|
// read
|
||||||
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &rdwrs[rw], off, LFS_SEEK_SET) => off;
|
||||||
|
|||||||
+23
-23
@@ -515,8 +515,8 @@ code = '''
|
|||||||
lfsr_file_open(&lfs, &file, "hello",
|
lfsr_file_open(&lfs, &file, "hello",
|
||||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0;
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0;
|
||||||
// simulate our file in ram
|
// simulate our file in ram
|
||||||
uint8_t sim[lfs_max32(FROM,TO)];
|
uint8_t sim[lfs_max(FROM,TO)];
|
||||||
memset(sim, 0, lfs_max32(FROM,TO));
|
memset(sim, 0, lfs_max(FROM,TO));
|
||||||
uint32_t prng = 42;
|
uint32_t prng = 42;
|
||||||
for (lfs_size_t i = 0; i < FROM; i++) {
|
for (lfs_size_t i = 0; i < FROM; i++) {
|
||||||
sim[i] = 'a' + (TEST_PRNG(&prng) % 26);
|
sim[i] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
@@ -640,8 +640,8 @@ code = '''
|
|||||||
lfsr_file_open(&lfs, &file, "hello",
|
lfsr_file_open(&lfs, &file, "hello",
|
||||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0;
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0;
|
||||||
// simulate our file in ram
|
// simulate our file in ram
|
||||||
uint8_t sim[lfs_max32(FROM,lfs_max32(AND,TO))];
|
uint8_t sim[lfs_max(FROM,lfs_max(AND,TO))];
|
||||||
memset(sim, 0, lfs_max32(FROM,lfs_max32(AND,TO)));
|
memset(sim, 0, lfs_max(FROM,lfs_max(AND,TO)));
|
||||||
uint32_t prng = 42;
|
uint32_t prng = 42;
|
||||||
for (lfs_size_t i = 0; i < FROM; i++) {
|
for (lfs_size_t i = 0; i < FROM; i++) {
|
||||||
sim[i] = 'a' + (TEST_PRNG(&prng) % 26);
|
sim[i] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
@@ -773,8 +773,8 @@ code = '''
|
|||||||
lfsr_file_open(&lfs, &file, "hello",
|
lfsr_file_open(&lfs, &file, "hello",
|
||||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0;
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0;
|
||||||
// simulate our file in ram
|
// simulate our file in ram
|
||||||
uint8_t sim[lfs_max32(FROM,TO)];
|
uint8_t sim[lfs_max(FROM,TO)];
|
||||||
memset(sim, 0, lfs_max32(FROM,TO));
|
memset(sim, 0, lfs_max(FROM,TO));
|
||||||
uint32_t prng = 42;
|
uint32_t prng = 42;
|
||||||
for (lfs_size_t i = 0; i < FROM; i++) {
|
for (lfs_size_t i = 0; i < FROM; i++) {
|
||||||
sim[i] = 'a' + (TEST_PRNG(&prng) % 26);
|
sim[i] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
@@ -902,8 +902,8 @@ code = '''
|
|||||||
lfsr_file_open(&lfs, &file, "hello",
|
lfsr_file_open(&lfs, &file, "hello",
|
||||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0;
|
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0;
|
||||||
// simulate our file in ram
|
// simulate our file in ram
|
||||||
uint8_t sim[lfs_max32(FROM,lfs_max32(AND,TO))];
|
uint8_t sim[lfs_max(FROM,lfs_max(AND,TO))];
|
||||||
memset(sim, 0, lfs_max32(FROM,lfs_max32(AND,TO)));
|
memset(sim, 0, lfs_max(FROM,lfs_max(AND,TO)));
|
||||||
uint32_t prng = 42;
|
uint32_t prng = 42;
|
||||||
for (lfs_size_t i = 0; i < FROM; i++) {
|
for (lfs_size_t i = 0; i < FROM; i++) {
|
||||||
sim[i] = 'a' + (TEST_PRNG(&prng) % 26);
|
sim[i] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
@@ -1595,7 +1595,7 @@ code = '''
|
|||||||
for (lfs_size_t j = 0; j < CHUNK; j++) {
|
for (lfs_size_t j = 0; j < CHUNK; j++) {
|
||||||
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
}
|
}
|
||||||
size = lfs_max32(size, off+CHUNK);
|
size = lfs_max(size, off+CHUNK);
|
||||||
|
|
||||||
// update file
|
// update file
|
||||||
lfsr_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
||||||
@@ -1735,7 +1735,7 @@ code = '''
|
|||||||
// choose a random location
|
// choose a random location
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
// and a random size, up to the chunk size
|
// and a random size, up to the chunk size
|
||||||
lfs_size_t chunk = lfs_min32(
|
lfs_size_t chunk = lfs_min(
|
||||||
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
||||||
SIZE - off);
|
SIZE - off);
|
||||||
|
|
||||||
@@ -1743,7 +1743,7 @@ code = '''
|
|||||||
for (lfs_size_t j = 0; j < chunk; j++) {
|
for (lfs_size_t j = 0; j < chunk; j++) {
|
||||||
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
}
|
}
|
||||||
size = lfs_max32(size, off+chunk);
|
size = lfs_max(size, off+chunk);
|
||||||
|
|
||||||
// update file
|
// update file
|
||||||
lfsr_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
||||||
@@ -1858,7 +1858,7 @@ code = '''
|
|||||||
// choose a random location
|
// choose a random location
|
||||||
lfs_soff_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_soff_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
// and a random size, up to the chunk size
|
// and a random size, up to the chunk size
|
||||||
lfs_size_t chunk = lfs_min32(
|
lfs_size_t chunk = lfs_min(
|
||||||
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
||||||
SIZE - off);
|
SIZE - off);
|
||||||
|
|
||||||
@@ -1953,7 +1953,7 @@ code = '''
|
|||||||
// choose a random location
|
// choose a random location
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
// and a random size, up to the chunk size
|
// and a random size, up to the chunk size
|
||||||
lfs_size_t chunk = lfs_min32(
|
lfs_size_t chunk = lfs_min(
|
||||||
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
||||||
SIZE - off);
|
SIZE - off);
|
||||||
|
|
||||||
@@ -1973,7 +1973,7 @@ code = '''
|
|||||||
for (lfs_size_t j = 0; j < chunk; j++) {
|
for (lfs_size_t j = 0; j < chunk; j++) {
|
||||||
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
}
|
}
|
||||||
size = lfs_max32(size, off+chunk);
|
size = lfs_max(size, off+chunk);
|
||||||
|
|
||||||
// update the file
|
// update the file
|
||||||
lfsr_file_write(&lfs, &file, &sim[off], chunk) => chunk;
|
lfsr_file_write(&lfs, &file, &sim[off], chunk) => chunk;
|
||||||
@@ -2100,7 +2100,7 @@ code = '''
|
|||||||
// choose a random location
|
// choose a random location
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
// and a random size, up to the chunk size
|
// and a random size, up to the chunk size
|
||||||
lfs_size_t chunk = lfs_min32(
|
lfs_size_t chunk = lfs_min(
|
||||||
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
||||||
SIZE - off);
|
SIZE - off);
|
||||||
// and if we are reading or writing
|
// and if we are reading or writing
|
||||||
@@ -2124,7 +2124,7 @@ code = '''
|
|||||||
for (lfs_size_t j = 0; j < chunk; j++) {
|
for (lfs_size_t j = 0; j < chunk; j++) {
|
||||||
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
}
|
}
|
||||||
size = lfs_max32(size, off+chunk);
|
size = lfs_max(size, off+chunk);
|
||||||
|
|
||||||
// update the file
|
// update the file
|
||||||
lfsr_file_write(&lfs, &file, &sim[off], chunk) => chunk;
|
lfsr_file_write(&lfs, &file, &sim[off], chunk) => chunk;
|
||||||
@@ -2143,9 +2143,9 @@ code = '''
|
|||||||
// reading?
|
// reading?
|
||||||
} else if (op == 1) {
|
} else if (op == 1) {
|
||||||
// we may read less than chunk if we're past eof
|
// we may read less than chunk if we're past eof
|
||||||
lfs_off_t expected = lfs_min32(
|
lfs_off_t expected = lfs_min(
|
||||||
chunk,
|
chunk,
|
||||||
size - lfs_min32(off, size));
|
size - lfs_min(off, size));
|
||||||
|
|
||||||
// read the file and assert we got the correct data
|
// read the file and assert we got the correct data
|
||||||
uint8_t rbuf[2*SIZE];
|
uint8_t rbuf[2*SIZE];
|
||||||
@@ -2394,7 +2394,7 @@ code = '''
|
|||||||
// choose a random location
|
// choose a random location
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
// and a random size, up to the chunk size
|
// and a random size, up to the chunk size
|
||||||
lfs_size_t chunk = lfs_min32(
|
lfs_size_t chunk = lfs_min(
|
||||||
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
||||||
SIZE - off);
|
SIZE - off);
|
||||||
|
|
||||||
@@ -2405,7 +2405,7 @@ code = '''
|
|||||||
for (lfs_size_t j = 0; j < chunk; j++) {
|
for (lfs_size_t j = 0; j < chunk; j++) {
|
||||||
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
sim[off+j] = 'a' + (TEST_PRNG(&prng) % 26);
|
||||||
}
|
}
|
||||||
size = lfs_max32(size, off+chunk);
|
size = lfs_max(size, off+chunk);
|
||||||
|
|
||||||
// update the file
|
// update the file
|
||||||
lfsr_file_write(&lfs, &file, &sim[off], chunk) => chunk;
|
lfsr_file_write(&lfs, &file, &sim[off], chunk) => chunk;
|
||||||
@@ -2428,7 +2428,7 @@ code = '''
|
|||||||
// choose a random location
|
// choose a random location
|
||||||
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
lfs_off_t off = TEST_PRNG(&prng) % SIZE;
|
||||||
// and a random size, up to the chunk size
|
// and a random size, up to the chunk size
|
||||||
lfs_size_t chunk = lfs_min32(
|
lfs_size_t chunk = lfs_min(
|
||||||
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
(TEST_PRNG(&prng) % (CHUNK+1-1)) + 1,
|
||||||
SIZE - off);
|
SIZE - off);
|
||||||
|
|
||||||
@@ -2436,9 +2436,9 @@ code = '''
|
|||||||
lfsr_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
lfsr_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
||||||
|
|
||||||
// we may read less than chunk if we're past eof
|
// we may read less than chunk if we're past eof
|
||||||
lfs_off_t expected = lfs_min32(
|
lfs_off_t expected = lfs_min(
|
||||||
chunk,
|
chunk,
|
||||||
size - lfs_min32(off, size));
|
size - lfs_min(off, size));
|
||||||
|
|
||||||
// read the file and assert we got the correct data
|
// read the file and assert we got the correct data
|
||||||
uint8_t rbuf[2*SIZE];
|
uint8_t rbuf[2*SIZE];
|
||||||
|
|||||||
Reference in New Issue
Block a user