bin/153426: [patch] fsck_msdosfs only works with sector size 512
Keith White
kwhite at site.uottawa.ca
Fri Dec 24 13:10:13 UTC 2010
>Number: 153426
>Category: bin
>Synopsis: [patch] fsck_msdosfs only works with sector size 512
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: update
>Submitter-Id: current-users
>Arrival-Date: Fri Dec 24 13:10:11 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator: Keith White
>Release: FreeBSD 9.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD demo 9.0-CURRENT FreeBSD 9.0-CURRENT #49: Mon Nov 22 07:00:30 EST 2010 kwhite at demo:/usr/src/obj/usr/src/sys/U100 i386
>Description:
It is possible to create and use an msdos filesystem with 2048-byte
sectors; but it is not possible to "fsck" it. "fsck_msdosfs" on
such a fileystem returns:
"could not read boot block (Invalid argument)"
>How-To-Repeat:
dd if=/dev/zero bs=1m of=msdos.img count=20
MD=`mdconfig -af msdos.img`
gnop create -S 2048 -v $MD
newfs_msdos -n1 $MD.nop
fsck_msdosfs /dev/$MD.nop
** /dev/md4.nop
could not read boot block (Invalid argument)
...
mount -t msdosfs /dev/$MD.nop /mnt
>Fix:
The following POC patch uses DIOCGSECTORSIZE instead of a fixed value of DOSBOOTBLOCKSIZE.
=============
--- src/sbin/fsck_msdosfs/boot.c.orig 2010-07-03 06:49:57.000000000 -0400
+++ src/sbin/fsck_msdosfs/boot.c 2010-12-24 05:49:09.000000000 -0500
@@ -35,6 +35,7 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
+#include <sys/disk.h>
#include "ext.h"
#include "fsutil.h"
@@ -47,11 +48,23 @@
u_char backup[DOSBOOTBLOCKSIZE];
int ret = FSOK;
int i;
+ u_char *tblock;
+ unsigned int sectorsize;
- if (read(dosfs, block, sizeof block) != sizeof block) {
+ if ((ioctl(dosfs, DIOCGSECTORSIZE, §orsize) == -1) || sectorsize < sizeof block) {
+ printf("** could not get valid device sectorsize, assuming %d\n", sizeof block);
+ sectorsize = sizeof block;
+ }
+ tblock = (u_char *)malloc(sectorsize);
+ if (read(dosfs, tblock, sectorsize) != sectorsize) {
perror("could not read boot block");
return FSFATAL;
}
+ memcpy(block, tblock, sizeof block);
+ free(tblock);
+ if (sectorsize != sizeof block) {
+ printf("** non-standard sectorsize of %d\n", sectorsize);
+ }
if (block[510] != 0x55 || block[511] != 0xaa) {
pfatal("Invalid signature in boot block: %02x%02x",
=============
>Release-Note:
>Audit-Trail:
>Unformatted:
To: FreeBSD-gnats-submit at freebsd.org
Subject: [patch] fsck_msdosfs only works with sector size 512
From: Keith White <kwhite at uottawa.ca>
Reply-To: Keith White <kwhite at uottawa.ca>
Cc: kwhite at uottawa.ca
X-send-pr-version: 3.113
X-GNATS-Notify:
More information about the freebsd-bugs
mailing list