Commit 9d956e0fefa39ba49250f61e3c7aa3dadafdb7fd

Authored by Egbert Eich
Committed by Tom Rini
1 parent 8bfa195e4e

disk/part_dos: check harder for partition table

Devices that used to have a whole disk FAT filesystem but got then
partitioned will most likely still have a FAT or FAT32 signature
in the first sector as this sector does not get overwritten by
a partitioning tool (otherwise the tool would risk to kill the mbr).

The current partition search algorithm will erronously detects such
a device as a raw FAT device.

Instead of looking for the FAT or FAT32 signatures immediately we
use the same algorithm as used by the Linux kernel and first check
for a valid boot indicator flag on each of the 4 partitions.
If the value of this flag is invalid for the first entry we then
do the raw partition check.
If the flag for any higher partition is wrong we assume the device
is neiter a MBR nor PBR device.

Signed-off-by: Egbert Eich <eich@suse.com>

Showing 1 changed file with 16 additions and 3 deletions Side-by-side Diff

... ... @@ -74,13 +74,26 @@
74 74  
75 75 static int test_block_type(unsigned char *buffer)
76 76 {
  77 + int slot;
  78 + struct dos_partition *p;
  79 +
77 80 if((buffer[DOS_PART_MAGIC_OFFSET + 0] != 0x55) ||
78 81 (buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) ) {
79 82 return (-1);
80 83 } /* no DOS Signature at all */
81   - if (strncmp((char *)&buffer[DOS_PBR_FSTYPE_OFFSET],"FAT",3)==0 ||
82   - strncmp((char *)&buffer[DOS_PBR32_FSTYPE_OFFSET],"FAT32",5)==0) {
83   - return DOS_PBR; /* is PBR */
  84 + p = (struct dos_partition *)&buffer[DOS_PART_TBL_OFFSET];
  85 + for (slot = 0; slot < 3; slot++) {
  86 + if (p->boot_ind != 0 && p->boot_ind != 0x80) {
  87 + if (!slot &&
  88 + (strncmp((char *)&buffer[DOS_PBR_FSTYPE_OFFSET],
  89 + "FAT", 3) == 0 ||
  90 + strncmp((char *)&buffer[DOS_PBR32_FSTYPE_OFFSET],
  91 + "FAT32", 5) == 0)) {
  92 + return DOS_PBR; /* is PBR */
  93 + } else {
  94 + return -1;
  95 + }
  96 + }
84 97 }
85 98 return DOS_MBR; /* Is MBR */
86 99 }