how can I determine how many files are open on the SD card?

RalphD
Posts: 103
Joined: Thu Nov 25, 2021 9:02 pm

how can I determine how many files are open on the SD card?

Postby RalphD » Sun Jul 24, 2022 8:02 pm

well the subject is the question. I studied a lot. VFS driver etc. may be somebody knows the solution ?

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

Re: how can I determine how many files are open on the SD card?

Postby ESP_Sprite » Mon Jul 25, 2022 3:44 am

That sounds a bit like an X-Y problem... Why would you need to know that?

abansal22
Posts: 105
Joined: Wed Apr 22, 2020 8:24 am

Re: how can I determine how many files are open on the SD card?

Postby abansal22 » Mon Jul 25, 2022 1:32 pm

RalphD wrote:
Sun Jul 24, 2022 8:02 pm
well the subject is the question. I studied a lot. VFS driver etc. may be somebody knows the solution ?
I am not aware of any function, but you can take one variable named index.Whenever you open file just increment the index pointer and when ever you closes the file just decrement the index pointer. Any time you can call the index which let you know the files open in the system.

Thanks
Ankit Bansal

Craige Hales
Posts: 94
Joined: Tue Sep 07, 2021 12:07 pm

Re: how can I determine how many files are open on the SD card?

Postby Craige Hales » Mon Jul 25, 2022 1:49 pm

Thanks for that: https://en.wikipedia.org/wiki/XY_problem
I did not know it had a name.
Craige

RalphD
Posts: 103
Joined: Thu Nov 25, 2021 9:02 pm

Re: how can I determine how many files are open on the SD card?

Postby RalphD » Mon Jul 25, 2022 4:54 pm

@ESP_sprite your question let me without words .... in multitask applications it may be likely that one task wants to reboot the device but don't you think a reboot with an open file is a good thing? and many more applications in a multitask environment. I was simply hoping to spare not to fiddle through the FATFS driver code.

somebody must have done this before.

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

Re: how can I determine how many files are open on the SD card?

Postby ESP_Sprite » Tue Jul 26, 2022 2:59 am

RalphD wrote:
Mon Jul 25, 2022 4:54 pm
@ESP_sprite your question let me without words .... in multitask applications it may be likely that one task wants to reboot the device but don't you think a reboot with an open file is a good thing? and many more applications in a multitask environment.
There we go; your actual question would be something like 'How do I make sure the SD card filesystem is in a consistent state when I order a reboot, without modifying the code that accesses the files'?

The answer is: I don't think you can, not without running the risk of corruption anyway. The thing is that even if you had a way of finding out the amount of files open, you'd run into a race condition: between the query and you shutting down the ESP chip, a thread may have opened a file, and you'll still get corruption

Note that in embedded devices, a voluntary reboot is actually not that common: it's way more common for the battery to run empty, the user pulls the power plug, a crash happens, whatnot. So in general, you should already develop your application with the capability to recover from e.g. half-written files in mind. If you do that, you get 'free' protection from that happening on a voluntary reboot as well.

RalphD
Posts: 103
Joined: Thu Nov 25, 2021 9:02 pm

Re: how can I determine how many files are open on the SD card?

Postby RalphD » Tue Jul 26, 2022 9:31 am

@ESP_sprite absolutely not my question. Leave it, you are too far out of real world applications and requirements.
The info I m looking for is there, in the FATFS driver. The fact that you have to give the number of allowed open files indicates that there is a structure having the space for n open file descriptors. This is the source to look at if I want to know how many files are open.

ESP_Sprite
Posts: 9764
Joined: Thu Nov 26, 2015 4:08 am

Re: how can I determine how many files are open on the SD card?

Postby ESP_Sprite » Wed Jul 27, 2022 12:38 am

Okidoki, good luck with that then.

Who is online

Users browsing this forum: No registered users and 218 guests