Check RAW_PART against the media size instead of the disklabel.

Add the media size in 512-byte sectors to the softc, to avoid
some 64 bit computations. Bump the capacity stored in softcs
for disks to 64 bits.
This commit is contained in:
fvdl 2003-04-03 22:18:23 +00:00
parent 14e617d80f
commit 8103646465
10 changed files with 94 additions and 47 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: wd.c,v 1.239 2003/03/21 22:40:56 thorpej Exp $ */
/* $NetBSD: wd.c,v 1.240 2003/04/03 22:18:23 fvdl Exp $ */
/*
* Copyright (c) 1998, 2001 Manuel Bouyer. All rights reserved.
@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.239 2003/03/21 22:40:56 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: wd.c,v 1.240 2003/04/03 22:18:23 fvdl Exp $");
#ifndef WDCDEBUG
#define WDCDEBUG
@ -366,13 +366,12 @@ wdattach(parent, self, aux)
wd->sc_params.atap_heads *
wd->sc_params.atap_sectors;
}
format_bytes(pbuf, sizeof(pbuf),
(u_int64_t)wd->sc_capacity * DEV_BSIZE);
format_bytes(pbuf, sizeof(pbuf), wd->sc_capacity * DEV_BSIZE);
printf("%s: %s, %d cyl, %d head, %d sec, "
"%d bytes/sect x %d sectors\n",
"%d bytes/sect x %llu sectors\n",
self->dv_xname, pbuf, wd->sc_params.atap_cylinders,
wd->sc_params.atap_heads, wd->sc_params.atap_sectors,
DEV_BSIZE, wd->sc_capacity);
DEV_BSIZE, (unsigned long long)wd->sc_capacity);
WDCDEBUG_PRINT(("%s: atap_dmatiming_mimi=%d, atap_dmatiming_recom=%d\n",
self->dv_xname, wd->sc_params.atap_dmatiming_mimi,
@ -502,9 +501,15 @@ wdstrategy(bp)
* Do bounds checking, adjust transfer. if error, process.
* If end of partition, just return.
*/
if (bounds_check_with_label(bp, wd->sc_dk.dk_label,
(wd->sc_flags & (WDF_WLABEL|WDF_LABELLING)) != 0) <= 0)
goto done;
if (WDPART(bp->b_dev) == RAW_PART) {
if (bounds_check_with_mediasize(bp, DEV_BSIZE,
wd->sc_capacity) <= 0)
goto done;
} else {
if (bounds_check_with_label(bp, wd->sc_dk.dk_label,
(wd->sc_flags & (WDF_WLABEL|WDF_LABELLING)) != 0) <= 0)
goto done;
}
/*
* Now convert the block number to absolute and put it in
@ -996,7 +1001,10 @@ wdgetdefaultlabel(wd, lp)
strncpy(lp->d_typename, wd->sc_params.atap_model, 16);
strncpy(lp->d_packname, "fictitious", 16);
lp->d_secperunit = wd->sc_capacity;
if (wd->sc_capacity > UINT32_MAX)
lp->d_secperunit = UINT32_MAX;
else
lp->d_secperunit = wd->sc_capacity;
lp->d_rpm = 3600;
lp->d_interleave = 1;
lp->d_flags = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: wdvar.h,v 1.14 2003/03/21 22:40:57 thorpej Exp $ */
/* $NetBSD: wdvar.h,v 1.15 2003/04/03 22:18:23 fvdl Exp $ */
/*
* Copyright (c) 1998, 2001 Manuel Bouyer.
@ -128,7 +128,7 @@ struct wd_softc {
#define WDF_LBA 0x040 /* using LBA mode */
#define WDF_KLABEL 0x080 /* retain label after 'full' close */
#define WDF_LBA48 0x100 /* using 48-bit LBA mode */
int sc_capacity;
u_int64_t sc_capacity;
int cyl; /* actual drive parameters */
int heads;
int sectors;

View File

