(This commit touches about 15 disk device drivers in a very consistent

and predictable way, and I apologize if I have gotten it wrong anywhere,
getting prior review on a patch like this is not feasible, considering
the number of people involved and hardware availability etc.)

If struct disklabel is the messenger: kill the messenger.

Inside struct disk we had a struct disklabel which disk drivers used to
communicate certain metrics to the disklayer above (GEOM or the disk
mini-layer).  This commit changes this communication to use four
explicit fields instead.

Amongst the benefits is that the fields do not get overwritten by
wrong or bogus on-disk disklabels.

Once that is clear, <sys/disk.h> which is included in the drivers
no longer need to pull <sys/disklabel.h> and <sys/diskslice.h> in,
the few places that needs them, have gotten explicit #includes for
them.

The disklabel inside struct disk is now only for internal use in
the disk mini-layer, so instead of embedding it, we malloc it as
we need it.

This concludes (modulus any mistakes) the series of disklabel related
commits.

I belive it all amounts to a NOP for all the rest of you :-)

Sponsored by:   DARPA & NAI Labs.
This commit is contained in:
phk 2002-09-20 19:36:05 +00:00
parent 2fb7a39c0f
commit 57a346a213
22 changed files with 100 additions and 219 deletions

View File

@ -54,6 +54,7 @@
#include <sys/bio.h>
#include <sys/conf.h>
#include <sys/disk.h>
#include <sys/diskslice.h>
#include <sys/malloc.h>
#include <sys/cdio.h>
#include <sys/dvdio.h>
@ -858,10 +859,8 @@ cdregister(struct cam_periph *periph, void *arg)
static int
cdopen(dev_t dev, int flags, int fmt, struct thread *td)
{
struct disklabel *label;
struct cam_periph *periph;
struct cd_softc *softc;
struct ccb_getdev cgd;
u_int32_t size;
int error;
int s;
@ -912,41 +911,12 @@ cdopen(dev_t dev, int flags, int fmt, struct thread *td)
error = 0;
}
/*
* Build prototype label for whole disk.
* Should take information about different data tracks from the
* TOC and put it in the partition table.
*/
label = &softc->disk.d_label;
bzero(label, sizeof(*label));
label->d_type = DTYPE_SCSI;
/*
* Grab the inquiry data to get the vendor and product names.
* Put them in the typename and packname for the label.
*/
xpt_setup_ccb(&cgd.ccb_h, periph->path, /*priority*/ 1);
cgd.ccb_h.func_code = XPT_GDEV_TYPE;
xpt_action((union ccb *)&cgd);
strncpy(label->d_typename, cgd.inq_data.vendor,
min(SID_VENDOR_SIZE, sizeof(label->d_typename)));
strncpy(label->d_packname, cgd.inq_data.product,
min(SID_PRODUCT_SIZE, sizeof(label->d_packname)));
label->d_secsize = softc->params.blksize;
label->d_secperunit = softc->params.disksize;
label->d_flags = D_REMOVABLE;
/*
* Make partition 'a' cover the whole disk. This is a temporary
* compatibility hack. The 'a' partition should not exist, so
* the slice code won't create it. The slice code will make
* partition (RAW_PART + 'a') cover the whole disk and fill in
* some more defaults.
*/
label->d_partitions[0].p_size = label->d_secperunit;
label->d_partitions[0].p_fstype = FS_OTHER;
softc->disk.d_sectorsize = softc->params.blksize;
softc->disk.d_mediasize = softc->params.blksize *
(off_t)softc->params.disksize;
softc->disk.d_fwsectors = 0;
softc->disk.d_fwheads = 0;
/*
* We unconditionally (re)set the blocksize each time the
* CD device is opened. This is because the CD can change,

View File

@ -496,7 +496,6 @@ daopen(dev_t dev, int flags __unused, int fmt __unused, struct thread *td __unus
{
struct cam_periph *periph;
struct da_softc *softc;
struct disklabel *label;
struct scsi_read_capacity_data *rcap;
union ccb *ccb;
int unit;
@ -565,33 +564,12 @@ daopen(dev_t dev, int flags __unused, int fmt __unused, struct thread *td __unus
free(rcap, M_TEMP);
if (error == 0) {
struct ccb_getdev cgd;
/* Build label for whole disk. */
label = &softc->disk.d_label;
bzero(label, sizeof(*label));
label->d_type = DTYPE_SCSI;
/*
* Grab the inquiry data to get the vendor and product names.
* Put them in the typename and packname for the label.
*/
xpt_setup_ccb(&cgd.ccb_h, periph->path, /*priority*/ 1);
cgd.ccb_h.func_code = XPT_GDEV_TYPE;
xpt_action((union ccb *)&cgd);
strncpy(label->d_typename, cgd.inq_data.vendor,
min(SID_VENDOR_SIZE, sizeof(label->d_typename)));
strncpy(label->d_packname, cgd.inq_data.product,
min(SID_PRODUCT_SIZE, sizeof(label->d_packname)));
label->d_secsize = softc->params.secsize;
label->d_nsectors = softc->params.secs_per_track;
label->d_ntracks = softc->params.heads;
label->d_ncylinders = softc->params.cylinders;
label->d_secpercyl = softc->params.heads
* softc->params.secs_per_track;
label->d_secperunit = softc->params.sectors;
softc->disk.d_sectorsize = softc->params.secsize;
softc->disk.d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
/* XXX: these are not actually "firmware" values, so they may be wrong */
softc->disk.d_fwsectors = softc->params.secs_per_track;
softc->disk.d_fwheads = softc->params.heads;
/*
* Check to see whether or not the blocksize is set yet.

View File

@ -116,7 +116,7 @@ flaopen(dev_t dev, int flag, int fmt, struct thread *td)
{
struct fla_s *sc;
int error;
struct disklabel *dl;
u_int spu, ncyl, nt, ns;
if (fla_debug)
printf("flaopen(%s %x %x %p)\n",
@ -131,12 +131,11 @@ flaopen(dev_t dev, int flag, int fmt, struct thread *td)
return (EIO);
}
dl = &sc->disk.d_label;
bzero(dl, sizeof(*dl));
error = doc2k_size(sc->unit, &dl->d_secperunit,
&dl->d_ncylinders, &dl->d_ntracks, &dl->d_nsectors);
dl->d_secsize = DEV_BSIZE;
dl->d_secpercyl = dl->d_ntracks * dl->d_nsectors; /* XXX */
error = doc2k_size(sc->unit, &spu, &ncyl, &nt, &ns);
sc->disk.d_sectorsize = DEV_BSIZE;
sc->disk.d_mediasize = (off_t)spu * DEV_BSIZE;
sc->disk.d_fwsectors = ns;
sc->disk.d_fwheads = nt;
return (0);
}

