Recent

Author Topic: SD card low level read  (Read 1772 times)

dseligo

  • Sr. Member
  • ****
  • Posts: 375
SD card low level read
« on: August 25, 2021, 12:47:03 pm »
How could SD card be read if there isn't drive letter assigned to it and it doesn't show in Disk Management?

I can read cards that show in Disk Management with this:
Code: Pascal  [Select][+][-]
  1. hBlockDevice := CreateFile(PChar(sFileName), GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
  2. // where sFileName is something like \\.\PHYSICALDRIVE1
  3.   if hBlockDevice <> INVALID_HANDLE_VALUE then
  4.   begin
  5.     SetFilePointer(hBlockDevice, BlockSize * dwSector, nil, FILE_BEGIN);
  6.     ReadFile(hBlockDevice, Buffer[0], BlockSize, dwRead, nil);
  7.     ...

But if card doesn't show in Disk Management I get INVALID_HANDLE_VALUE.

MarkMLl

  • Hero Member
  • *****
  • Posts: 3501
Re: SD card low level read
« Reply #1 on: August 25, 2021, 08:56:49 pm »
In the general case, forget it. BTDT, and the only way you can get low-level access to a possibly-damaged card is by using something like an Arduino.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 2799
Re: SD card low level read
« Reply #2 on: August 25, 2021, 09:08:48 pm »
Hi!

There is a marvelous tool  simply called testdisk

https://www.cgsecurity.org/wiki/TestDisk_Download


Available for a lot of OS but I would advise Linux, because Windows gives up quick.

As long a Linux detects a device there is a good chance to recover your data.

Before you plug the card do a

ls /dev/sd*

Plug the card and do the same. If something changed then the new device is your card. Then there is  good chance to get the data back.

I recovered a lot of broken hard-disks with testdisk. For example:

*External 350 GB full of music but with a zerod  directory
*Laptop-Disk, which had a big scratch from a crash: 85% of the photos saved. The other 15% were on the cratch

Hope you are lucky!
 
Winni

dseligo

  • Sr. Member
  • ****
  • Posts: 375
Re: SD card low level read
« Reply #3 on: August 26, 2021, 12:15:38 am »
Cards are not damaged. They are used in microcontroller operated devices and probably has some custom memory organization.
I hoped I could read them from Windows when some of this devices stop working.

I will try with Linux and if that doesn't work I'll try it with Arduino.

dseligo

  • Sr. Member
  • ****
  • Posts: 375
Re: SD card low level read
« Reply #4 on: August 26, 2021, 12:22:01 am »
There is a marvelous tool  simply called testdisk

https://www.cgsecurity.org/wiki/TestDisk_Download

Maybe it won't help me now with this SD cards, but thank you for tip on this tool. I just hope I won't need it anytime soon. :)

MarkMLl

  • Hero Member
  • *****
  • Posts: 3501
Re: SD card low level read
« Reply #5 on: August 26, 2021, 08:12:09 am »
Cards are not damaged. They are used in microcontroller operated devices and probably has some custom memory organization.
I hoped I could read them from Windows when some of this devices stop working.

I will try with Linux and if that doesn't work I'll try it with Arduino.

My experience is that when they go wrong, they go wrong badly. Getting the "physical damage" side out of the way first, the narrowest line across the card runs straight through the die so if they crack- and I've done this twice due to a badly-designed Raspberry Pi case- they're beyond even a dissolve-card-and-rebond solution.

Electrically, they're known to be very susceptible to poor voltage control and power interruption at critical times. IIRC, the low-level metadata blocks are R/O so won't be damaged by this sort of thing, but it's still very easy to get to a situation where the card doesn't respond normally and you have to go in using SPI: hence Arduino although in principle at least any SPI controller e.g. a Raspberry Pi would work.

Logically, since they don't have load balancing they're extremely susceptible to having their FAT-style directory screwed by repeated write operations. Now at least some cards are specially designed on the assumption that they'll be partitioned in a way that puts the FATs in a specially-designed resistant area, but there's always a risk that any derangement to this will get the card into a state that a standard reader will reject it: and there's neither BIOS support nor something that looks like a (S)ATA controller to get in at a lower level. And of course most readers are "smart" with either a USB interface or a controller chip with a special Windows driver... and I've had no success at all getting the latter to work on Linux.

Oh, and if in doubt always check with a different (newer) reader: there's an arms race as capacities are pushed up by consumer equipment with PCs rather struggling to keep up.

HTH, MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018