@ -1,4 +1,4 @@
/* $NetBSD: cd.c,v 1.180 2003/03/20 05:49:21 dbj Exp $ */
/* $NetBSD: cd.c,v 1.181 2003/04/03 22:18:24 fvdl Exp $ */
/*-
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@ -54,7 +54,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.180 2003/03/20 05:49:21 dbj Exp $");
__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.181 2003/04/03 22:18:24 fvdl Exp $");
#include "rnd.h"
@ -584,9 +584,15 @@ cdstrategy(bp)
* Do bounds checking, adjust transfer. if error, process.
* If end of partition, just return.
*/
if (bounds_check_with_label(bp, lp,
(cd->flags & (CDF_WLABEL|CDF_LABELLING)) != 0) <= 0)
goto done;
if (CDPART(bp->b_dev) == RAW_PART) {
if (bounds_check_with_mediasize(bp, DEV_BSIZE,
cd->params.disksize512) <= 0)
goto done;
} else {
if (bounds_check_with_label(bp, lp,
(cd->flags & (CDF_WLABEL|CDF_LABELLING)) != 0) <= 0)
goto done;
}
/*
* Now convert the block number to absolute and put it in
@ -1561,6 +1567,7 @@ cd_size(cd, flags)
*/
cd->params.blksize = 2048;
cd->params.disksize = 400000;
cd->params.disksize512 = 1600000;
return (400000);
}
@ -1590,6 +1597,7 @@ cd_size(cd, flags)
if (size < 100)
size = 400000; /* ditto */
cd->params.disksize = size;
cd->params.disksize512 = (cd->params.disksize * blksize) / DEV_BSIZE;
SC_DEBUG(cd->sc_periph, SCSIPI_DB2,
("cd_size: %d %ld\n", blksize, size));

View File

@ -1,4 +1,4 @@
/* $NetBSD: cdvar.h,v 1.15 2002/07/22 14:59:44 hannken Exp $ */
/* $NetBSD: cdvar.h,v 1.16 2003/04/03 22:18:24 fvdl Exp $ */
/*
* Copyright (c) 1997 Manuel Bouyer. All rights reserved.
@ -49,6 +49,7 @@ struct cd_softc {
struct cd_parms {
int blksize;
u_long disksize; /* total number sectors */
u_long disksize512; /* total number sectors */
} params;
struct bufq_state buf_queue;

View File

@ -1,4 +1,4 @@
/* $NetBSD: scsipi_base.c,v 1.84 2003/02/03 23:51:00 thorpej Exp $ */
/* $NetBSD: scsipi_base.c,v 1.85 2003/04/03 22:18:25 fvdl Exp $ */
/*-
* Copyright (c) 1998, 1999, 2000, 2002 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.84 2003/02/03 23:51:00 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.85 2003/04/03 22:18:25 fvdl Exp $");
#include "opt_scsi.h"
@ -1003,7 +1003,7 @@ scsipi_interpret_sense(xs)
*
* Find out from the device what its capacity is.
*/
u_long
u_int64_t
scsipi_size(periph, flags)
struct scsipi_periph *periph;
int flags;

View File

