2007-10-09 00:12:05 +04:00
|
|
|
/* $NetBSD: disksubr.c,v 1.9 2007/10/08 20:12:05 ad Exp $ */
|
2003-11-15 20:52:30 +03:00
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
/*
|
2003-11-15 20:52:30 +03:00
|
|
|
* Copyright (c) 1982, 1986, 1988 Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
1998-06-20 08:58:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1994, 1995 Gordon W. Ross
|
|
|
|
* Copyright (c) 1994 Theo de Raadt
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-07-15 06:54:31 +04:00
|
|
|
#include <sys/cdefs.h>
|
2007-10-09 00:12:05 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.9 2007/10/08 20:12:05 ad Exp $");
|
2003-07-15 06:54:31 +04:00
|
|
|
|
1998-06-20 08:58:50 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/dkbad.h>
|
|
|
|
|
1998-06-20 09:58:05 +04:00
|
|
|
#include <dev/sun/disklabel.h>
|
|
|
|
|
2003-11-15 20:52:30 +03:00
|
|
|
#if LABELSECTOR != 0
|
|
|
|
#error "Default value of LABELSECTOR no longer zero?"
|
1998-06-20 08:58:50 +04:00
|
|
|
#endif
|
|
|
|
|
2005-05-31 04:47:54 +04:00
|
|
|
static const char *disklabel_sun_to_bsd(char *, struct disklabel *);
|
2005-02-04 05:10:35 +03:00
|
|
|
static int disklabel_bsd_to_sun(struct disklabel *, char *);
|
1998-06-20 08:58:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to read a disk label from a device
|
2002-02-19 20:09:40 +03:00
|
|
|
* using the indicated strategy routine.
|
1998-06-20 08:58:50 +04:00
|
|
|
* The label must be partly set up before this:
|
|
|
|
* secpercyl, secsize and anything required for a block i/o read
|
|
|
|
* operation in the driver's strategy/start routines
|
|
|
|
* must be filled in before calling us.
|
|
|
|
*
|
|
|
|
* Return buffer for use in signalling errors if requested.
|
|
|
|
*
|
|
|
|
* Returns null on success and an error string on failure.
|
|
|
|
*/
|
2003-05-02 12:45:10 +04:00
|
|
|
const char *
|
1998-06-20 08:58:50 +04:00
|
|
|
readdisklabel(dev, strat, lp, clp)
|
|
|
|
dev_t dev;
|
2005-02-04 05:10:35 +03:00
|
|
|
void (*strat)(struct buf *);
|
1998-06-20 08:58:50 +04:00
|
|
|
struct disklabel *lp;
|
|
|
|
struct cpu_disklabel *clp;
|
|
|
|
{
|
|
|
|
struct buf *bp;
|
|
|
|
struct disklabel *dlp;
|
|
|
|
struct sun_disklabel *slp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* minimal requirements for archtypal disk label */
|
|
|
|
if (lp->d_secperunit == 0)
|
|
|
|
lp->d_secperunit = 0x1fffffff;
|
2000-12-18 01:39:18 +03:00
|
|
|
if (lp->d_npartitions == 0) {
|
|
|
|
lp->d_npartitions = RAW_PART + 1;
|
|
|
|
if (lp->d_partitions[RAW_PART].p_size == 0)
|
|
|
|
lp->d_partitions[RAW_PART].p_size = 0x1fffffff;
|
|
|
|
lp->d_partitions[RAW_PART].p_offset = 0;
|
|
|
|
}
|
1998-06-20 08:58:50 +04:00
|
|
|
|
|
|
|
/* obtain buffer to probe drive with */
|
|
|
|
bp = geteblk((int)lp->d_secsize);
|
|
|
|
|
|
|
|
/* next, dig out disk label */
|
|
|
|
bp->b_dev = dev;
|
|
|
|
bp->b_blkno = LABELSECTOR;
|
2000-01-18 22:48:02 +03:00
|
|
|
bp->b_cylinder = 0;
|
1998-06-20 08:58:50 +04:00
|
|
|
bp->b_bcount = lp->d_secsize;
|
2000-11-20 11:24:08 +03:00
|
|
|
bp->b_flags |= B_READ;
|
1998-06-20 08:58:50 +04:00
|
|
|
(*strat)(bp);
|
|
|
|
|
|
|
|
/* if successful, locate disk label within block and validate */
|
|
|
|
error = biowait(bp);
|
|
|
|
if (error == 0) {
|
|
|
|
/* Save the whole block in case it has info we need. */
|
2003-11-09 19:41:52 +03:00
|
|
|
memcpy(clp->cd_block, bp->b_data, sizeof(clp->cd_block));
|
1998-06-20 08:58:50 +04:00
|
|
|
}
|
2007-10-09 00:12:05 +04:00
|
|
|
brelse(bp, 0);
|
1998-06-20 08:58:50 +04:00
|
|
|
if (error)
|
|
|
|
return ("disk label read error");
|
|
|
|
|
2003-11-15 20:52:30 +03:00
|
|
|
/* Check for a NetBSD disk label at LABELOFFSET */
|
1998-06-20 08:58:50 +04:00
|
|
|
dlp = (struct disklabel *) (clp->cd_block + LABELOFFSET);
|
|
|
|
if (dlp->d_magic == DISKMAGIC) {
|
|
|
|
if (dkcksum(dlp))
|
|
|
|
return ("NetBSD disk label corrupted");
|
|
|
|
*lp = *dlp;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for a Sun disk label (for PROM compatibility). */
|
|
|
|
slp = (struct sun_disklabel *) clp->cd_block;
|
|
|
|
if (slp->sl_magic == SUN_DKMAGIC)
|
|
|
|
return (disklabel_sun_to_bsd(clp->cd_block, lp));
|
|
|
|
|
2003-11-15 20:52:30 +03:00
|
|
|
/*
|
|
|
|
* Check for a NetBSD disk label somewhere in LABELSECTOR
|
|
|
|
* (compat with others big-endian boxes)
|
|
|
|
*/
|
|
|
|
for (dlp = (struct disklabel *)clp->cd_block;
|
|
|
|
dlp <= (struct disklabel *)((char *)clp->cd_block +
|
|
|
|
DEV_BSIZE - sizeof(*dlp));
|
|
|
|
dlp = (struct disklabel *)((char *)dlp + sizeof(long))) {
|
|
|
|
if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (dlp->d_npartitions > MAXPARTITIONS || dkcksum(dlp) != 0)
|
|
|
|
return("NetBSD disk label corrupted");
|
|
|
|
else {
|
|
|
|
*lp = *dlp;
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
}
|
1998-06-20 08:58:50 +04:00
|
|
|
|
2003-11-09 19:41:52 +03:00
|
|
|
memset(clp->cd_block, 0, sizeof(clp->cd_block));
|
1998-06-20 08:58:50 +04:00
|
|
|
return ("no disk label");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check new disk label for sensibility
|
|
|
|
* before setting it.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
setdisklabel(olp, nlp, openmask, clp)
|
2000-03-30 15:37:21 +04:00
|
|
|
struct disklabel *olp, *nlp;
|
1998-06-20 08:58:50 +04:00
|
|
|
u_long openmask;
|
|
|
|
struct cpu_disklabel *clp;
|
|
|
|
{
|
2000-03-30 15:37:21 +04:00
|
|
|
int i;
|
|
|
|
struct partition *opp, *npp;
|
1998-06-20 08:58:50 +04:00
|
|
|
|
|
|
|
/* sanity clause */
|
|
|
|
if (nlp->d_secpercyl == 0 || nlp->d_secsize == 0 ||
|
|
|
|
(nlp->d_secsize % DEV_BSIZE) != 0)
|
|
|
|
return(EINVAL);
|
|
|
|
|
|
|
|
/* special case to allow disklabel to be invalidated */
|
|
|
|
if (nlp->d_magic == 0xffffffff) {
|
|
|
|
*olp = *nlp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC ||
|
|
|
|
dkcksum(nlp) != 0)
|
|
|
|
return (EINVAL);
|
|
|
|
|
2002-03-05 12:40:38 +03:00
|
|
|
while ((i = ffs(openmask)) != 0) {
|
1998-06-20 08:58:50 +04:00
|
|
|
i--;
|
|
|
|
openmask &= ~(1 << i);
|
|
|
|
if (nlp->d_npartitions <= i)
|
|
|
|
return (EBUSY);
|
|
|
|
opp = &olp->d_partitions[i];
|
|
|
|
npp = &nlp->d_partitions[i];
|
|
|
|
if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size)
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
|
|
|
|
*olp = *nlp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write disk label back to device after modification.
|
|
|
|
* Current label is already in clp->cd_block[]
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
writedisklabel(dev, strat, lp, clp)
|
|
|
|
dev_t dev;
|
2005-02-04 05:10:35 +03:00
|
|
|
void (*strat)(struct buf *);
|
2000-03-30 15:37:21 +04:00
|
|
|
struct disklabel *lp;
|
1998-06-20 08:58:50 +04:00
|
|
|
struct cpu_disklabel *clp;
|
|
|
|
{
|
|
|
|
struct buf *bp;
|
|
|
|
int error;
|
|
|
|
struct disklabel *dlp;
|
|
|
|
struct sun_disklabel *slp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Embed native label in a piece of wasteland.
|
|
|
|
*/
|
|
|
|
if (sizeof(struct disklabel) > sizeof slp->sl_bsdlabel)
|
|
|
|
return EFBIG;
|
|
|
|
|
|
|
|
slp = (struct sun_disklabel *)clp->cd_block;
|
2003-11-09 19:41:52 +03:00
|
|
|
memset(slp->sl_bsdlabel, 0, sizeof(slp->sl_bsdlabel));
|
1998-06-20 08:58:50 +04:00
|
|
|
dlp = (struct disklabel *)slp->sl_bsdlabel;
|
|
|
|
*dlp = *lp;
|
|
|
|
|
|
|
|
/* Build a SunOS compatible label around the native label */
|
|
|
|
error = disklabel_bsd_to_sun(lp, clp->cd_block);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/* Get a buffer and copy the new label into it. */
|
|
|
|
bp = geteblk((int)lp->d_secsize);
|
2003-11-09 19:41:52 +03:00
|
|
|
memcpy(bp->b_data, clp->cd_block, sizeof(clp->cd_block));
|
1998-06-20 08:58:50 +04:00
|
|
|
|
|
|
|
/* Write out the updated label. */
|
|
|
|
bp->b_dev = dev;
|
|
|
|
bp->b_blkno = LABELSECTOR;
|
2000-01-18 22:48:02 +03:00
|
|
|
bp->b_cylinder = 0;
|
1998-06-20 08:58:50 +04:00
|
|
|
bp->b_bcount = lp->d_secsize;
|
2000-11-20 11:24:08 +03:00
|
|
|
bp->b_flags |= B_WRITE;
|
1998-06-20 08:58:50 +04:00
|
|
|
(*strat)(bp);
|
|
|
|
error = biowait(bp);
|
2007-10-09 00:12:05 +04:00
|
|
|
brelse(bp, 0);
|
1998-06-20 08:58:50 +04:00
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
*
|
1998-06-20 09:58:05 +04:00
|
|
|
* The rest of this was taken from arch/sparc/scsi/sun_disklabel.c
|
1998-06-20 08:58:50 +04:00
|
|
|
* and then substantially rewritten by Gordon W. Ross
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/* What partition types to assume for Sun disklabels: */
|
|
|
|
static u_char
|
|
|
|
sun_fstypes[8] = {
|
|
|
|
FS_BSDFFS, /* a */
|
|
|
|
FS_SWAP, /* b */
|
|
|
|
FS_OTHER, /* c - whole disk */
|
|
|
|
FS_BSDFFS, /* d */
|
|
|
|
FS_BSDFFS, /* e */
|
|
|
|
FS_BSDFFS, /* f */
|
|
|
|
FS_BSDFFS, /* g */
|
|
|
|
FS_BSDFFS, /* h */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a SunOS disk label, set lp to a BSD disk label.
|
|
|
|
* Returns NULL on success, else an error string.
|
|
|
|
*
|
|
|
|
* The BSD label is cleared out before this is called.
|
|
|
|
*/
|
2005-05-31 02:17:11 +04:00
|
|
|
static const char *
|
1998-06-20 08:58:50 +04:00
|
|
|
disklabel_sun_to_bsd(cp, lp)
|
|
|
|
char *cp;
|
|
|
|
struct disklabel *lp;
|
|
|
|
{
|
|
|
|
struct sun_disklabel *sl;
|
|
|
|
struct partition *npp;
|
|
|
|
struct sun_dkpart *spp;
|
|
|
|
int i, secpercyl;
|
|
|
|
u_short cksum, *sp1, *sp2;
|
|
|
|
|
|
|
|
sl = (struct sun_disklabel *)cp;
|
|
|
|
|
|
|
|
/* Verify the XOR check. */
|
|
|
|
sp1 = (u_short *)sl;
|
|
|
|
sp2 = (u_short *)(sl + 1);
|
|
|
|
cksum = 0;
|
|
|
|
while (sp1 < sp2)
|
|
|
|
cksum ^= *sp1++;
|
|
|
|
if (cksum != 0)
|
|
|
|
return("SunOS disk label, bad checksum");
|
|
|
|
|
|
|
|
/* Format conversion. */
|
|
|
|
lp->d_magic = DISKMAGIC;
|
|
|
|
lp->d_magic2 = DISKMAGIC;
|
|
|
|
memcpy(lp->d_packname, sl->sl_text, sizeof(lp->d_packname));
|
|
|
|
|
|
|
|
lp->d_secsize = 512;
|
|
|
|
lp->d_nsectors = sl->sl_nsectors;
|
|
|
|
lp->d_ntracks = sl->sl_ntracks;
|
|
|
|
lp->d_ncylinders = sl->sl_ncylinders;
|
|
|
|
|
|
|
|
secpercyl = sl->sl_nsectors * sl->sl_ntracks;
|
|
|
|
lp->d_secpercyl = secpercyl;
|
|
|
|
lp->d_secperunit = secpercyl * sl->sl_ncylinders;
|
|
|
|
|
|
|
|
lp->d_sparespercyl = sl->sl_sparespercyl;
|
|
|
|
lp->d_acylinders = sl->sl_acylinders;
|
|
|
|
lp->d_rpm = sl->sl_rpm;
|
|
|
|
lp->d_interleave = sl->sl_interleave;
|
|
|
|
|
|
|
|
lp->d_npartitions = 8;
|
|
|
|
/* These are as defined in <ufs/ffs/fs.h> */
|
|
|
|
lp->d_bbsize = 8192; /* XXX */
|
|
|
|
lp->d_sbsize = 8192; /* XXX */
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
spp = &sl->sl_part[i];
|
|
|
|
npp = &lp->d_partitions[i];
|
|
|
|
npp->p_offset = spp->sdkp_cyloffset * secpercyl;
|
|
|
|
npp->p_size = spp->sdkp_nsectors;
|
|
|
|
if (npp->p_size == 0) {
|
|
|
|
npp->p_fstype = FS_UNUSED;
|
|
|
|
} else {
|
|
|
|
npp->p_fstype = sun_fstypes[i];
|
|
|
|
if (npp->p_fstype == FS_BSDFFS) {
|
|
|
|
/*
|
|
|
|
* The sun label does not store the FFS fields,
|
|
|
|
* so just set them with default values here.
|
|
|
|
*/
|
|
|
|
npp->p_fsize = 1024;
|
|
|
|
npp->p_frag = 8;
|
|
|
|
npp->p_cpg = 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lp->d_checksum = 0;
|
|
|
|
lp->d_checksum = dkcksum(lp);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a BSD disk label, update the Sun disklabel
|
|
|
|
* pointed to by cp with the new info. Note that the
|
|
|
|
* Sun disklabel may have other info we need to keep.
|
|
|
|
* Returns zero or error code.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
disklabel_bsd_to_sun(lp, cp)
|
|
|
|
struct disklabel *lp;
|
|
|
|
char *cp;
|
|
|
|
{
|
|
|
|
struct sun_disklabel *sl;
|
|
|
|
struct partition *npp;
|
|
|
|
struct sun_dkpart *spp;
|
|
|
|
int i, secpercyl;
|
|
|
|
u_short cksum, *sp1, *sp2;
|
|
|
|
|
|
|
|
if (lp->d_secsize != 512)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
sl = (struct sun_disklabel *)cp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Format conversion.
|
|
|
|
*/
|
|
|
|
memcpy(sl->sl_text, lp->d_packname, sizeof(lp->d_packname));
|
|
|
|
sl->sl_rpm = lp->d_rpm;
|
|
|
|
sl->sl_pcylinders = lp->d_ncylinders + lp->d_acylinders; /* XXX */
|
|
|
|
sl->sl_sparespercyl = lp->d_sparespercyl;
|
|
|
|
sl->sl_interleave = lp->d_interleave;
|
|
|
|
sl->sl_ncylinders = lp->d_ncylinders;
|
|
|
|
sl->sl_acylinders = lp->d_acylinders;
|
|
|
|
sl->sl_ntracks = lp->d_ntracks;
|
|
|
|
sl->sl_nsectors = lp->d_nsectors;
|
|
|
|
|
|
|
|
secpercyl = sl->sl_nsectors * sl->sl_ntracks;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
spp = &sl->sl_part[i];
|
|
|
|
npp = &lp->d_partitions[i];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SunOS partitions must start on a cylinder boundary.
|
|
|
|
* Note this restriction is forced upon NetBSD/sparc
|
|
|
|
* labels too, since we want to keep both labels
|
|
|
|
* synchronised.
|
|
|
|
*/
|
|
|
|
if (npp->p_offset % secpercyl)
|
|
|
|
return (EINVAL);
|
|
|
|
spp->sdkp_cyloffset = npp->p_offset / secpercyl;
|
|
|
|
spp->sdkp_nsectors = npp->p_size;
|
|
|
|
}
|
|
|
|
sl->sl_magic = SUN_DKMAGIC;
|
|
|
|
|
|
|
|
/* Compute the XOR check. */
|
|
|
|
sp1 = (u_short *)sl;
|
|
|
|
sp2 = (u_short *)(sl + 1);
|
|
|
|
sl->sl_cksum = cksum = 0;
|
|
|
|
while (sp1 < sp2)
|
|
|
|
cksum ^= *sp1++;
|
|
|
|
sl->sl_cksum = cksum;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search the bad sector table looking for the specified sector.
|
|
|
|
* Return index if found.
|
|
|
|
* Return -1 if not found.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
isbad(bt, cyl, trk, sec)
|
2000-03-30 15:37:21 +04:00
|
|
|
struct dkbad *bt;
|
1998-06-20 08:58:50 +04:00
|
|
|
int cyl, trk, sec;
|
|
|
|
{
|
2000-03-30 15:37:21 +04:00
|
|
|
int i;
|
|
|
|
long blk, bblk;
|
1998-06-20 08:58:50 +04:00
|
|
|
|
|
|
|
blk = ((long)cyl << 16) + (trk << 8) + sec;
|
|
|
|
for (i = 0; i < 126; i++) {
|
|
|
|
bblk = ((long)bt->bt_bad[i].bt_cyl << 16) +
|
|
|
|
bt->bt_bad[i].bt_trksec;
|
|
|
|
if (blk == bblk)
|
|
|
|
return (i);
|
|
|
|
if (blk < bblk || bblk < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (-1);
|
|
|
|
}
|