Use <sys/disklabel_mbr.h>.

This commit is contained in:
thorpej 1999-01-27 21:00:05 +00:00
parent f077362c41
commit cb8268a3a5
4 changed files with 44 additions and 100 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: disksubr.c,v 1.4 1998/06/22 21:12:51 sommerfe Exp $ */
/* $NetBSD: disksubr.c,v 1.5 1999/01/27 21:00:05 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1988 Regents of the University of California.
@ -45,8 +45,8 @@
#define b_cylin b_resid
int fat_types[] = { DOSPTYP_FAT12, DOSPTYP_FAT16S,
DOSPTYP_FAT16B, DOSPTYP_FAT16C, -1 };
int fat_types[] = { MBR_PTYPE_FAT12, MBR_PTYPE_FAT16S,
MBR_PTYPE_FAT16B, MBR_PTYPE_FAT16L, -1 };
/*
* Attempt to read a disk label from a device
@ -101,10 +101,10 @@ readdisklabel(dev, strat, lp, osdep)
cyl = LABELSECTOR / lp->d_secpercyl;
if (osdep && (dp = osdep->dosparts) != NULL) {
/* read master boot record */
bp->b_blkno = DOSBBSECTOR;
bp->b_blkno = MBR_BBSECTOR;
bp->b_bcount = lp->d_secsize;
bp->b_flags = B_BUSY | B_READ;
bp->b_cylin = DOSBBSECTOR / lp->d_secpercyl;
bp->b_cylin = MBR_BBSECTOR / lp->d_secpercyl;
(*strat)(bp);
/* if successful, wander through dos partition table */
@ -113,39 +113,39 @@ readdisklabel(dev, strat, lp, osdep)
goto done;
} else {
/* XXX how do we check veracity/bounds of this? */
bcopy(bp->b_data + DOSPARTOFF, dp,
NDOSPART * sizeof(*dp));
for (i = 0; i < NDOSPART; i++, dp++) {
bcopy(bp->b_data + MBR_PARTOFF, dp,
NMBRPART * sizeof(*dp));
for (i = 0; i < NMBRPART; i++, dp++) {
/* Install in partition e, f, g, or h. */
pp = &lp->d_partitions[RAW_PART + 1 + i];
pp->p_offset = dp->dp_start;
pp->p_size = dp->dp_size;
pp->p_offset = dp->mbrp_start;
pp->p_size = dp->mbrp_size;
for (ip = fat_types; *ip != -1; ip++) {
if (dp->dp_typ == *ip)
if (dp->mbrp_typ == *ip)
pp->p_fstype = FS_MSDOS;
}
/* is this ours? */
if (dp->dp_size &&
(dp->dp_typ == DOSPTYP_NETBSD
if (dp->mbrp_size &&
(dp->mbrp_typ == MBR_PTYPE_NETBSD
#ifdef COMPAT_386BSD_MBRPART
|| (dp->dp_typ == DOSPTYP_386BSD &&
|| (dp->mbrp_typ == MBR_PTYPE_386BSD &&
(printf("old BSD partition ID!\n"), 1)
/* XXX XXX - libsa printf() is void */)
#endif
) && dospartoff == 0) {
/* need sector address for SCSI/IDE,
cylinder for ESDI/ST506/RLL */
dospartoff = dp->dp_start;
cyl = DPCYL(dp->dp_scyl, dp->dp_ssect);
dospartoff = dp->mbrp_start;
cyl = MBR_PCYL(dp->mbrp_scyl, dp->mbrp_ssect);
/* update disklabel with details */
lp->d_partitions[2].p_size =
dp->dp_size;
dp->mbrp_size;
lp->d_partitions[2].p_offset =
dp->dp_start;
lp->d_ntracks = dp->dp_ehd + 1;
lp->d_nsectors = DPSECT(dp->dp_esect);
dp->mbrp_start;
lp->d_ntracks = dp->mbrp_ehd + 1;
lp->d_nsectors = DPSECT(dp->mbrp_esect);
lp->d_secpercyl =
lp->d_ntracks * lp->d_nsectors;
}
@ -315,22 +315,22 @@ writedisklabel(dev, strat, lp, osdep)
if ((error = biowait(bp)) == 0) {
/* XXX how do we check veracity/bounds of this? */
bcopy(bp->b_data + DOSPARTOFF, dp,
NDOSPART * sizeof(*dp));
for (i = 0; i < NDOSPART; i++, dp++)
bcopy(bp->b_data + MBR_PARTOFF, dp,
NMBRPART * sizeof(*dp));
for (i = 0; i < NMBRPART; i++, dp++)
/* is this ours? */
if (dp->dp_size &&
(dp->dp_typ == DOSPTYP_NETBSD
if (dp->mbrp_size &&
(dp->mbrp_typ == MBR_PTYPE_NETBSD
#ifdef COMPAT_386BSD_MBRPART
|| (dp->dp_typ == DOSPTYP_386BSD &&
|| (dp->mbrp_typ == MBR_PTYPE_386BSD &&
(printf("old BSD partition ID!\n"), 1)
/* XXX XXX - libsa printf() is void */)
#endif
) && dospartoff == 0) {
/* need sector address for SCSI/IDE,
cylinder for ESDI/ST506/RLL */
dospartoff = dp->dp_start;
cyl = DPCYL(dp->dp_scyl, dp->dp_ssect);
dospartoff = dp->mbrp_start;
cyl = MBR_PCYL(dp->mbrp_scyl, dp->mbrp_ssect);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: disklabel.h,v 1.3 1998/07/07 04:36:15 thorpej Exp $ */
/* $NetBSD: disklabel.h,v 1.4 1999/01/27 21:00:05 thorpej Exp $ */
/*
* Copyright (c) 1994 Christopher G. Demetriou
@ -38,42 +38,15 @@
#define MAXPARTITIONS 8 /* number of partitions */
#define RAW_PART 3 /* raw partition: XX?d (XXX) */
/* DOS partition table -- located in boot block */
#define DOSBBSECTOR 0 /* DOS boot block relative sector # */
#define DOSPARTOFF 446
#define NDOSPART 4
struct dos_partition {
u_int8_t dp_flag; /* bootstrap flags */
u_int8_t dp_shd; /* starting head */
u_int8_t dp_ssect; /* starting sector */
u_int8_t dp_scyl; /* starting cylinder */
u_int8_t dp_typ; /* partition type (see below) */
u_int8_t dp_ehd; /* end head */
u_int8_t dp_esect; /* end sector */
u_int8_t dp_ecyl; /* end cylinder */
u_int32_t dp_start; /* absolute starting sector number */
u_int32_t dp_size; /* partition size in sectors */
};
/* Known DOS partition types. */
#define DOSPTYP_386BSD 0xa5 /* 386BSD partition type */
#define DOSPTYP_NETBSD 0xa9 /* NetBSD partition type */
#define DOSPTYP_FAT12 0x1 /* 12-bit FAT */
#define DOSPTYP_FAT16S 0x4 /* 16-bit FAT, less than 32M */
#define DOSPTYP_FAT16B 0x6 /* 16-bit FAT, more than 32M */
#define DOSPTYP_FAT16C 0xe /* 16-bit FAT, CHS-mapped */
/* Pull in MBR partition definitions. */
#include <sys/disklabel_mbr.h>
#include <sys/dkbad.h>
struct cpu_disklabel {
struct dos_partition dosparts[NDOSPART];
struct mbr_partition dosparts[NMBRPART];
struct dkbad bad;
};
/* Isolate the relevant bits to get sector and cylinder. */
#define DPSECT(s) ((s) & 0x3f)
#define DPCYL(c, s) ((c) + (((s) & 0xc0) << 2))
#ifdef _KERNEL
struct disklabel;
int bounds_check_with_label __P((struct buf *, struct disklabel *, int));

View File

@ -1,4 +1,4 @@
/* $NetBSD: disklabel.h,v 1.5 1998/10/30 06:48:51 scottr Exp $ */
/* $NetBSD: disklabel.h,v 1.6 1999/01/27 21:03:46 thorpej Exp $ */
/*
* Copyright (c) 1994 Christopher G. Demetriou
@ -71,35 +71,6 @@
#define MAXPARTITIONS 8 /* number of partitions */
#define RAW_PART 2 /* raw partition: xx?c */
/* DOS partition table -- located in boot block */
#define DOSBBSECTOR 0 /* DOS boot block relative sector # */
#define DOSPARTOFF 446
#define NDOSPART 4
struct dos_partition {
u_int8_t dp_flag; /* bootstrap flags */
u_int8_t dp_shd; /* starting head */
u_int8_t dp_ssect; /* starting sector */
u_int8_t dp_scyl; /* starting cylinder */
u_int8_t dp_typ; /* partition type (see below) */
u_int8_t dp_ehd; /* end head */
u_int8_t dp_esect; /* end sector */
u_int8_t dp_ecyl; /* end cylinder */
u_int32_t dp_start; /* absolute starting sector number */
u_int32_t dp_size; /* partition size in sectors */
};
/* Known DOS partition types. */
#define DOSPTYP_NETBSD 0xa9 /* NetBSD/i386 partition type (XXX) */
#define DOSPTYP_386BSD 0xa5 /* 386BSD partition type (XXX) */
#define DOSPTYP_FAT12 0x01 /* 12-bit FAT */
#define DOSPTYP_FAT16S 0x04 /* 16-bit FAT, less than 32M */
#define DOSPTYP_FAT16B 0x06 /* 16-bit FAT, more than 32M */
#define DOSPTYP_FAT32 0x0b /* 32-bit FAT */
#define DOSPTYP_FAT32L 0x0c /* 32-bit FAT, LBA-mapped */
#define DOSPTYP_FAT16L 0x0e /* 16-bit FAT, LBA-mapped */
#define DOSPTYP_LNXEXT2 0x83 /* Linux native */
/* Just a dummy */
struct cpu_disklabel {
int cd_dummy; /* must have one element. */

View File

@ -1,4 +1,4 @@
/* $NetBSD: disksubr.c,v 1.27 1999/01/19 15:41:03 scottr Exp $ */
/* $NetBSD: disksubr.c,v 1.28 1999/01/27 21:03:46 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1988 Regents of the University of California.
@ -100,9 +100,9 @@
#define MBRSIGOFS 0x1fe
#define MBRSIG 0x55aa
int fat_types[] = { DOSPTYP_FAT12, DOSPTYP_FAT16S,
DOSPTYP_FAT16B, DOSPTYP_FAT32,
DOSPTYP_FAT32L, DOSPTYP_FAT16L,
int fat_types[] = { MBR_PTYPE_FAT12, MBR_PTYPE_FAT16S,
MBR_PTYPE_FAT16B, MBR_PTYPE_FAT32,
MBR_PTYPE_FAT32L, MBR_PTYPE_FAT16L,
-1 };
static int getFreeLabelEntry __P((struct disklabel *));
@ -485,7 +485,7 @@ read_dos_label(dev, strat, lp, osdep)
struct disklabel *lp;
struct cpu_disklabel *osdep;
{
struct dos_partition *dp;
struct mbr_partition *dp;
struct partition *pp;
struct buf *bp;
char *msg = NULL;
@ -496,10 +496,10 @@ read_dos_label(dev, strat, lp, osdep)
bp->b_dev = dev;
/* read master boot record */
bp->b_blkno = DOSBBSECTOR;
bp->b_blkno = MBR_BBSECTOR;
bp->b_bcount = lp->d_secsize;
bp->b_flags = B_BUSY | B_READ;
bp->b_cylin = DOSBBSECTOR / lp->d_secpercyl;
bp->b_cylin = MBR_BBSECTOR / lp->d_secpercyl;
(*strat)(bp);
/* if successful, wander through dos partition table */
@ -508,8 +508,8 @@ read_dos_label(dev, strat, lp, osdep)
goto done;
} else {
/* XXX */
dp = (struct dos_partition *)(bp->b_data + DOSPARTOFF);
for (i = 0; i < NDOSPART; i++, dp++) {
dp = (struct mbr_partition *)(bp->b_data + MBR_PARTOFF);
for (i = 0; i < NMBRPART; i++, dp++) {
if (dp->dp_typ != 0) {
slot = getFreeLabelEntry(lp);
if (slot > maxslot)
@ -730,9 +730,9 @@ bounds_check_with_label(bp, lp, wlabel)
}
#endif
#if defined(DOSBBSECTOR) && defined(notyet)
#if defined(MBR_BBSECTOR) && defined(notyet)
/* overwriting master boot record? */
if (bp->b_blkno + p->p_offset <= DOSBBSECTOR &&
if (bp->b_blkno + p->p_offset <= MBR_BBSECTOR &&
(bp->b_flags & B_READ) == 0 && wlabel == 0) {
bp->b_error = EROFS;
goto bad;