@ -1,4 +1,4 @@
/* $NetBSD: scsipiconf.h,v 1.71 2002/10/19 18:41:34 mjacob Exp $ */
/* $NetBSD: scsipiconf.h,v 1.72 2003/04/03 22:18:25 fvdl Exp $ */
/*-
* Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
@ -641,7 +641,7 @@ caddr_t scsipi_inqmatch __P((struct scsipi_inquiry_pattern *, caddr_t,
char *scsipi_dtype __P((int));
void scsipi_strvis __P((u_char *, int, u_char *, int));
int scsipi_execute_xs __P((struct scsipi_xfer *));
u_long scsipi_size __P((struct scsipi_periph *, int));
u_int64_t scsipi_size __P((struct scsipi_periph *, int));
int scsipi_test_unit_ready __P((struct scsipi_periph *, int));
int scsipi_prevent __P((struct scsipi_periph *, int, int));
int scsipi_inquire __P((struct scsipi_periph *,
@ -720,6 +720,8 @@ static __inline u_int32_t _3btol __P((const u_int8_t *bytes))
__attribute__ ((unused));
static __inline u_int32_t _4btol __P((const u_int8_t *bytes))
__attribute__ ((unused));
static __inline u_int64_t _5btol __P((const u_int8_t *bytes))
__attribute__ ((unused));
static __inline void _lto2l __P((u_int32_t val, u_int8_t *bytes))
__attribute__ ((unused));
@ -803,6 +805,20 @@ _4btol(bytes)
return (rv);
}
static __inline u_int64_t
_5btol(bytes)
const u_int8_t *bytes;
{
u_int64_t rv;
rv = ((u_int64_t)bytes[0] << 32) |
((u_int64_t)bytes[1] << 24) |
((u_int64_t)bytes[2] << 16) |
((u_int64_t)bytes[3] << 8) |
(u_int64_t)bytes[4];
return (rv);
}
static __inline void
_lto2l(val, bytes)
u_int32_t val;

View File

@ -1,4 +1,4 @@
/* $NetBSD: sd.c,v 1.196 2003/03/20 05:49:21 dbj Exp $ */
/* $NetBSD: sd.c,v 1.197 2003/04/03 22:18:25 fvdl Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -54,7 +54,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.196 2003/03/20 05:49:21 dbj Exp $");
__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.197 2003/04/03 22:18:25 fvdl Exp $");
#include "opt_scsi.h"
#include "opt_bufq.h"
@ -204,9 +204,9 @@ sdattach(parent, sd, periph, ops)
format_bytes(pbuf, sizeof(pbuf),
(u_int64_t)dp->disksize * dp->blksize);
printf(
"%s, %ld cyl, %ld head, %ld sec, %ld bytes/sect x %lu sectors",
"%s, %ld cyl, %ld head, %ld sec, %ld bytes/sect x %llu sectors",
pbuf, dp->cyls, dp->heads, dp->sectors, dp->blksize,
dp->disksize);
(unsigned long long)dp->disksize);
break;
case SDGP_RESULT_OFFLINE:
@ -631,9 +631,15 @@ sdstrategy(bp)
* Do bounds checking, adjust transfer. if error, process.
* If end of partition, just return.
*/
if (bounds_check_with_label(bp, lp,
(sd->flags & (SDF_WLABEL|SDF_LABELLING)) != 0) <= 0)
goto done;
if (SDPART(bp->b_dev) == RAW_PART) {
if (bounds_check_with_mediasize(bp, DEV_BSIZE,
sd->params.disksize512) <= 0)
goto done;
} else {
if (bounds_check_with_label(bp, lp,
(sd->flags & (SDF_WLABEL|SDF_LABELLING)) != 0) <= 0)
goto done;
}
/*
* Now convert the block number to absolute and put it in

View File

@ -1,4 +1,4 @@
/* $NetBSD: sd_atapi.c,v 1.17 2002/10/02 16:52:54 thorpej Exp $ */
/* $NetBSD: sd_atapi.c,v 1.18 2003/04/03 22:18:26 fvdl Exp $ */
/*
* Copyright 1998
@ -40,7 +40,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sd_atapi.c,v 1.17 2002/10/02 16:52:54 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: sd_atapi.c,v 1.18 2003/04/03 22:18:26 fvdl Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -174,6 +174,10 @@ sd_atapibus_get_parms(sd, dp, flags)
dp->disksize = _4btol(descp->nblks);
dp->blksize = _3btol(descp->blklen);
if (dp->blksize == 0)
dp->disksize512 = dp->disksize;
else
dp->disksize512 = (dp->disksize * dp->blksize) / DEV_BSIZE;
/*
* First, set up standard fictitious geometry, a la sd_scsi.c.

View File

@ -1,4 +1,4 @@
/* $NetBSD: sd_scsi.c,v 1.27 2003/03/07 16:18:57 drochner Exp $ */
/* $NetBSD: sd_scsi.c,v 1.28 2003/04/03 22:18:26 fvdl Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -54,7 +54,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sd_scsi.c,v 1.27 2003/03/07 16:18:57 drochner Exp $");
__KERNEL_RCSID(0, "$NetBSD: sd_scsi.c,v 1.28 2003/04/03 22:18:26 fvdl Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -205,7 +205,7 @@ sd_scsibus_get_optparms(sd, dp, flags)
int flags;
{
struct sd_scsibus_mode_sense_data scsipi_sense;
u_long sectors;
u_int64_t sectors;
int error;
dp->blksize = 512;
@ -236,6 +236,7 @@ sd_scsibus_get_optparms(sd, dp, flags)
dp->sectors = 32;
dp->cyls = sectors / (dp->heads * dp->sectors);
dp->disksize = sectors;
dp->disksize512 = (sectors * dp->blksize) / DEV_BSIZE;
return (SDGP_RESULT_OK);
}
@ -258,7 +259,7 @@ sd_scsibus_get_simplifiedparms(sd, dp, flags)
u_int8_t flags;
u_int8_t resvd;
} scsipi_sense;
u_long sectors;
u_int64_t sectors;
int error;
/*
@ -288,15 +289,14 @@ sd_scsibus_get_simplifiedparms(sd, dp, flags)
dp->heads = 64;
dp->sectors = 32;
dp->cyls = sectors / (dp->heads * dp->sectors);
/* XXX disksize is only a "long" currently */
dp->disksize = /* XXX _5btol */
(_3btol(scsipi_sense.size) << 16)
| (_2btol(&scsipi_sense.size[3]));
if (dp->disksize != sectors) {
printf("RBC size: mode sense=%ld, get cap=%ld\n",
dp->disksize, sectors);
dp->disksize = _5btol(scsipi_sense.size);
if (dp->disksize <= UINT32_MAX && dp->disksize != sectors) {
printf("RBC size: mode sense=%llu, get cap=%llu\n",
(unsigned long long)dp->disksize,
(unsigned long long)sectors);
dp->disksize = sectors;
}
dp->disksize512 = (dp->disksize * dp->blksize) / DEV_BSIZE;
return (SDGP_RESULT_OK);
}
@ -312,7 +312,7 @@ sd_scsibus_get_parms(sd, dp, flags)
int flags;
{
struct sd_scsibus_mode_sense_data scsipi_sense;
u_long sectors;
u_int64_t sectors;
int page;
int error;
@ -356,6 +356,7 @@ sd_scsibus_get_parms(sd, dp, flags)
sectors = scsipi_size(sd->sc_periph, flags);
dp->disksize = sectors;
dp->disksize512 = (sectors * dp->blksize) / DEV_BSIZE;
sectors /= (dp->heads * dp->cyls);
dp->sectors = sectors; /* XXX dubious on SCSI */
@ -375,6 +376,8 @@ sd_scsibus_get_parms(sd, dp, flags)
if (dp->blksize == 0)
dp->blksize = 512;
dp->disksize512 = (dp->disksize * dp->blksize) / DEV_BSIZE;
return (SDGP_RESULT_OK);
}
@ -397,7 +400,7 @@ fake_it:
if (sectors == 0)
return (SDGP_RESULT_OFFLINE); /* XXX? */
dp->blksize = 512;
dp->disksize = sectors;
dp->disksize512 = dp->disksize = sectors;
/* Try calling driver's method for figuring out geometry. */
if (sd->sc_periph->periph_channel->chan_adapter->adapt_getgeom ==
NULL ||

View File

@ -1,4 +1,4 @@
/* $NetBSD: sdvar.h,v 1.18 2003/01/06 21:02:18 matt Exp $ */
/* $NetBSD: sdvar.h,v 1.19 2003/04/03 22:18:26 fvdl Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -92,8 +92,9 @@ struct sd_softc {
u_long cyls; /* number of cylinders */
u_long sectors; /* number of sectors/track */
u_long blksize; /* number of bytes/sector */
u_long disksize; /* total number sectors */
u_long rot_rate; /* rotational rate, in RPM */
u_int64_t disksize; /* total number sectors */
u_int64_t disksize512; /* total number sectors */
} params;
struct bufq_state buf_queue;