rust-embedded-community / embedded-sdmmc-rs

A SD/MMC library with FAT16/FAT32 support, suitable for Embedded Rust systems
Apache License 2.0
309 stars 73 forks source link

Release/v0.6.0 #104

Closed thejpster closed 11 months ago

thejpster commented 11 months ago

Changed

Added

Removed

Murmele commented 4 months ago
  • Writing to a file no longer flushes file metadata to the Directory Entry. Instead closing a file now flushes file metadata to the Directory Entry.

But this means I have always to close the file. Currently I store a RawFile object (as filehandler) and execute only the write. In this case the file gets created but stays always empty (Currently I don't close the file for testing, but in real scenario this can also happen, so the data is lost?)

Usecase:

The problem is when I have to close it, the RawFile "handler" is invalid in my understanding. Is that correct?

Reason why I don't like to close:

thejpster commented 4 months ago

If closing/re-opening is a performance bottleneck, you could propose a PR containing a flush API, which just looks at the dirty flag and if required, writes to disk and then clears it.

Murmele commented 4 months ago

I thought about the same. I will have a look into it tomorrow and will create a pullrequest. Thanks for the project!

Murmele commented 4 months ago

@thejpster

Since DOS 7.1 the two most-significant bits of this cluster entry may hold two optional bitflags representing the current volume status on FAT16 and FAT32, but not on FAT12 volumes. These bitflags are not supported by all operating systems, but operating systems supporting this feature would set these bits on shutdown and clear the most significant bit on startup: If bit 15 (on FAT16) or bit 27 (on FAT32)[41] is not set when mounting the volume, the volume was not properly unmounted before shutdown or ejection and thus is in an unknown and possibly "dirty" state.[27] On FAT32 volumes, the FS Information Sector may hold outdated data and thus should not be used. The operating system would then typically run SCANDISK or CHKDSK on the next startup[nb 9][41] (but not on insertion of removable media) to ensure and possibly reestablish the volume's integrity. Source: https://en.wikipedia.org/wiki/Design_of_the_FAT_file_system

Could this help? So the computer gets the indication that the filesystem was not properly closed and it should rescan?

thejpster commented 4 months ago

There is always a trade off between performance and reliability with FAT.

I like the idea of being able to mark disks as dirty if they have open writable files, and non-dirty when the last writable file has been closed. I just wouldn't want to see read-only access (99% of my use case) mark the FS as dirty.

Murmele commented 4 months ago

There is always a trade off between performance and reliability with FAT.

I like the idea of being able to mark disks as dirty if they have open writable files, and non-dirty when the last writable file has been closed. I just wouldn't want to see read-only access (99% of my use case) mark the FS as dirty.

Haha then we have opposite usecases 😄 i have most of the time writing. Neverthless, I will check this flag out. I don't think during read the dirty flag will be set