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/mvmeppc | |
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/mvmeppc')
-rw-r--r-- | sys/arch/mvmeppc/mvmeppc/disksubr.c | 30 |
1 files changed, 29 insertions, 1 deletions
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; |