Skip to content

Available space #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
davidefer opened this issue Mar 28, 2018 · 7 comments
Closed

Available space #45

davidefer opened this issue Mar 28, 2018 · 7 comments

Comments

@davidefer
Copy link

Hi
first of all thank you very much for having developed littlefs.

I have a question concerning the available space on the storage: how to calculate it?
Thank you in advance.

@guillaumerems
Copy link

Hi davidefer,
Here is my implementation of a df function:

static int _traverse_df_cb(void *p, lfs_block_t block){
	uint32_t *nb = p;
	*nb += 1;
	return 0;
}
static int _df(void){
	int err;

	uint32_t _df_nballocatedblock = 0;
	err = lfs_traverse(&_lfs, _traverse_df_cb, &_df_nballocatedblock);
	if(err < 0){
		return err;
	}

	uint32_t available = _lfs_cfg.block_count*BLOCK_SIZE- _df_nballocatedblock*BLOCK_SIZE;

	return available;
}

It counts the allocated block then as we know the number of total block we can know how many block are available

@davidefer
Copy link
Author

Thank you guillaumerems, it works.
Do you know if it would be possible to get the amount of bad blocks (blocks which have reported an error while writing/erasing)?

@geky
Copy link
Member

geky commented Apr 7, 2018

Thanks @guillaumerems!

It sounds like we should probably add a lfs_fs_size function or something since this feature has been requested fairly often.

@davidefer, littlefs itself doesn't actually know which blocks are bad until it tries to write to them. It just doesn't store this information.

@geky
Copy link
Member

geky commented Apr 9, 2018

I went ahead and tacked on a lfs_fs_size function to this pr #48 so it should be in v1.4. Hopefully that will be easier to use.

@tomvarghese
Copy link

I tried this code and it works if I mount the fs and check before and after an operation. However, if I unmount and remount, this number appears to reset to the original value before I did the operation. Am I missing something simple?

@geky
Copy link
Member

geky commented Apr 1, 2019

@tomvarghese, that should not happen. Is it possible to create a small program that reproduces this? Thanks.

@tomvarghese
Copy link

tomvarghese commented Apr 1, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants