> Removable media such as sd cards do
> not have a boot sector. I think
> this is what I was looking for with 0xEB

"boot sector" can be a "Master Boot Record" or a "Volume Boot Record". The 
first belongs to the media, the latter to the file system. Partitioned 
harddisks have an MBR, and each file system on it has a VBR. Unpartitioned 
media (possibly common for SD cards, but they can be partitioned, too) just has 
a VBR, which is the first sector of the file system.

The problem is, neither the byte value 0xEB in the first byte nor the values 
0x55, 0xAA in the last two bytes tell us if the sector is a MBR or a VBR. The 
0x55, 0xAA must be in a MBR and also in a VBR. As first byte, in a FAT32 VBR 
there can be 0xEB or 0xE9. As first byte in a MBR can be about any value, but I 
think it might be quite often an 0xEB or an 0xE9. 

So, we have to look close to the data and find out if it is valid for a MBR or 
a VBR. For a FAT32 VBR it is not to hard: The word 48/49 points to the sector 
adress of the "FileSystem Information Sector". This sector starts with four 
bytes that have always the same value. If we just follow the pointer and find 
those four values, we can be sure that it is a FAT32 VBR we found on sector 0. 
If it is no FAT32 VBR, bytes 48/49 point us straight to who-knows-where. The 
values we'll find there will surely be not those we were looking for. So if the 
values aren't there, it was no FAT32 VBR, and we can assume it must be 
partitioned media and therefore an MBR.

And, a partition entry is 16 bytes long, not 32?


procedure fat32_read_boot_sector(byte in partition_select) is
   var dword sec_per_fat
   var byte _sec_per_fat[4] at sec_per_fat
   var word reserved_sectors -- usually 20h (may only need var 
reserved_sectors_1)
   var byte _reserved_sectors[2] at reserved_sectors
   var dword partition_lba_begin = 0

--                          Here I changed 32 to 16
   var word part_addr = ((partition_select - 1)* 16)

   fat32_raw_read_sector2(0)
   -- check if there is a master boot record, removable media does not always 
have an MBR.

   -- read the FileSystem Information Sector
fat32_raw_read_sector2((word(fat32_sector_buffer[49])*256)+fat32_sector_buffer[48])

   -- check for the signature of a FileSystem Information Sector
   if (  
     (fat32_sector_buffer[0] == 0x52) &
     (fat32_sector_buffer[1] == 0x52) &
     (fat32_sector_buffer[2] == 0x61) &
     (fat32_sector_buffer[3] == 0x41)
      )
   then -- Medium is identified as unpartitioned FAT32 filesystem
     fat32_raw_read_sector2(0)
     fat32_init_ok = TRUE
   else -- Medium is partitioned or contains no FAT32 filesystem
     fat32_raw_read_sector2(0)
      -- check if the partition is fat32
      var byte type_code -- partition type code

     [...]

Greets,
Kiste


-- 
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en.

Reply via email to