possible bug in sbin/fsck_msdosfs/boot.c

Alexander Best alexbestms at math.uni-muenster.de
Thu Jul 23 10:29:31 UTC 2009


i just tried to do fsck_msdosfs on my mobile phone's memory card using a usb
connection cable. this is what `file -s` has to say about /dev/da0:

/dev/da0: x86 boot sector, code offset 0x0, OEM-ID "        ", sectors/cluster
64, reserved sectors 6304, Media descriptor 0xf8, heads 128, hidden sectors
8192, sectors 7736320 (volumes > 32 MB) , FAT (32 bit), sectors/FAT 944,
reserved3 0x800000, serial number 0x34613466, label: "mem        "

however after issuing the command `fsck_msdosfs /dev/da0` i got the following
error:

fsck_msdosfs /dev/da0
** /dev/da0
backup doesn't compare to primary bootblock

i did a bit of research and it seems this bug was supposed to be fixed by
r128463. the problem was that the entire bootblock was compared to the
backupblock. but since only the first 52 bytes of the bootblock are important
many device use the rest of the bootblock for some other purpose. the
following change was made to sbin/fsck_msdosfs/boot.c:

-- if (memcmp(block, backup, DOSBOOTBLOCKSIZE)) {
++ if (memcmp(block + 11, backup + 11, 79)) {

it seems however that the last memcmp argument is still too high. could
somebody with good fat12/16/32 knowledge please look into this?

i attached the original openbsd problem report which described the problem in
detail in 2006 (actually the problem was first discovered in 2001 but nobody
seemed to care about it back then).

cheers.
alex

oh...and i'm running r195774 (8.0-BETA2).
-------------- next part --------------
>Submitter-Id: kousu
>Originator: Nick Guenther
>Organization:
>Synopsis: fsck_msdos detects a bad partition when it's actually okay
>Severity: non-critical
>Priority: medium
>Catergory: system
>Class: sw-bug
>Release: 3.8-Release
>Environment:
	System	: OpenBSD 3.8
	Architecture	: OpenBSD.i386
	Machine:	: i386
>Description:
	Runng fsck_msdos on FAT32 partitions that have been corrupted in a
certain way causes "backup doesn't compare to primary bootblock" even
when the corresponding microsoft tools say the disk is clean. This is
because it compares too much of the primary and backup bootblocks on a
FAT32 partition. It should only compare the first 52 bytes but it
compares the entirety of the DOS boot block.
>How-To-Repeat:
	Format a new FAT32 partition (ideally using microsoft tools). If you
run fsck_msdos on this it is fine because the primary and backup
bootblocks were both initialized the same way (presumable to nulls).
However, if you corrupt one of them (pulling the power while it's
running will do this) and then try fsck_msdos you see "backup doesn't
compare to primary bootblock"; this occurs even if you run scandisk
(from windows) on the partition before trying fsck_msdos because
scandisk will only fix the first 52 bytes and ignores the rest of the
boot block.
>Fix:
	The fix for this was actually provided years ago, but appearantly was
forgotten, so I'm reminding you. See
http://www.monkey.org/openbsd/archive/bugs/0105/msg00085.html for the
fix. Basically, just go into /usr/src/sbin/fsck_msdos/boot.c and
change
if(memcmp(block, backup, DOSBOOTBLOCKSIZE ))
to
if(memcmp(block, backup, 52))
There's something else in that message too that I don't understand but
is probably worth looking at.



More information about the freebsd-current mailing list