You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Flavio Castro Alves Filho <fl...@gmail.com> on 2021/05/28 12:21:13 UTC

Support for disk full detection using LittleFS

Hello,

I am using LittleFS to store information on an external dataflash.

I need to know if the memory is full. I saw that the nsh provides the
df command, which as far as I understood is a cat for /proc/fs/usage
file.

In my code, I could see the LFS message indicating LFS_ERR_NOSPC,
which is an error message indicating no more space when writing files.
But the return from the fwrite call is OK (indicating the number of
written bytes) :-|

Is /proc/fs/usage available for LittleFS? Is there any way to get the
disk space programmatically?

Best regards,

Flavio

-- 
Flavio de Castro Alves Filho

flavio.alves@gmail.com
Twitter: http://twitter.com/#!/fraviofii
LinkedIn profile: www.linkedin.com/in/flaviocastroalves

Re: Support for disk full detection using LittleFS

Posted by Xiang Xiao <xi...@gmail.com>.
On Fri, May 28, 2021 at 8:21 PM Flavio Castro Alves Filho <
flavio.alves@gmail.com> wrote:

> Hello,
>
> I am using LittleFS to store information on an external dataflash.
>
> I need to know if the memory is full. I saw that the nsh provides the
> df command, which as far as I understood is a cat for /proc/fs/usage
> file.
>
> In my code, I could see the LFS message indicating LFS_ERR_NOSPC,
> which is an error message indicating no more space when writing files.
> But the return from the fwrite call is OK (indicating the number of
> written bytes) :-|
>
>
This behaviour may be due to LittleFS not really committing the change to
disk until you call flush or close the file.


> Is /proc/fs/usage available for LittleFS? Is there any way to get the
> disk space programmatically?
>

You could call statfs and check f_bavail/f_bfree field:
https://github.com/apache/incubator-nuttx/blob/master/fs/littlefs/lfs_vfs.c#L1148-L1184


>
> Best regards,
>
> Flavio
>
> --
> Flavio de Castro Alves Filho
>
> flavio.alves@gmail.com
> Twitter: http://twitter.com/#!/fraviofii
> LinkedIn profile: www.linkedin.com/in/flaviocastroalves
>

Re: Support for disk full detection using LittleFS

Posted by Takashi Yamamoto <ya...@midokura.com.INVALID>.
On Fri, May 28, 2021 at 9:21 PM Flavio Castro Alves Filho
<fl...@gmail.com> wrote:
>
> Hello,
>
> I am using LittleFS to store information on an external dataflash.
>
> I need to know if the memory is full. I saw that the nsh provides the
> df command, which as far as I understood is a cat for /proc/fs/usage
> file.
>
> In my code, I could see the LFS message indicating LFS_ERR_NOSPC,
> which is an error message indicating no more space when writing files.
> But the return from the fwrite call is OK (indicating the number of
> written bytes) :-|

if your FILE is buffered, you may just need fflush or fclose and check
the error.
in that case, it's an expected behavior.

otherwise, sounds like a bug in the OS.

>
> Is /proc/fs/usage available for LittleFS? Is there any way to get the
> disk space programmatically?
>
> Best regards,
>
> Flavio
>
> --
> Flavio de Castro Alves Filho
>
> flavio.alves@gmail.com
> Twitter: http://twitter.com/#!/fraviofii
> LinkedIn profile: www.linkedin.com/in/flaviocastroalves