how can I determine how many files are open on the SD card?
how can I determine how many files are open on the SD card?
well the subject is the question. I studied a lot. VFS driver etc. may be somebody knows the solution ?
-
- Posts: 9772
- Joined: Thu Nov 26, 2015 4:08 am
Re: how can I determine how many files are open on the SD card?
That sounds a bit like an X-Y problem... Why would you need to know that?
Re: how can I determine how many files are open on the SD card?
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
-
- Posts: 94
- Joined: Tue Sep 07, 2021 12:07 pm
Re: how can I determine how many files are open on the SD card?
Thanks for that: https://en.wikipedia.org/wiki/XY_problem
I did not know it had a name.
I did not know it had a name.
Craige
Re: how can I determine how many files are open on the SD card?
@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.
somebody must have done this before.
-
- Posts: 9772
- Joined: Thu Nov 26, 2015 4:08 am
Re: how can I determine how many files are open on the SD card?
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.
Re: how can I determine how many files are open on the SD card?
@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.
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.
-
- Posts: 9772
- Joined: Thu Nov 26, 2015 4:08 am
Re: how can I determine how many files are open on the SD card?
Okidoki, good luck with that then.
Who is online
Users browsing this forum: Bing [Bot] and 98 guests