View File

@ -130,7 +130,6 @@ static int
aac_disk_open(dev_t dev, int flags, int fmt, d_thread_t *td)
{
struct aac_disk *sc;
struct disklabel *label;
debug_called(4);
@ -143,16 +142,10 @@ aac_disk_open(dev_t dev, int flags, int fmt, d_thread_t *td)
if (sc->ad_controller->aac_state & AAC_STATE_SUSPEND)
return(ENXIO);
/* build synthetic label */
label = &sc->ad_disk.d_label;
bzero(label, sizeof(*label));
label->d_type = DTYPE_ESDI;
label->d_secsize = AAC_BLOCK_SIZE;
label->d_nsectors = sc->ad_sectors;
label->d_ntracks = sc->ad_heads;
label->d_ncylinders = sc->ad_cylinders;
label->d_secpercyl = sc->ad_sectors * sc->ad_heads;
label->d_secperunit = sc->ad_size;
sc->ad_disk.d_sectorsize = AAC_BLOCK_SIZE;
sc->ad_disk.d_mediasize = (off_t)sc->ad_size * AAC_BLOCK_SIZE;
sc->ad_disk.d_fwsectors = sc->ad_sectors;
sc->ad_disk.d_fwheads = sc->ad_heads;
sc->ad_flags |= AAC_DISK_OPEN;
return (0);

View File

@ -103,7 +103,6 @@ static int
amrd_open(dev_t dev, int flags, int fmt, struct thread *td)
{
struct amrd_softc *sc = (struct amrd_softc *)dev->si_drv1;
struct disklabel *label;
debug_called(1);
@ -114,15 +113,10 @@ amrd_open(dev_t dev, int flags, int fmt, struct thread *td)
if (sc->amrd_controller->amr_state & AMR_STATE_SHUTDOWN)
return(ENXIO);
label = &sc->amrd_disk.d_label;
bzero(label, sizeof(*label));
label->d_type = DTYPE_SCSI;
label->d_secsize = AMR_BLKSIZE;
label->d_nsectors = sc->amrd_drive->al_sectors;
label->d_ntracks = sc->amrd_drive->al_heads;
label->d_ncylinders = sc->amrd_drive->al_cylinders;
label->d_secpercyl = sc->amrd_drive->al_sectors * sc->amrd_drive->al_heads;
label->d_secperunit = sc->amrd_drive->al_size;
sc->amrd_disk.d_sectorsize = AMR_BLKSIZE;
sc->amrd_disk.d_mediasize = (off_t)sc->amrd_drive->al_size * AMR_BLKSIZE;
sc->amrd_disk.d_fwsectors = sc->amrd_drive->al_sectors;
sc->amrd_disk.d_fwheads = sc->amrd_drive->al_heads;
sc->amrd_flags |= AMRD_OPEN;
return (0);

View File

@ -208,14 +208,10 @@ ad_attach(struct ata_device *atadev)
dev->si_iosize_max = adp->max_iosize;
adp->dev = dev;
/* construct the disklabel */
bzero(&adp->disk.d_label, sizeof(struct disklabel));
adp->disk.d_label.d_secsize = DEV_BSIZE;
adp->disk.d_label.d_nsectors = adp->sectors;
adp->disk.d_label.d_ntracks = adp->heads;
adp->disk.d_label.d_ncylinders = adp->total_secs/(adp->heads*adp->sectors);
adp->disk.d_label.d_secpercyl = adp->sectors * adp->heads;
adp->disk.d_label.d_secperunit = adp->total_secs;
adp->disk.d_sectorsize = DEV_BSIZE;
adp->disk.d_mediasize = DEV_BSIZE * (off_t)adp->total_secs;
adp->disk.d_fwsectors = adp->sectors;
adp->disk.d_fwheads = adp->heads;
atadev->driver = adp;
atadev->flags = 0;

View File

@ -470,16 +470,11 @@ static int
aropen(dev_t dev, int flags, int fmt, struct thread *td)
{
struct ar_softc *rdp = dev->si_drv1;
struct disklabel *dl;
dl = &rdp->disk.d_label;
bzero(dl, sizeof *dl);
dl->d_secsize = DEV_BSIZE;
dl->d_nsectors = rdp->sectors;
dl->d_ntracks = rdp->heads;
dl->d_ncylinders = rdp->cylinders;
dl->d_secpercyl = rdp->sectors * rdp->heads;
dl->d_secperunit = rdp->total_sectors;
rdp->disk.d_sectorsize = DEV_BSIZE;
rdp->disk.d_mediasize = (off_t)rdp->total_sectors * DEV_BSIZE;
rdp->disk.d_fwsectors = rdp->sectors;
rdp->disk.d_fwheads = rdp->heads;
return 0;
}

View File

@ -224,7 +224,6 @@ static int
afdopen(dev_t dev, int flags, int fmt, struct thread *td)
{
struct afd_softc *fdp = dev->si_drv1;
struct disklabel *label = &fdp->disk.d_label;
atapi_test_ready(fdp->device);
@ -236,13 +235,12 @@ afdopen(dev_t dev, int flags, int fmt, struct thread *td)
fdp->device->flags &= ~ATA_D_MEDIA_CHANGED;
bzero(label, sizeof *label);
label->d_secsize = fdp->cap.sector_size;
label->d_nsectors = fdp->cap.sectors;
label->d_ntracks = fdp->cap.heads;
label->d_ncylinders = fdp->cap.cylinders;
label->d_secpercyl = fdp->cap.sectors * fdp->cap.heads;
label->d_secperunit = label->d_secpercyl * fdp->cap.cylinders;
fdp->disk.d_sectorsize = fdp->cap.sector_size;
fdp->disk.d_mediasize = (off_t)fdp->cap.sector_size * fdp->cap.sectors *
fdp->cap.heads * fdp->cap.cylinders;
fdp->disk.d_fwsectors = fdp->cap.sectors;
fdp->disk.d_fwheads = fdp->cap.heads;
return 0;
}

View File

@ -100,6 +100,7 @@
#include <sys/stdint.h>
#include <sys/sysctl.h>
#include <sys/disk.h>
#include <sys/disklabel.h>
#include <sys/devicestat.h>
#include <sys/fcntl.h>
#include <sys/vnode.h>

View File

@ -111,21 +111,15 @@ static int
idad_open(dev_t dev, int flags, int fmt, struct thread *td)
{
struct idad_softc *drv;
struct disklabel *label;
drv = idad_getsoftc(dev);
if (drv == NULL)
return (ENXIO);
label = &drv->disk.d_label;
bzero(label, sizeof(*label));
label->d_type = DTYPE_SCSI;
label->d_secsize = drv->secsize;
label->d_nsectors = drv->sectors;
label->d_ntracks = drv->heads;
label->d_ncylinders = drv->cylinders;
label->d_secpercyl = drv->sectors * drv->heads;
label->d_secperunit = drv->secperunit;
drv->disk.d_sectorsize = drv->secsize;
drv->disk.d_mediasize = (off_t)drv->secperunit * drv->secsize;
drv->disk.d_fwsectors = drv->sectors;
drv->disk.d_fwheads = drv->heads;
return (0);
}

View File

@ -360,7 +360,6 @@ static int
mdopen(dev_t dev, int flag, int fmt, struct thread *td)
{
struct md_s *sc;
struct disklabel *dl;
if (md_debug)
printf("mdopen(%s %x %x %p)\n",
@ -368,14 +367,10 @@ mdopen(dev_t dev, int flag, int fmt, struct thread *td)
sc = dev->si_drv1;
dl = &sc->disk.d_label;
bzero(dl, sizeof(*dl));
dl->d_secsize = sc->secsize;
dl->d_nsectors = sc->nsect > 63 ? 63 : sc->nsect;
dl->d_ntracks = 1;
dl->d_secpercyl = dl->d_nsectors * dl->d_ntracks;
dl->d_secperunit = sc->nsect;
dl->d_ncylinders = dl->d_secperunit / dl->d_secpercyl;
sc->disk.d_sectorsize = sc->secsize;
sc->disk.d_mediasize = (off_t)sc->nsect * sc->secsize;
sc->disk.d_fwsectors = 0;
sc->disk.d_fwheads = 0;
sc->opencount++;
return (0);
}
@ -646,7 +641,7 @@ mdnew(int unit)
}
if (unit == -1)
unit = max + 1;
if (unit > DKMAXUNIT)
if (unit > 255)
return (NULL);
sc = (struct md_s *)malloc(sizeof *sc, M_MD, M_WAITOK | M_ZERO);
sc->unit = unit;

View File

@ -98,7 +98,6 @@ static int
mlxd_open(dev_t dev, int flags, int fmt, struct thread *td)
{
struct mlxd_softc *sc = (struct mlxd_softc *)dev->si_drv1;
struct disklabel *label;
debug_called(1);
@ -109,15 +108,10 @@ mlxd_open(dev_t dev, int flags, int fmt, struct thread *td)
if (sc->mlxd_controller->mlx_state & MLX_STATE_SHUTDOWN)
return(ENXIO);
label = &sc->mlxd_disk.d_label;
bzero(label, sizeof(*label));
label->d_type = DTYPE_SCSI;
label->d_secsize = MLX_BLKSIZE;
label->d_nsectors = sc->mlxd_drive->ms_sectors;
label->d_ntracks = sc->mlxd_drive->ms_heads;
label->d_ncylinders = sc->mlxd_drive->ms_cylinders;
label->d_secpercyl = sc->mlxd_drive->ms_sectors * sc->mlxd_drive->ms_heads;
label->d_secperunit = sc->mlxd_drive->ms_size;
sc->mlxd_disk.d_sectorsize = MLX_BLKSIZE;
sc->mlxd_disk.d_mediasize = MLX_BLKSIZE * (off_t)sc->mlxd_drive->ms_size;
sc->mlxd_disk.d_fwsectors = sc->mlxd_drive->ms_sectors;
sc->mlxd_disk.d_fwheads = sc->mlxd_drive->ms_heads;
sc->mlxd_flags |= MLXD_OPEN;
return (0);

View File

@ -114,24 +114,16 @@ static int
ofwd_open(dev_t dev, int flags, int fmt, struct thread *td)
{
struct ofwd_softc *sc;
struct disklabel *label;
sc = (struct ofwd_softc *)dev->si_drv1;
if (sc == NULL)
return (ENXIO);
/*
* Build synthetic label.
*/
label = &sc->ofwd_disk.d_label;
bzero(label, sizeof(*label));
label->d_type = DTYPE_ESDI;
label->d_secsize = OFWD_BLOCKSIZE;
label->d_nsectors = 33554432;
label->d_ntracks = 1;
label->d_ncylinders = 1024;
label->d_secpercyl = 32768;
label->d_secperunit = 33554432;
sc->ofwd_disk.d_sectorsize = OFWD_BLOCKSIZE;
sc->ofwd_disk.d_mediasize = (off_t)33554432 * OFWD_BLOCKSIZE;
/* XXX: probably don't need the next two */
sc->ofwd_disk.d_fwsectors = 33554432;
sc->ofwd_disk.d_fwheads = 1
sc->ofwd_flags |= OFWD_OPEN;
return (0);

View File

@ -172,15 +172,10 @@ pst_attach(device_t dev)
psc->device->si_drv1 = psc;
psc->device->si_iosize_max = 64 * 1024; /*I2O_SGL_MAX_SEGS * PAGE_SIZE;*/
bzero(&psc->disk.d_label, sizeof(struct disklabel));
psc->disk.d_label.d_secsize = psc->info->block_size;
psc->disk.d_label.d_nsectors = 63;
psc->disk.d_label.d_ntracks = 255;
psc->disk.d_label.d_ncylinders =
(psc->info->capacity / psc->info->block_size) / (255 * 63);
psc->disk.d_label.d_secpercyl = 255 * 63;
psc->disk.d_label.d_secperunit =
psc->info->capacity / psc->info->block_size;
psc->disk.d_sectorsize = psc->info->block_size;
psc->disk.d_mediasize = psc->info->capacity;
psc->disk.d_fssectors = 63;
psc->disk.d_fsheads = 255;
devstat_add_entry(&psc->stats, "pst", lun, psc->info->block_size,
DEVSTAT_NO_ORDERED_TAGS,

View File

@ -549,7 +549,6 @@ struct twed_softc
struct twe_drive *twed_drive; /* drive data in parent softc */
struct disk twed_disk; /* generic disk handle */
struct devstat twed_stats; /* accounting */
struct disklabel twed_label; /* synthetic label */
int twed_flags;
#define TWED_OPEN (1<<0) /* drive is open (can't shut down) */
};
@ -622,7 +621,6 @@ static int
twed_open(dev_t dev, int flags, int fmt, d_thread_t *td)
{
struct twed_softc *sc = (struct twed_softc *)dev->si_drv1;
struct disklabel *label;
debug_called(4);
@ -633,16 +631,10 @@ twed_open(dev_t dev, int flags, int fmt, d_thread_t *td)
if (sc->twed_controller->twe_state & TWE_STATE_SHUTDOWN)
return(ENXIO);
/* build synthetic label */
label = &sc->twed_disk.d_label;
bzero(label, sizeof(*label));
label->d_type = DTYPE_ESDI;
label->d_secsize = TWE_BLOCK_SIZE;
label->d_nsectors = sc->twed_drive->td_sectors;
label->d_ntracks = sc->twed_drive->td_heads;
label->d_ncylinders = sc->twed_drive->td_cylinders;
label->d_secpercyl = sc->twed_drive->td_sectors * sc->twed_drive->td_heads;
label->d_secperunit = sc->twed_drive->td_size;
sc->twed_disk.d_sectorsize = TWE_BLOCK_SIZE;
sc->twed_disk.d_mediasize = TWE_BLOCK_SIZE * (off_t)sc->twed_drive->td_size;
sc->twed_disk.d_fwsectors = sc->twed_drive->td_sectors;
sc->twed_disk.d_fwheads = sc->twed_drive->td_heads;
sc->twed_flags |= TWED_OPEN;
return (0);

View File

@ -100,6 +100,7 @@
#include <sys/stdint.h>
#include <sys/sysctl.h>
#include <sys/disk.h>
#include <sys/disklabel.h>
#include <sys/devicestat.h>
#include <sys/fcntl.h>
#include <sys/vnode.h>

View File

@ -44,6 +44,8 @@
#include <sys/bio.h>
#include <sys/conf.h>
#include <sys/disk.h>
#include <sys/diskslice.h>
#include <sys/disklabel.h>
#include <sys/malloc.h>
#include <sys/sysctl.h>
#include <sys/stdint.h>
@ -94,8 +96,7 @@ g_disk_access(struct g_provider *pp, int r, int w, int e)
} else {
error = 0;
}
pp->mediasize =
dp->d_label.d_secsize * (off_t)dp->d_label.d_secperunit;
pp->mediasize = dp->d_mediasize;
return (error);
}
@ -110,7 +111,7 @@ g_disk_kerneldump(struct bio *bp, struct disk *dp)
printf("Kerneldump off=%jd len=%jd\n", (intmax_t)gkd->offset, (intmax_t)gkd->length);
di.dumper = (dumper_t *)dp->d_devsw->d_dump;
di.priv = dp->d_dev;
di.blocksize = dp->d_label.d_secsize;
di.blocksize = dp->d_sectorsize;
di.mediaoffset = gkd->offset;
di.mediasize = gkd->length;
error = set_dumper(&di);
@ -153,17 +154,13 @@ g_disk_start(struct bio *bp)
mtx_unlock(&Giant);
break;
case BIO_GETATTR:
if (g_handleattr_int(bp, "GEOM::sectorsize",
dp->d_label.d_secsize))
if (g_handleattr_int(bp, "GEOM::sectorsize", dp->d_sectorsize))
break;
else if (g_handleattr_int(bp, "GEOM::fwsectors",
dp->d_label.d_nsectors))
else if (g_handleattr_int(bp, "GEOM::fwsectors", dp->d_fwsectors))
break;
else if (g_handleattr_int(bp, "GEOM::fwheads",
dp->d_label.d_ntracks))
else if (g_handleattr_int(bp, "GEOM::fwheads", dp->d_fwheads))
break;
else if (g_handleattr_off_t(bp, "GEOM::mediasize",
dp->d_label.d_secsize * (off_t)dp->d_label.d_secperunit))
else if (g_handleattr_off_t(bp, "GEOM::mediasize", dp->d_mediasize))
break;
else if (g_handleattr_off_t(bp, "GEOM::frontstuff", 0))
break;

View File

@ -125,7 +125,6 @@ static int
sscopen(dev_t dev, int flag, int fmt, struct thread *td)
{
struct ssc_s *sc;
struct disklabel *dl;
if (ssc_debug)
printf("sscopen(%s %x %x %p)\n",
@ -133,14 +132,10 @@ sscopen(dev_t dev, int flag, int fmt, struct thread *td)
sc = dev->si_drv1;
dl = &sc->disk.d_label;
bzero(dl, sizeof(*dl));
dl->d_secsize = DEV_BSIZE;
dl->d_nsectors = sc->nsect > 63 ? 63 : sc->nsect;
dl->d_ntracks = 1;
dl->d_secpercyl = dl->d_nsectors * dl->d_ntracks;
dl->d_secperunit = sc->nsect;
dl->d_ncylinders = dl->d_secperunit / dl->d_secpercyl;
sc->disk.d_sectorsize = DEV_BSIZE;
sc->disk.d_mediasize = (off_t)sc-nsect * DEV_BSIZE;
sc->disk.d_fwsectors = 0;
sc->disk.d_fwheads = 0;
return (0);
}

View File

@ -18,6 +18,8 @@
#include <sys/bio.h>
#include <sys/conf.h>
#include <sys/disk.h>
#include <sys/diskslice.h>
#include <sys/disklabel.h>
#ifndef GEOM
#include <sys/kernel.h>
#include <sys/sysctl.h>
@ -175,6 +177,7 @@ disk_create(int unit, struct disk *dp, int flags, struct cdevsw *cdevsw, struct
}
bzero(dp, sizeof(*dp));
dp->d_label = malloc(sizeof *dp->d_label, M_DEVBUF, M_WAITOK|M_ZERO);
if (proto->d_open != diskopen) {
*proto = *cdevsw;
@ -232,6 +235,7 @@ void
disk_destroy(dev_t dev)
{
LIST_REMOVE(dev->si_disk, d_list);
free(dev->si_disk->d_label, M_DEVBUF);
bzero(dev->si_disk, sizeof(*dev->si_disk));
dev->si_disk = NULL;
destroy_dev(dev);
@ -305,6 +309,8 @@ diskopen(dev_t dev, int oflags, int devtype, struct thread *td)
if (!pdev->si_iosize_max)
pdev->si_iosize_max = dev->si_iosize_max;
error = dp->d_devsw->d_open(pdev, oflags, devtype, td);
dp->d_label->d_secsize = dp->d_sectorsize;
dp->d_label->d_secperunit = dp->d_mediasize / dp->d_sectorsize;
}
/* Inherit properties from the whole/raw dev_t */
@ -313,7 +319,7 @@ diskopen(dev_t dev, int oflags, int devtype, struct thread *td)
if (error)
goto out;
error = dsopen(dev, devtype, dp->d_dsflags, &dp->d_slice, &dp->d_label);
error = dsopen(dev, devtype, dp->d_dsflags, &dp->d_slice, dp->d_label);
if (!dsisopen(dp->d_slice))
dp->d_devsw->d_close(pdev, oflags, devtype, td);

View File

@ -46,6 +46,7 @@
#include <sys/buf.h>
#include <sys/conf.h>
#include <sys/kernel.h>
#include <sys/disk.h>
#include <sys/disklabel.h>
#include <sys/syslog.h>

View File

@ -1229,7 +1229,6 @@ wdopen(dev_t dev, int flags, int fmt, struct thread *td)
{
register unsigned int lunit;
register struct softc *du;
struct disklabel *dl;
lunit = dkunit(dev);
if (lunit >= NWD || dksparebits(dev) != 0)
@ -1257,14 +1256,10 @@ wdopen(dev_t dev, int flags, int fmt, struct thread *td)
du->dk_flags |= DKFL_LABELLING;
du->dk_state = WANTOPEN;
dl = &du->disk.d_label;
bzero(dl, sizeof(*dl));
dl->d_secsize = du->dk_dd.d_secsize;
dl->d_nsectors = du->dk_dd.d_nsectors;
dl->d_ntracks = du->dk_dd.d_ntracks;
dl->d_ncylinders = du->dk_dd.d_ncylinders;
dl->d_secpercyl = du->dk_dd.d_secpercyl;
dl->d_secperunit = du->dk_dd.d_secperunit;
du->disk.d_sectorsize = du->dk_dd.d_secsize;
du->disk.d_mediasize = du->dk_dd.d_secperunit * du->dk_dd.d_secsize;
du->disk.d_fwsectors = du->dk_dd.d_nsectors;
du->disk.d_fwheads = du->dk_dd.d_ntracks;
du->dk_flags &= ~DKFL_LABELLING;
wdsleep(du->dk_ctrlr, "wdopn2");

View File

@ -16,13 +16,6 @@
#include <sys/ioccom.h>
#ifdef _KERNEL
#ifndef _SYS_DISKSLICE_H_
#include <sys/diskslice.h>
#endif /* _SYS_DISKSLICE_H_ */
#ifndef _SYS_DISKLABEL
#include <sys/disklabel.h>
#endif /* _SYS_DISKLABEL */
#include <sys/queue.h>
@ -31,8 +24,15 @@ struct disk {
u_int d_dsflags;
struct cdevsw *d_devsw;
dev_t d_dev;
/* These four fields must be valid while opened */
u_int d_sectorsize;
off_t d_mediasize;
u_int d_fwsectors;
u_int d_fwheads;
struct diskslices *d_slice;
struct disklabel d_label;
struct disklabel *d_label;
LIST_ENTRY(disk) d_list;
void *d_softc;
};