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.
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
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)?
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.
I went ahead and tacked on a lfs_fs_size function to this pr https://github.com/geky/littlefs/pull/48 so it should be in v1.4. Hopefully that will be easier to use.
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?
@tomvarghese, that should not happen. Is it possible to create a small program that reproduces this? Thanks.
I just found the problem yesterday evening. It was a bug in my code, was not closing the file before unmounting.
Thanks for your response though. Really appreciate it.
Tom
From: Christopher Haster notifications@github.com
Sent: Monday, April 1, 2019 12:57 AM
To: ARMmbed/littlefs littlefs@noreply.github.com
Cc: Thomas Varghese tomv@onyxmicro.com; Mention mention@noreply.github.com
Subject: Re: [ARMmbed/littlefs] Available space (#45)
@tomvarghesehttps://github.com/tomvarghese, that should not happen. Is it possible to create a small program that reproduces this? Thanks.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/ARMmbed/littlefs/issues/45#issuecomment-478445648, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AN9FN1bcJpYOSiIrRxe5D-ufOhXGpfRCks5vcZ-YgaJpZM4S-txS.