(This project would probably on-topic on the SuperUser or Electronics sites, but the focus of this question is programmable software for accomplishing it.)
I have an embedded system which produces data at about 100KB/s which needs to be stored and later processed on a Windows PC. Serial streaming works, but internal storage has the obvious advantage of not requiring a laptop and cabling present in the room where data collection occurs.
My circuit board has an SD card socket (SPI connected), and I had previously tried writing files into a FAT filesystem. But this turned out to be a horrible bottleneck, not least of the reasons for which is that, in order to support multiple files of arbitrary length growing at arbitrary times, file access in FAT requires reading and writing multiple layers of metadata -- the allocation table itself and directories -- in addition to the actual content, and these cannot fit entirely in microcontroller RAM, so the number of card accesses is magnified. Worse, some tasks such as finding a new free block have linear complexity in the card size.
Another strike against FAT is that it's quite prone to data corruption in case of power loss without prior clean unmount, and my system doesn't have any user interface which could initiate an unmount. I'm aware of techniques including power-failing interrupts and capacitance to keep the processor and SD card going for a few extra milliseconds, but since those don't help with hot removal anyway and my existing circuit doesn't have them, I'm trying to achieve a crash-only design for storage.
So I've decided to skip the filesystem and just use the card as a raw sequence of blocks. However, I don't want my users being invited to reformat cards containing data
So, I want to partition the cards and place a small FAT partition on the front which OSes will recognize, with an explanatory test file. Users need to be able to replace cards, so I need to automate the partitioning and formatting process within my PC application.
Raw access can be achieved by calling CreateFile("\\\\.\\PhysicalDisk3")
and similar paths, and this can be done on removable disks without requiring admin rights. Still, this is code I'd rather not have to write myself. And the OS would still have to be told to rescan volumes after the change.
Are there APIs either built into Windows or part of the third-party open source framework for partitioning SD cards without requiring direct bitwise access to partition tables? If not, what should I do to have Windows rescan volumes after I change partitioning? I much prefer methods that work on XP and newer.