Brynet-Inc wrote:
The physical lock switch on SD cards is essentially the same as the lock switch on floppy disks, it requires support from the device it's inserted into and can be ignored.
http://www.seanet.com/~karllunt/sdlocker.htmlhttp://hackaday.com/2014/01/18/the-tini ... rd-locker/SD cards have a pretty extensive feature-set (MMC), one interesting feature is the ability to lock writes temporarily until unlocked or even lock permanently. There's a 32-bit ARM microcontroller inside even microSD cards, and it's running a complex firmware that handles communication with the host.
Unfortunately with a USB card reader you can't do any of that, you need a real SD controller.. some laptops do have PCI host controllers though.
http://www.bunniestudios.com/blog/?p=3554Thanks for the links and other info. (I look forward to communicating directly with cards some day and risking write protecting them permanently - I didn't know that hazard was available.)
So, it's a control register that's responsible for changing it to write protected and it's something the BIOS has started doing by mistake. It's a puzzle though as to why it's started doing it now after so long, starting just a couple of weeks ago with one card, and then yesterday with the second card. It's just possible that I'm doing something different, but if so it's not through any modifications to my code (because it's happened at a time when I haven't been changing it; all I'm doing is using my OS to load in text files from my own partition, to edit them, and then to write them back to my own partition, though not always on the same drive), but must be something I'm doing as a user of my OS. I'll have to try a few experiments to see if multiple reads are necessary before a write in order to prevent it from ending up write-protected after the first set of writes.
embryo wrote:
DavidCooper wrote:
I can get the SD cards back to normal again just by putting them in a Pentax camera and taking a photo
May be it's the file system that was changed and allows BIOS code to work with the card? In my practice incomplete partition table was a real cause of a problem like described above. It can be any data structure on the media that can be changed properly by the Pentax and not properly by your code.
It is possible to get raw bytes right from the media start and up to a few megabytes, after your system makes the card inoperable. Next, after the Pentax makes the card working, it is possible to get the raw bytes againt and to compare them with previous version.
I was hoping it would be something of that kind that's easy to access, but I'm not writing to the FAT partition at all, or even reading it, so the only changes made there are the ones made by the camera. The camera must be changing a bit in a control register to enable itself to write to the card again, and the BIOS must be modifying it too for some reason, but in the wrong direction. I have to try to find a way to stop it doing that. I know that it used to write to the cards without setting it, so hopefully I can find a way to get it back to doing that.
Anyway, it's a problem that's unlikely to affect many people as it's so unusual to use the BIOS to write to SD cards. If I find an easy way to fix it, I'll post about it here just on the off chance that it helps someone else. The idea fix though is to write USB drivers and escape from the BIOS. Some day...