Originally proposed by @kaetemi, this API allows you to change the size of the filesystem on disk to take advantage of additional space if it becomes available:
cfg.block_count = 1024;
int err = lfs_mount(lfs, cfg);
if (err) {
return err;
}
struct lfs_fsstat fsstat;
err = lfs_fs_stat(lfs, &fsstat);
if (err) {
return err;
}
printf("block_count: %d\n", fsstat.block_count); // prints 1024
err = lfs_fs_grow(lfs, 2048);
if (err) {
return err;
}
struct lfs_fsstat fsstat;
err = lfs_fs_stat(lfs, &fsstat);
if (err) {
return err;
}
printf("block_count: %d\n", fsstat.block_count); // prints 2048
If you want to automatically resize littlefs to the full disk size every mount, this can be done by using these two calls as your "mount" operation:
lfs_size_t required_block_count = DISK_SIZE / BLOCK_SIZE;
// unknown block_count
cfg.block_count = 0;
// mount and resize if disk has grown
int err = lfs_mount(lfs, cfg);
if (err) {
return err;
}
err = lfs_fs_grow(lfs, required_block_count);
if (err) {
return err;
}
Originally proposed by @kaetemi, this API allows you to change the size of the filesystem on disk to take advantage of additional space if it becomes available:
If you want to automatically resize littlefs to the full disk size every mount, this can be done by using these two calls as your "mount" operation:
See https://github.com/littlefs-project/littlefs/pull/702, https://github.com/littlefs-project/littlefs/issues/279, and https://github.com/littlefs-project/littlefs/pull/753 for related discussions.
This depends on https://github.com/littlefs-project/littlefs/pull/866, which makes
block_size
optional