0

I'm trying to implement a read only FAT16/32 Filesystem library for embedded systems, to read SD Cards (reinventing the wheel for educational purpose).

It seems like there are cards which are formatted without an MBR; just the FAT without any partition table.

I have read FAT docs and MBR docs and learnt how to read an SD Card which both has MBR and FAT.

I need my C++ library to support reading SD Cards without an MBR.

My current approach is the following:

  1. Try reading the first sector assuming it contains FAT BPB (Boot Parameter Block).
  2. Check whether the information is valid.
  3. If yes, continue reading root directory.
  4. Otherwise assume it has an MBR.
  5. Read the partition table starting at 0x1BE.
  6. If a supported partition type is available, try reading its first sector as FAT.
  7. If the read information is valid, continue reading root directory.
  8. Otherwise return an ERROR_CODE

Is there a better approach? For example, is there any magic number or a specific pattern that can be identified?

itsfarseen
  • 1,109
  • 10
  • 25
  • you just read and see if it is there? – old_timer Jun 24 '16 at 01:03
  • is there any magic number or specific pattern to identify? – itsfarseen Jun 24 '16 at 01:05
  • or is there a way to distinguish between the first sector of FAT and the MBR? – itsfarseen Jun 24 '16 at 01:05
  • I thought that was by location, the wikipedia page for master boot record doesnt help here? – old_timer Jun 24 '16 at 01:11
  • I looked through a lot of introductory docs. But I just couldn't find a key difference. – itsfarseen Jun 24 '16 at 01:14
  • of course you cant assume EVERY card will have X any more than every hard drive will have X. some may be wiped clean or partitioned differently or used without a file system. All it takes is one on the planet not being that way and the answer to your question is no, you cannot count on that fact. – old_timer Jun 24 '16 at 01:15
  • So just try to read the first sector. Check if it is a valid FAT boot sector. If not, then try to read the partition table and loop through each partition trying to find a valid FAT boot sector. That's it? – itsfarseen Jun 24 '16 at 01:19
  • Just because a FAT FS floppy is not bootable does not mean that it has no MBR - merely that the MBR does not load a boot sector. – Clifford Jun 24 '16 at 09:44
  • @Clifford, yes. I meant there existed floppies which did not have an MBR. – itsfarseen Jun 24 '16 at 09:48
  • @happycoder : Really? Were they FAT? What I am doubting is that such things existed. – Clifford Jun 24 '16 at 10:02
  • 1
    This maybe relevant: http://www.avrfreaks.net/forum/sd-card-missing-mbr – Clifford Jun 24 '16 at 18:31

1 Answers1

0
  1. Check for the text FAT32 at offset 0x52.
  2. If that fails, check for FAT12 or FAT16 at 0x36
  3. If that fails too, assume the first sector is MBR.

Thanks to @Clifford

itsfarseen
  • 1,109
  • 10
  • 25