FSRW: opendir with filesize, create time?
SRLM
Posts: 5,045
Is there any way to iterate through all the files on the SD card and get the filename, the creation time, and the file size? Does anybody have a path to add this information to nextfile()?
Comments
If you have a closer look at sdfat#DIRSIZE, then you'll see that one directory-entry has a size of 32. The first 8 bytes are the filename, the next 3 bytes are the extension.
The rest contains the file mode, start cluster, date, size and so on. The size is stored in the last 4 bytes in this buffer.
term.dec( long[ @dirbuf ][ $1c ] )
should do the job. The date is not usefull if you access files created by FSRW, as FSRW does write a fixed value. Kyes SD driver supports time information if an RTC is available - as far as I remember.
That being said, I have gone through the source and done a bunch of cleanups and optimizations. It's pretty light weight now. You can see the source here: https://github.com/libpropeller/libpropeller/tree/master/libpropeller/sd
The main addition that I made was the error handling. Unfortunately, C++ doesn't have a good equivalent to abort, and I couldn't get exceptions small enough. So I came up with an error code system. Not the best, and kind of clunky, but it works well.
On a side note: much of libpropeller is based on the equivalent spin objects: FFDS1, PWM32, FSRW, MCP3208, and the Quadrature Encoder were all Spin objects. I'd like to think that I did a good job porting them (both in readability and performance), but I'm open to any suggestions.
Exceptions would be the best, but no matter what I did I couldn't get the code size down enough to be effective. I got it to fit, but just barely. My SD unit tests were somewhere around 30KB. Not to mention the speed cost, whatever that would turn out to be.
How big is simple open, read, write, SD test code now in CMM mode?
I don't have my system set up to test the simplelibraries tools, and I'm a bit pressed for time right now so I can't work on getting that set up. I did take the simpletools test from here and duplicate it to work with libpropeller. See the attached zip.
Note: I changed "print" to "printf" to make the comparison fair.
I compiled with the following:
As is (with printf) the downloaded size is 18096 bytes.
Hmmm. Now that I read your post over again I see that it's not so much asking for a comparison with simpletools but a question about size of simple functionality. Still, I'm interested in size comparisons.
If I comment out all the printfs the size drops to 8256 bytes. So, that's 8256 bytes to open a file, write to it, then read it back.
We've struggled to find an SD driver that was less than about 8KB. Amazingly, the DOSFS stuff in PropellerGCC is relatively competitive in code size, and it has a very good feature-set. Thanks to Dave Hein for adding DOSFS.
Thanks! That was exactly what I needed. I've added this to my SD driver
Now we can get the filesize (in bytes) and the last modification time. The last modification time is meaningful if the SetDate function is called before the file is created so that FSRW has the current time.
https://github.com/libpropeller/libpropeller/blob/master/libpropeller/sd/sd.h#L534