diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2012-04-07 16:48:39 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2012-04-07 16:48:39 +0000 |
commit | e1d3eacc1dbb1e6b6f7884516db9a220fc9a4f79 (patch) | |
tree | bb008ee512fff5095e0d82fc5df6ba9730c6a01d /sys/kern | |
parent | 5ef8dee4c781181c4c257ac39dfee320bacd9d8f (diff) |
Tweak FAT detection/usage. Recognize 'bare' FAT media that lacks
the 0x55aa signature. Don't try FAT detection if we have found an
OpenBSD MBR partition. Don't try to read a disklabel from 'bare'
FAT media. There can't be one.
Finally, don't allow the writing of a disklabel on 'bare' FAT media.
There is no safe spot for it, and splatting it in the middle of the
FAT structures has not proved helpful.
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/subr_disk.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index 542fd5097f4..c79eb61cb59 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.144 2012/03/31 23:10:34 krw Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.145 2012/04/07 16:48:38 krw Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -435,7 +435,7 @@ readdoslabel(struct buf *bp, void (*strat)(struct buf *), mbrtest = ((bp->b_data[510] << 8) & 0xff00) | (bp->b_data[511] & 0xff); if (mbrtest != 0x55aa) - goto notfat; + goto notmbr; } if (ourpart == -1) { @@ -542,13 +542,13 @@ donot: DL_SETPSIZE(pp, letoh32(dp2->dp_size)); } } - if (partoffp) - /* dospartoff has been set and we must not modify *lp. */ - goto notfat; - lp->d_npartitions = MAXPARTITIONS; +notmbr: + if (partoffp == NULL) + /* Must not modify *lp when partoffp is set. */ + lp->d_npartitions = MAXPARTITIONS; - if (n == 0 && part_blkno == DOSBBSECTOR) { + if (n == 0 && part_blkno == DOSBBSECTOR && ourpart == -1) { u_int16_t fattest; /* Check for a valid initial jmp instruction. */ @@ -578,12 +578,17 @@ donot: if (fattest < 512 || fattest > 4096 || (fattest % 512 != 0)) goto notfat; - /* Looks like a FAT filesystem. Spoof 'i'. */ + if (partoffp) + return (ENXIO); /* No place for disklabel on FAT! */ + DL_SETPSIZE(&lp->d_partitions['i' - 'a'], DL_GETPSIZE(&lp->d_partitions[RAW_PART])); DL_SETPOFFSET(&lp->d_partitions['i' - 'a'], 0); lp->d_partitions['i' - 'a'].p_fstype = FS_MSDOS; + + spoofonly = 1; /* No disklabel to read from disk. */ } + notfat: /* record the OpenBSD partition's placement for the caller */ if (partoffp) |