Hi,

time to merge another fix from NetBSD (and FreeBSD who applied it too):

If sector size is not 512, the boot signature is placed at a wrong
position.  It always has to be at offset 510/511, not sector size - 2.

# dd if=/dev/zero of=fat.iso bs=1M count=1
# vnconfig vnd0c fat.iso
# newfs_msdos -S 4096 vnd0c
/dev/rvnd0c: 2041 sectors in 2041 FAT12 clusters (4096 bytes/cluster)
bps=4096 spc=1 res=1 nft=2 rde=512 sec=2048 mid=0xf0 spf=1 spt=63 hds=1 hid=0
# fsck_msdos vnd0c
** /dev/rvnd0c (vnd0c)
Invalid signature in boot block: 0000

Also, the minimum allowed sector size is 512.


NetBSD (Revision 1.24):
Don't use negative offsets from "bpb.bps" when writing out values such
as DOSMAGIC in the MBR. In non-512 byte media, the MBR is still 512
bytes in length.

Based on the patches provided in PR kern/17398 by Trevin Beattie.

FreeBSD (Revision 170166):
The newfs_msdos utility does not store the boot signature in the
correct place on large sector disks.  The boot signature should be at
offset 0x1fe in the BPB; newfs_msdos currently stores it 2 bytes from
the end of the sector.

Taken from:     NetBSD


Tobias

Index: newfs_msdos.8
===================================================================
RCS file: /cvs/src/sbin/newfs_msdos/newfs_msdos.8,v
retrieving revision 1.24
diff -u -p -r1.24 newfs_msdos.8
--- newfs_msdos.8       16 Jul 2013 09:45:28 -0000      1.24
+++ newfs_msdos.8       24 Jun 2014 19:20:35 -0000
@@ -134,7 +134,7 @@ Number of hidden sectors.
 Number of reserved sectors.
 .It Fl S Ar sector-size
 Number of bytes per sector.
-Acceptable values are powers of 2 in the range 128 through 32768.
+Acceptable values are powers of 2 in the range 512 through 32768.
 .It Fl s Ar total
 File system size.
 .It Fl u Ar track-size
Index: newfs_msdos.c
===================================================================
RCS file: /cvs/src/sbin/newfs_msdos/newfs_msdos.c,v
retrieving revision 1.22
diff -u -p -r1.22 newfs_msdos.c
--- newfs_msdos.c       22 Nov 2013 04:14:01 -0000      1.22
+++ newfs_msdos.c       24 Jun 2014 19:20:35 -0000
@@ -50,7 +50,7 @@
 #define NPB      2             /* nibbles per byte */
 
 #define DOSMAGIC  0xaa55       /* DOS magic number */
-#define MINBPS   128           /* minimum bytes per sector */
+#define MINBPS   512           /* minimum bytes per sector */
 #define MAXSPC   128           /* maximum sectors per cluster */
 #define MAXNFT   16            /* maximum number of FATs */
 #define DEFBLK   4096          /* default block size */
@@ -617,17 +617,17 @@ main(int argc, char *argv[])
                    setstr(bs->oem, opt_O ? opt_O : "BSD  4.4",
                           sizeof(bs->oem));
                    memcpy(img + x1, bootcode, sizeof(bootcode));
-                   mk2(img + bpb.bps - 2, DOSMAGIC);
+                   mk2(img + MINBPS - 2, DOSMAGIC);
                }
            } else if (fat == 32 && bpb.infs != MAXU16 &&
                       (lsn == bpb.infs ||
                        (bpb.bkbs != MAXU16 &&
                         lsn == bpb.bkbs + bpb.infs))) {
                mk4(img, 0x41615252);
-               mk4(img + bpb.bps - 28, 0x61417272);
-               mk4(img + bpb.bps - 24, 0xffffffff);
-               mk4(img + bpb.bps - 20, bpb.rdcl);
-               mk2(img + bpb.bps - 2, DOSMAGIC);
+               mk4(img + MINBPS - 28, 0x61417272);
+               mk4(img + MINBPS - 24, 0xffffffff);
+               mk4(img + MINBPS - 20, bpb.rdcl);
+               mk2(img + MINBPS - 2, DOSMAGIC);
            } else if (lsn >= bpb.res && lsn < dir &&
                       !((lsn - bpb.res) %
                         (bpb.spf ? bpb.spf : bpb.bspf))) {

Reply via email to