@@ -2358,6 +2358,13 @@ static lfs3_scmp_t lfs3_attr_cmp(lfs3_t *lfs3, const struct lfs3_attr *attr,
23582358// to avoid the mess of redeclaring flags and things, just declare
23592359// everything we need here
23602360
2361+ // block allocator flags
2362+ #define LFS3_ALLOC_ERASE 0x000000001 // Please erase the block
2363+
2364+ static inline bool lfs3_alloc_iserase (uint32_t flags ) {
2365+ return flags & LFS3_ALLOC_ERASE ;
2366+ }
2367+
23612368// checkpoint the allocator
23622369//
23632370// operations that need to alloc should call this when all in-use blocks
@@ -2376,7 +2383,7 @@ static inline void lfs3_alloc_discard(lfs3_t *lfs3);
23762383
23772384// allocate a block
23782385#if !defined(LFS3_RDONLY ) && !defined(LFS3_2BONLY )
2379- static lfs3_sblock_t lfs3_alloc (lfs3_t * lfs3 , bool erase );
2386+ static lfs3_sblock_t lfs3_alloc (lfs3_t * lfs3 , uint32_t flags );
23802387#endif
23812388
23822389
@@ -2764,7 +2771,7 @@ static inline int lfs3_rbyd_cmp(
27642771// allocate an rbyd block
27652772#if !defined(LFS3_RDONLY ) && !defined(LFS3_2BONLY )
27662773static int lfs3_rbyd_alloc (lfs3_t * lfs3 , lfs3_rbyd_t * rbyd ) {
2767- lfs3_sblock_t block = lfs3_alloc (lfs3 , true );
2774+ lfs3_sblock_t block = lfs3_alloc (lfs3 , LFS3_ALLOC_ERASE );
27682775 if (block < 0 ) {
27692776 return block ;
27702777 }
@@ -8045,7 +8052,7 @@ static int lfs3_mdir_alloc__(lfs3_t *lfs3, lfs3_mdir_t *mdir,
80458052
80468053 if (!partial ) {
80478054 // allocate one block without an erase
8048- lfs3_sblock_t block = lfs3_alloc (lfs3 , false );
8055+ lfs3_sblock_t block = lfs3_alloc (lfs3 , 0 );
80498056 if (block < 0 ) {
80508057 return block ;
80518058 }
@@ -8069,7 +8076,7 @@ static int lfs3_mdir_alloc__(lfs3_t *lfs3, lfs3_mdir_t *mdir,
80698076
80708077relocate :;
80718078 // allocate another block with an erase
8072- lfs3_sblock_t block = lfs3_alloc (lfs3 , true );
8079+ lfs3_sblock_t block = lfs3_alloc (lfs3 , LFS3_ALLOC_ERASE );
80738080 if (block < 0 ) {
80748081 return block ;
80758082 }
@@ -10418,7 +10425,7 @@ static inline lfs3_size_t lfs3_graft_count(lfs3_size_t graft_count);
1041810425
1041910426// allocate a block
1042010427#if !defined(LFS3_RDONLY ) && !defined(LFS3_2BONLY )
10421- static lfs3_sblock_t lfs3_alloc (lfs3_t * lfs3 , bool erase ) {
10428+ static lfs3_sblock_t lfs3_alloc (lfs3_t * lfs3 , uint32_t flags ) {
1042210429 while (true) {
1042310430 // scan our lookahead buffer for free blocks
1042410431 lfs3_sblock_t block = lfs3_alloc_findfree (lfs3 );
@@ -10431,7 +10438,7 @@ static lfs3_sblock_t lfs3_alloc(lfs3_t *lfs3, bool erase) {
1043110438 LFS3_ASSERT (block != 0 && block != 1 );
1043210439
1043310440 // erase requested?
10434- if (erase ) {
10441+ if (lfs3_alloc_iserase ( flags ) ) {
1043510442 int err = lfs3_bd_erase (lfs3 , block );
1043610443 if (err ) {
1043710444 // bad erase? try another block
@@ -12666,7 +12673,7 @@ static int lfs3_file_crystallize__(lfs3_t *lfs3, lfs3_file_t *file,
1266612673 //
1266712674 // note if we relocate, we rewrite the entire block from
1266812675 // block_pos using what we can find in our tree
12669- lfs3_sblock_t block = lfs3_alloc (lfs3 , true );
12676+ lfs3_sblock_t block = lfs3_alloc (lfs3 , LFS3_ALLOC_ERASE );
1267012677 if (block < 0 ) {
1267112678 return block ;
1267212679 }
@@ -12770,7 +12777,7 @@ static int lfs3_file_flushset_(lfs3_t *lfs3, lfs3_file_t *file,
1277012777
1277112778 relocate :;
1277212779 // allocate a new block
12773- lfs3_sblock_t block = lfs3_alloc (lfs3 , true );
12780+ lfs3_sblock_t block = lfs3_alloc (lfs3 , LFS3_ALLOC_ERASE );
1277412781 if (block < 0 ) {
1277512782 return block ;
1277612783 }
0 commit comments