diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2007-02-18 13:49:23 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2007-02-18 13:49:23 +0000 |
commit | f81626bc7723b5e5969a08ef9557de09183ca9a3 (patch) | |
tree | 5a82d80c3336b33b249a19d6fb4510aaa1a23f5f /sys/arch | |
parent | 60d6d9e3f658e9a697073fa8ec8c1b23cadb66e0 (diff) |
If no MBR partitions are found when spoofing a disklabel, try looking
for a bare FAT12/16/32 filesystem. If one is found, spoof it as 'i'.
This enables iPod shuffles and other umass devices that are shipped
with a bare FAT32 filesystem to be used as install media. And
generally makes things easier for the user just trying to mount some
media, e.g. floppies.
Does not make it safe to write a disklabel or MBR on such a device!
That will still obliterate the FAT filesystem.
Help and suggestions from tom@ and deraadt@. Feedback and suggestions
for future enhancements from espie@ mickey@ and peter@.
ok tom@ deraadt@
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/alpha/alpha/disksubr.c | 32 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/disksubr.c | 32 | ||||
-rw-r--r-- | sys/arch/arm/arm/disksubr.c | 30 | ||||
-rw-r--r-- | sys/arch/aviion/aviion/disksubr.c | 30 | ||||
-rw-r--r-- | sys/arch/hppa/hppa/disksubr.c | 32 | ||||
-rw-r--r-- | sys/arch/hppa64/hppa64/disksubr.c | 32 | ||||
-rw-r--r-- | sys/arch/i386/i386/disksubr.c | 30 | ||||
-rw-r--r-- | sys/arch/landisk/landisk/disksubr.c | 30 | ||||
-rw-r--r-- | sys/arch/macppc/macppc/disksubr.c | 30 | ||||
-rw-r--r-- | sys/arch/mips64/mips64/disksubr.c | 32 | ||||
-rw-r--r-- | sys/arch/mvmeppc/mvmeppc/disksubr.c | 30 |
11 files changed, 324 insertions, 16 deletions
diff --git a/sys/arch/alpha/alpha/disksubr.c b/sys/arch/alpha/alpha/disksubr.c index 5c46a1ed150..1dc11fc99ab 100644 --- a/sys/arch/alpha/alpha/disksubr.c +++ b/sys/arch/alpha/alpha/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.65 2007/02/03 18:22:33 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.66 2007/02/18 13:49:22 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -221,6 +221,7 @@ readdoslabel(bp, strat, lp, osdep, partoffp, cylp, spoofonly) struct dos_partition dp[NDOSPART], *dp2; struct partition *pp; unsigned long extoff = 0; + unsigned int fattest; daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL; int dospartoff, cyl, i, ourpart = -1; @@ -356,7 +357,34 @@ donot: } lp->d_bbsize = 8192; lp->d_sbsize = 64*1024; /* XXX ? */ - lp->d_npartitions = n > 0 ? n + 8 : 3; + lp->d_npartitions = MAXPARTITIONS; + + if (n == 0 && part_blkno == DOSBBSECTOR) { + /* Check for a short jump instruction. */ + fattest = ((bp->b_data[0] << 8) & 0xff00) | (bp->b_data[2] & + 0xff); + if (fattest != 0xeb90 && fattest != 0xe900) + goto notfat; + + /* Check for a valid bytes per sector value. */ + fattest = ((bp->b_data[12] << 8) & 0xff00) | (bp->b_data[11] & + 0xff); + if (fattest < 512 || fattest > 4096 || (fattest % 512 != 0)) + goto notfat; + + /* Check the end of sector marker. */ + fattest = ((bp->b_data[510] << 8) & 0xff00) | (bp->b_data[511] & + 0xff); + if (fattest != 0x55aa) + goto notfat; + + /* Looks like a FAT filesystem. Spoof 'i'. */ + lp->d_partitions['i' - 'a'].p_size = + lp->d_partitions[RAW_PART].p_size; + lp->d_partitions['i' - 'a'].p_offset = 0; + lp->d_partitions['i' - 'a'].p_fstype = FS_MSDOS; + } +notfat: /* record the OpenBSD partition's placement for the caller */ if (partoffp) diff --git a/sys/arch/amd64/amd64/disksubr.c b/sys/arch/amd64/amd64/disksubr.c index af07238bff7..a27cc4d60ac 100644 --- a/sys/arch/amd64/amd64/disksubr.c +++ b/sys/arch/amd64/amd64/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.29 2007/02/03 18:22:33 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.30 2007/02/18 13:49:22 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -67,6 +67,7 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp, struct disklabel *dlp; struct partition *pp; unsigned long extoff = 0; + unsigned int fattest; struct buf *bp = NULL; daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL; @@ -212,7 +213,34 @@ donot: lp->d_sbsize = 64*1024; /* XXX ? */ lp->d_npartitions = MAXPARTITIONS; - /* don't read the on-disk label if we are in spoofed-only mode */ + if (n == 0 && part_blkno == DOSBBSECTOR) { + /* Check for a short jump instruction. */ + fattest = ((bp->b_data[0] << 8) & 0xff00) | (bp->b_data[2] & + 0xff); + if (fattest != 0xeb90 && fattest != 0xe900) + goto notfat; + + /* Check for a valid bytes per sector value. */ + fattest = ((bp->b_data[12] << 8) & 0xff00) | (bp->b_data[11] & + 0xff); + if (fattest < 512 || fattest > 4096 || (fattest % 512 != 0)) + goto notfat; + + /* Check the end of sector marker. */ + fattest = ((bp->b_data[510] << 8) & 0xff00) | (bp->b_data[511] & + 0xff); + if (fattest != 0x55aa) + goto notfat; + + /* Looks like a FAT filesystem. Spoof 'i'. */ + lp->d_partitions['i' - 'a'].p_size = + lp->d_partitions[RAW_PART].p_size; + lp->d_partitions['i' - 'a'].p_offset = 0; + lp->d_partitions['i' - 'a'].p_fstype = FS_MSDOS; + } +notfat: + + /* Don't read the on-disk label if we are in spoofed-only mode. */ if (spoofonly) goto done; diff --git a/sys/arch/arm/arm/disksubr.c b/sys/arch/arm/arm/disksubr.c index c4d6176677f..203528f064c 100644 --- a/sys/arch/arm/arm/disksubr.c +++ b/sys/arch/arm/arm/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.25 2007/02/03 18:22:33 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.26 2007/02/18 13:49:22 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -71,6 +71,7 @@ readdisklabel(dev, strat, lp, osdep, spoofonly) struct partition *pp; struct disklabel *dlp; unsigned long extoff = 0; + unsigned int fattest; struct buf *bp = NULL; daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL; @@ -215,6 +216,33 @@ donot: lp->d_sbsize = 64*1024; /* XXX ? */ lp->d_npartitions = MAXPARTITIONS; + if (n == 0 && part_blkno == DOSBBSECTOR) { + /* Check for a short jump instruction. */ + fattest = ((bp->b_data[0] << 8) & 0xff00) | (bp->b_data[2] & + 0xff); + if (fattest != 0xeb90 && fattest != 0xe900) + goto notfat; + + /* Check for a valid bytes per sector value. */ + fattest = ((bp->b_data[12] << 8) & 0xff00) | (bp->b_data[11] & + 0xff); + if (fattest < 512 || fattest > 4096 || (fattest % 512 != 0)) + goto notfat; + + /* Check the end of sector marker. */ + fattest = ((bp->b_data[510] << 8) & 0xff00) | (bp->b_data[511] & + 0xff); + if (fattest != 0x55aa) + goto notfat; + + /* Looks like a FAT filesystem. Spoof 'i'. */ + lp->d_partitions['i' - 'a'].p_size = + lp->d_partitions[RAW_PART].p_size; + lp->d_partitions['i' - 'a'].p_offset = 0; + lp->d_partitions['i' - 'a'].p_fstype = FS_MSDOS; + } +notfat: + /* don't read the on-disk label if we are in spoofed-only mode */ if (spoofonly) goto done; diff --git a/sys/arch/aviion/aviion/disksubr.c b/sys/arch/aviion/aviion/disksubr.c index 3a439fbae1b..d2359312979 100644 --- a/sys/arch/aviion/aviion/disksubr.c +++ b/sys/arch/aviion/aviion/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.16 2007/02/03 18:22:33 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.17 2007/02/18 13:49:22 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -71,6 +71,7 @@ readdisklabel(dev, strat, lp, osdep, spoofonly) struct partition *pp; struct disklabel *dlp; unsigned long extoff = 0; + unsigned int fattest; struct buf *bp = NULL; daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL; @@ -215,6 +216,33 @@ donot: lp->d_sbsize = 64*1024; /* XXX ? */ lp->d_npartitions = MAXPARTITIONS; + if (n == 0 && part_blkno == DOSBBSECTOR) { + /* Check for a short jump instruction. */ + fattest = ((bp->b_data[0] << 8) & 0xff00) | (bp->b_data[2] & + 0xff); + if (fattest != 0xeb90 && fattest != 0xe900) + goto notfat; + + /* Check for a valid bytes per sector value. */ + fattest = ((bp->b_data[12] << 8) & 0xff00) | (bp->b_data[11] & + 0xff); + if (fattest < 512 || fattest > 4096 || (fattest % 512 != 0)) + goto notfat; + + /* Check the end of sector marker. */ + fattest = ((bp->b_data[510] << 8) & 0xff00) | (bp->b_data[511] & + 0xff); + if (fattest != 0x55aa) + goto notfat; + + /* Looks like a FAT filesystem. Spoof 'i'. */ + lp->d_partitions['i' - 'a'].p_size = + lp->d_partitions[RAW_PART].p_size; + lp->d_partitions['i' - 'a'].p_offset = 0; + lp->d_partitions['i' - 'a'].p_fstype = FS_MSDOS; + } +notfat: + /* don't read the on-disk label if we are in spoofed-only mode */ if (spoofonly) goto done; diff --git a/sys/arch/hppa/hppa/disksubr.c b/sys/arch/hppa/hppa/disksubr.c index e49725c7afd..7ff7b78069e 100644 --- a/sys/arch/hppa/hppa/disksubr.c +++ b/sys/arch/hppa/hppa/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.45 2007/02/03 18:22:33 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.46 2007/02/18 13:49:22 krw Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -224,6 +224,7 @@ readdoslabel(bp, strat, lp, osdep, partoffp, cylp, spoofonly) struct dos_partition dp[NDOSPART], *dp2; struct partition *pp; unsigned long extoff = 0; + unsigned int fattest; daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL; int dospartoff, cyl, i, ourpart = -1; @@ -359,7 +360,34 @@ donot: } lp->d_bbsize = 8192; lp->d_sbsize = 64*1024; /* XXX ? */ - lp->d_npartitions = n > 0 ? n + 8 : 3; + lp->d_npartitions = MAXPARTITIONS; + + if (n == 0 && part_blkno == DOSBBSECTOR) { + /* Check for a short jump instruction. */ + fattest = ((bp->b_data[0] << 8) & 0xff00) | (bp->b_data[2] & + 0xff); + if (fattest != 0xeb90 && fattest != 0xe900) + goto notfat; + + /* Check for a valid bytes per sector value. */ + fattest = ((bp->b_data[12] << 8) & 0xff00) | (bp->b_data[11] & + 0xff); + if (fattest < 512 || fattest > 4096 || (fattest % 512 != 0)) + goto notfat; + + /* Check the end of sector marker. */ + fattest = ((bp->b_data[510] << 8) & 0xff00) | (bp->b_data[511] & + 0xff); + if (fattest != 0x55aa) + goto notfat; + + /* Looks like a FAT filesystem. Spoof 'i'. */ + lp->d_partitions['i' - 'a'].p_size = + lp->d_partitions[RAW_PART].p_size; + lp->d_partitions['i' - 'a'].p_offset = 0; + lp->d_partitions['i' - 'a'].p_fstype = FS_MSDOS; + } +notfat: /* record the OpenBSD partition's placement for the caller */ if (partoffp) diff --git a/sys/arch/hppa64/hppa64/disksubr.c b/sys/arch/hppa64/hppa64/disksubr.c index 78d2fee78c8..f60223e1099 100644 --- a/sys/arch/hppa64/hppa64/disksubr.c +++ b/sys/arch/hppa64/hppa64/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.28 2007/02/03 18:22:33 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.29 2007/02/18 13:49:22 krw Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -220,6 +220,7 @@ readdoslabel(bp, strat, lp, osdep, partoffp, cylp, spoofonly) struct dos_partition dp[NDOSPART], *dp2; struct partition *pp; unsigned long extoff = 0; + unsigned int fattest; daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL; int dospartoff, cyl, i, ourpart = -1; @@ -355,7 +356,34 @@ donot: } lp->d_bbsize = 8192; lp->d_sbsize = 64*1024; /* XXX ? */ - lp->d_npartitions = n > 0 ? n + 8 : 3; + lp->d_npartitions = MAXPARTITIONS; + + if (n == 0 && part_blkno == DOSBBSECTOR) { + /* Check for a short jump instruction. */ + fattest = ((bp->b_data[0] << 8) & 0xff00) | (bp->b_data[2] & + 0xff); + if (fattest != 0xeb90 && fattest != 0xe900) + goto notfat; + + /* Check for a valid bytes per sector value. */ + fattest = ((bp->b_data[12] << 8) & 0xff00) | (bp->b_data[11] & + 0xff); + if (fattest < 512 || fattest > 4096 || (fattest % 512 != 0)) + goto notfat; + + /* Check the end of sector marker. */ + fattest = ((bp->b_data[510] << 8) & 0xff00) | (bp->b_data[511] & + 0xff); + if (fattest != 0x55aa) + goto notfat; + + /* Looks like a FAT filesystem. Spoof 'i'. */ + lp->d_partitions['i' - 'a'].p_size = + lp->d_partitions[RAW_PART].p_size; + lp->d_partitions['i' - 'a'].p_offset = 0; + lp->d_partitions['i' - 'a'].p_fstype = FS_MSDOS; + } +notfat: /* record the OpenBSD partition's placement for the caller */ if (partoffp) diff --git a/sys/arch/i386/i386/disksubr.c b/sys/arch/i386/i386/disksubr.c index 566533a4a13..ba57c79f7d4 100644 --- a/sys/arch/i386/i386/disksubr.c +++ b/sys/arch/i386/i386/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.69 2007/02/03 18:22:33 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.70 2007/02/18 13:49:22 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -67,6 +67,7 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp, struct partition *pp; struct disklabel *dlp; unsigned long extoff = 0; + unsigned int fattest; struct buf *bp = NULL; daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL; @@ -212,6 +213,33 @@ donot: lp->d_sbsize = 64*1024; /* XXX ? */ lp->d_npartitions = MAXPARTITIONS; + if (n == 0 && part_blkno == DOSBBSECTOR) { + /* Check for a short jump instruction. */ + fattest = ((bp->b_data[0] << 8) & 0xff00) | (bp->b_data[2] & + 0xff); + if (fattest != 0xeb90 && fattest != 0xe900) + goto notfat; + + /* Check for a valid bytes per sector value. */ + fattest = ((bp->b_data[12] << 8) & 0xff00) | (bp->b_data[11] & + 0xff); + if (fattest < 512 || fattest > 4096 || (fattest % 512 != 0)) + goto notfat; + + /* Check the end of sector marker. */ + fattest = ((bp->b_data[510] << 8) & 0xff00) | (bp->b_data[511] & + 0xff); + if (fattest != 0x55aa) + goto notfat; + + /* Looks like a FAT filesystem. Spoof 'i'. */ + lp->d_partitions['i' - 'a'].p_size = + lp->d_partitions[RAW_PART].p_size; + lp->d_partitions['i' - 'a'].p_offset = 0; + lp->d_partitions['i' - 'a'].p_fstype = FS_MSDOS; + } +notfat: + /* don't read the on-disk label if we are in spoofed-only mode */ if (spoofonly) goto done; diff --git a/sys/arch/landisk/landisk/disksubr.c b/sys/arch/landisk/landisk/disksubr.c index a3251e2d058..926922e2095 100644 --- a/sys/arch/landisk/landisk/disksubr.c +++ b/sys/arch/landisk/landisk/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.13 2007/02/03 18:22:33 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.14 2007/02/18 13:49:22 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -71,6 +71,7 @@ readdisklabel(dev, strat, lp, osdep, spoofonly) struct partition *pp; struct disklabel *dlp; unsigned long extoff = 0; + unsigned int fattest; struct buf *bp = NULL; daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL; @@ -215,6 +216,33 @@ donot: lp->d_sbsize = 64*1024; /* XXX ? */ lp->d_npartitions = MAXPARTITIONS; + if (n == 0 && part_blkno == DOSBBSECTOR) { + /* Check for a short jump instruction. */ + fattest = ((bp->b_data[0] << 8) & 0xff00) | (bp->b_data[2] & + 0xff); + if (fattest != 0xeb90 && fattest != 0xe900) + goto notfat; + + /* Check for a valid bytes per sector value. */ + fattest = ((bp->b_data[12] << 8) & 0xff00) | (bp->b_data[11] & + 0xff); + if (fattest < 512 || fattest > 4096 || (fattest % 512 != 0)) + goto notfat; + + /* Check the end of sector marker. */ + fattest = ((bp->b_data[510] << 8) & 0xff00) | (bp->b_data[511] & + 0xff); + if (fattest != 0x55aa) + goto notfat; + + /* Looks like a FAT filesystem. Spoof 'i'. */ + lp->d_partitions['i' - 'a'].p_size = + lp->d_partitions[RAW_PART].p_size; + lp->d_partitions['i' - 'a'].p_offset = 0; + lp->d_partitions['i' - 'a'].p_fstype = FS_MSDOS; + } +notfat: + /* don't read the on-disk label if we are in spoofed-only mode */ if (spoofonly) goto done; diff --git a/sys/arch/macppc/macppc/disksubr.c b/sys/arch/macppc/macppc/disksubr.c index 18d432cd113..b5201c6795a 100644 --- a/sys/arch/macppc/macppc/disksubr.c +++ b/sys/arch/macppc/macppc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.35 2007/02/03 18:22:33 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.36 2007/02/18 13:49:22 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -70,6 +70,7 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), struct partition *pp; struct disklabel *dlp; unsigned long extoff = 0; + unsigned int fattest; struct buf *bp; daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL; @@ -301,6 +302,33 @@ donot: lp->d_sbsize = 64*1024; /* XXX ? */ lp->d_npartitions = MAXPARTITIONS; + if (n == 0 && part_blkno == DOSBBSECTOR) { + /* Check for a short jump instruction. */ + fattest = ((bp->b_data[0] << 8) & 0xff00) | (bp->b_data[2] & + 0xff); + if (fattest != 0xeb90 && fattest != 0xe900) + goto notfat; + + /* Check for a valid bytes per sector value. */ + fattest = ((bp->b_data[12] << 8) & 0xff00) | (bp->b_data[11] & + 0xff); + if (fattest < 512 || fattest > 4096 || (fattest % 512 != 0)) + goto notfat; + + /* Check the end of sector marker. */ + fattest = ((bp->b_data[510] << 8) & 0xff00) | (bp->b_data[511] & + 0xff); + if (fattest != 0x55aa) + goto notfat; + + /* Looks like a FAT filesystem. Spoof 'i'. */ + lp->d_partitions['i' - 'a'].p_size = + lp->d_partitions[RAW_PART].p_size; + lp->d_partitions['i' - 'a'].p_offset = 0; + lp->d_partitions['i' - 'a'].p_fstype = FS_MSDOS; + } +notfat: + /* don't read the on-disk label if we are in spoofed-only mode */ if (spoofonly) goto done; diff --git a/sys/arch/mips64/mips64/disksubr.c b/sys/arch/mips64/mips64/disksubr.c index 42d8c8f1857..7b4518c1559 100644 --- a/sys/arch/mips64/mips64/disksubr.c +++ b/sys/arch/mips64/mips64/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.34 2007/02/03 18:22:33 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.35 2007/02/18 13:49:22 krw Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -228,6 +228,7 @@ readdoslabel(bp, strat, lp, osdep, partoffp, cylp, spoofonly) struct dos_partition dp[NDOSPART], *dp2; struct partition *pp; unsigned long extoff = 0; + unsigned int fattest; daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL; int dospartoff, cyl, i, ourpart = -1; @@ -363,7 +364,34 @@ donot: } lp->d_bbsize = 8192; lp->d_sbsize = 64*1024; /* XXX ? */ - lp->d_npartitions = n > 0 ? n + 8 : 3; + lp->d_npartitions = MAXPARTITIONS; + + if (n == 0 && part_blkno == DOSBBSECTOR) { + /* Check for a short jump instruction. */ + fattest = ((bp->b_data[0] << 8) & 0xff00) | (bp->b_data[2] & + 0xff); + if (fattest != 0xeb90 && fattest != 0xe900) + goto notfat; + + /* Check for a valid bytes per sector value. */ + fattest = ((bp->b_data[12] << 8) & 0xff00) | (bp->b_data[11] & + 0xff); + if (fattest < 512 || fattest > 4096 || (fattest % 512 != 0)) + goto notfat; + + /* Check the end of sector marker. */ + fattest = ((bp->b_data[510] << 8) & 0xff00) | (bp->b_data[511] & + 0xff); + if (fattest != 0x55aa) + goto notfat; + + /* Looks like a FAT filesystem. Spoof 'i'. */ + lp->d_partitions['i' - 'a'].p_size = + lp->d_partitions[RAW_PART].p_size; + lp->d_partitions['i' - 'a'].p_offset = 0; + lp->d_partitions['i' - 'a'].p_fstype = FS_MSDOS; + } +notfat: /* record the OpenBSD partition's placement for the caller */ if (partoffp) diff --git a/sys/arch/mvmeppc/mvmeppc/disksubr.c b/sys/arch/mvmeppc/mvmeppc/disksubr.c index 45473b054b9..f3c7bec6ed4 100644 --- a/sys/arch/mvmeppc/mvmeppc/disksubr.c +++ b/sys/arch/mvmeppc/mvmeppc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.31 2007/02/03 18:22:33 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.32 2007/02/18 13:49:22 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -74,6 +74,7 @@ readdisklabel(dev, strat, lp, osdep, spoofonly) struct partition *pp; struct disklabel *dlp; unsigned long extoff = 0; + unsigned int fattest; struct buf *bp; daddr_t part_blkno = DOSBBSECTOR; char *msg = NULL; @@ -218,6 +219,33 @@ donot: lp->d_sbsize = 64*1024; /* XXX ? */ lp->d_npartitions = MAXPARTITIONS; + if (n == 0 && part_blkno == DOSBBSECTOR) { + /* Check for a short jump instruction. */ + fattest = ((bp->b_data[0] << 8) & 0xff00) | (bp->b_data[2] & + 0xff); + if (fattest != 0xeb90 && fattest != 0xe900) + goto notfat; + + /* Check for a valid bytes per sector value. */ + fattest = ((bp->b_data[12] << 8) & 0xff00) | (bp->b_data[11] & + 0xff); + if (fattest < 512 || fattest > 4096 || (fattest % 512 != 0)) + goto notfat; + + /* Check the end of sector marker. */ + fattest = ((bp->b_data[510] << 8) & 0xff00) | (bp->b_data[511] & + 0xff); + if (fattest != 0x55aa) + goto notfat; + + /* Looks like a FAT filesystem. Spoof 'i'. */ + lp->d_partitions['i' - 'a'].p_size = + lp->d_partitions[RAW_PART].p_size; + lp->d_partitions['i' - 'a'].p_offset = 0; + lp->d_partitions['i' - 'a'].p_fstype = FS_MSDOS; + } +notfat: + /* don't read the on-disk label if we are in spoofed-only mode */ if (spoofonly) goto done; |