diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f3100bee..0815867c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -374,6 +374,22 @@ jobs: run: | CFLAGS="$CFLAGS -DLFS_NO_INTRINSICS" make test + test-shrink: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: install + run: | + # need a few things + sudo apt-get update -qq + sudo apt-get install -qq gcc python3 python3-pip + pip3 install toml + gcc --version + python3 --version + - name: test-no-intrinsics + run: | + CFLAGS="$CFLAGS -DLFS_SHRINKIFCHEAP" make test + # run with all trace options enabled to at least make sure these # all compile test-yes-trace: diff --git a/lfs.h b/lfs.h index be98b54b..a8e35eed 100644 --- a/lfs.h +++ b/lfs.h @@ -766,11 +766,11 @@ int lfs_fs_gc(lfs_t *lfs); // Grows the filesystem to a new size, updating the superblock with the new // block count. // -// if LFS_SHRINKIFCHEAP is defined, this function will also accept +// If LFS_SHRINKIFCHEAP is defined, this function will also accept // block_counts smaller than the current configuration, after checking // that none of the blocks that are being removed are in use. -// -// Note: This is irreversible. +// Note that littlefs's pseudorandom block allocation means that +// this is very unlikely to work in the general case. // // Returns a negative error code on failure. int lfs_fs_grow(lfs_t *lfs, lfs_size_t block_count); diff --git a/tests/test_shrink.toml b/tests/test_shrink.toml index 10c00ae8..47610485 100644 --- a/tests/test_shrink.toml +++ b/tests/test_shrink.toml @@ -2,8 +2,10 @@ [cases.test_shrink_simple] defines.BLOCK_COUNT = [10, 15, 20] defines.AFTER_BLOCK_COUNT = [5, 10, 15, 19] + if = "AFTER_BLOCK_COUNT <= BLOCK_COUNT" code = ''' +#ifdef LFS_SHRINKIFCHEAP lfs_t lfs; lfs_format(&lfs, cfg) => 0; lfs_mount(&lfs, cfg) => 0; @@ -18,6 +20,7 @@ code = ''' lfs2.cfg = &cfg2; lfs_mount(&lfs2, &cfg2) => 0; lfs_unmount(&lfs2) => 0; +#endif ''' # shrinking full @@ -27,6 +30,7 @@ defines.AFTER_BLOCK_COUNT = [5, 7, 10, 12, 15, 17, 20] defines.FILES_COUNT = [7, 8, 9, 10] if = "AFTER_BLOCK_COUNT <= BLOCK_COUNT && FILES_COUNT + 2 < BLOCK_COUNT" code = ''' +#ifdef LFS_SHRINKIFCHEAP lfs_t lfs; lfs_format(&lfs, cfg) => 0; // create FILES_COUNT files of BLOCK_SIZE - 50 bytes (to avoid inlining) @@ -101,4 +105,5 @@ code = ''' } lfs_unmount(&lfs2); } +#endif ''' diff --git a/tests/test_superblocks.toml b/tests/test_superblocks.toml index 4daf764b..188e4339 100644 --- a/tests/test_superblocks.toml +++ b/tests/test_superblocks.toml @@ -531,6 +531,7 @@ defines.BLOCK_COUNT = 'ERASE_COUNT' defines.BLOCK_COUNT_2 = ['ERASE_COUNT/2', 'ERASE_COUNT/4', '2'] defines.KNOWN_BLOCK_COUNT = [true, false] code = ''' +#ifdef LFS_SHRINKIFCHEAP lfs_t lfs; lfs_format(&lfs, cfg) => 0; @@ -628,6 +629,7 @@ code = ''' lfs_file_close(&lfs, &file) => 0; assert(memcmp(buffer, "hello!", 6) == 0); lfs_unmount(&lfs) => 0; +#endif ''' # test that metadata_max does not cause problems for superblock compaction