Implement DIOCGDEFLABEL.

This commit is contained in:
thorpej 1997-10-08 23:05:22 +00:00
parent 062c3f563a
commit 939e074dcc
7 changed files with 195 additions and 80 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: wd.c,v 1.163 1997/08/27 11:25:14 bouyer Exp $ */
/* $NetBSD: wd.c,v 1.164 1997/10/08 23:10:10 thorpej Exp $ */
/*
* Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
@ -94,6 +94,7 @@ struct cfdriver wd_cd = {
NULL, "wd", DV_DISK
};
void wdgetdefaultlabel __P((struct wd_softc *, struct disklabel *));
void wdgetdisklabel __P((struct wd_softc *));
int wd_get_parms __P((struct wd_softc *));
void wdstrategy __P((struct buf *));
@ -496,21 +497,14 @@ wdclose(dev, flag, fmt, p)
return 0;
}
/*
* Fabricate a default disk label, and try to read the correct one.
*/
void
wdgetdisklabel(wd)
wdgetdefaultlabel(wd, lp)
struct wd_softc *wd;
struct disklabel *lp;
{
struct disklabel *lp = wd->sc_dk.dk_label;
struct wd_link *d_link = wd->d_link;
char *errstring;
WDDEBUG_PRINT(("wdgetdisklabel\n"));
bzero(lp, sizeof(struct disklabel));
bzero(wd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
lp->d_secsize = DEV_BSIZE;
lp->d_ntracks = d_link->sc_params.wdp_heads;
@ -537,6 +531,24 @@ wdgetdisklabel(wd)
lp->d_magic = DISKMAGIC;
lp->d_magic2 = DISKMAGIC;
lp->d_checksum = dkcksum(lp);
}
/*
* Fabricate a default disk label, and try to read the correct one.
*/
void
wdgetdisklabel(wd)
struct wd_softc *wd;
{
struct disklabel *lp = wd->sc_dk.dk_label;
struct wd_link *d_link = wd->d_link;
char *errstring;
WDDEBUG_PRINT(("wdgetdisklabel\n"));
bzero(wd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
wdgetdefaultlabel(wd, lp);
d_link->sc_badsect[0] = -1;
@ -662,7 +674,11 @@ wdioctl(dev, xfer, addr, flag, p)
else
d_link->sc_flags &= ~WDF_WLABEL;
return 0;
case DIOCGDEFLABEL:
wdgetdefaultlabel(wd, (struct disklabel *)addr);
return 0;
#ifdef notyet
case DIOCWFORMAT:
if ((flag & FWRITE) == 0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: ccd.c,v 1.43 1997/08/04 10:00:11 fair Exp $ */
/* $NetBSD: ccd.c,v 1.44 1997/10/08 23:06:59 thorpej Exp $ */
/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@ -190,6 +190,7 @@ static int ccdinit __P((struct ccddevice *, char **, struct proc *));
static int ccdlookup __P((char *, struct proc *p, struct vnode **));
static void ccdbuffer __P((struct ccd_softc *, struct buf *,
daddr_t, caddr_t, long, struct ccdbuf **));
static void ccdgetdefaultlabel __P((struct ccd_softc *, struct disklabel *));
static void ccdgetdisklabel __P((dev_t));
static void ccdmakedisklabel __P((struct ccd_softc *));
static int ccdlock __P((struct ccd_softc *));
@ -1093,6 +1094,7 @@ ccdioctl(dev, cmd, data, flag, p)
case DIOCWDINFO:
case DIOCGPART:
case DIOCWLABEL:
case DIOCGDEFLABEL:
if ((cs->sc_flags & CCDF_INITED) == 0)
return (ENXIO);
}
@ -1300,6 +1302,10 @@ ccdioctl(dev, cmd, data, flag, p)
cs->sc_flags &= ~CCDF_WLABEL;
break;
case DIOCGDEFLABEL:
ccdgetdefaultlabel(cs, (struct disklabel *)data);
break;
default:
return (ENOTTY);
}
@ -1413,23 +1419,14 @@ ccdlookup(path, p, vpp)
return (0);
}
/*
* Read the disklabel from the ccd. If one is not present, fake one
* up.
*/
static void
ccdgetdisklabel(dev)
dev_t dev;
ccdgetdefaultlabel(cs, lp)
struct ccd_softc *cs;
struct disklabel *lp;
{
int unit = ccdunit(dev);
struct ccd_softc *cs = &ccd_softc[unit];
char *errstring;
struct disklabel *lp = cs->sc_dkdev.dk_label;
struct cpu_disklabel *clp = cs->sc_dkdev.dk_cpulabel;
struct ccdgeom *ccg = &cs->sc_geom;
bzero(lp, sizeof(*lp));
bzero(clp, sizeof(*clp));
lp->d_secperunit = cs->sc_size;
lp->d_secsize = ccg->ccg_secsize;
@ -1453,6 +1450,25 @@ ccdgetdisklabel(dev)
lp->d_magic = DISKMAGIC;
lp->d_magic2 = DISKMAGIC;
lp->d_checksum = dkcksum(cs->sc_dkdev.dk_label);
}
/*
* Read the disklabel from the ccd. If one is not present, fake one
* up.
*/
static void
ccdgetdisklabel(dev)
dev_t dev;
{
int unit = ccdunit(dev);
struct ccd_softc *cs = &ccd_softc[unit];
char *errstring;
struct disklabel *lp = cs->sc_dkdev.dk_label;
struct cpu_disklabel *clp = cs->sc_dkdev.dk_cpulabel;
bzero(clp, sizeof(*clp));
ccdgetdefaultlabel(cs, lp);
/*
* Call the generic disklabel extraction routine.
@ -1487,6 +1503,8 @@ ccdmakedisklabel(cs)
lp->d_partitions[RAW_PART].p_fstype = FS_BSDFFS;
strncpy(lp->d_packname, "default label", sizeof(lp->d_packname));
lp->d_checksum = dkcksum(lp);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: mcd.c,v 1.54 1997/06/14 08:55:14 thorpej Exp $ */
/* $NetBSD: mcd.c,v 1.55 1997/10/08 23:10:06 thorpej Exp $ */
/*
* Copyright (c) 1993, 1994, 1995 Charles M. Hannum. All rights reserved.
@ -189,6 +189,7 @@ struct cfdriver mcd_cd = {
NULL, "mcd", DV_DISK
};
void mcdgetdefaultlabel __P((struct mcd_softc *, struct disklabel *));
void mcdgetdisklabel __P((struct mcd_softc *));
int mcd_get_parms __P((struct mcd_softc *));
void mcdstrategy __P((struct buf *));
@ -617,6 +618,10 @@ mcdioctl(dev, cmd, addr, flag, p)
case DIOCWLABEL:
return EBADF;
case DIOCGDEFLABEL:
mcdgetdefaultlabel(sc, (struct disklabel *)addr);
return 0;
case CDIOCPLAYTRACKS:
return mcd_playtracks(sc, (struct ioc_play_track *)addr);
case CDIOCPLAYMSF:
@ -674,18 +679,13 @@ mcdioctl(dev, cmd, addr, flag, p)
#endif
}
/*
* This could have been taken from scsi/cd.c, but it is not clear
* whether the scsi cd driver is linked in.
*/
void
mcdgetdisklabel(sc)
mcdgetdefaultlabel(sc, lp)
struct mcd_softc *sc;
struct disklabel *lp;
{
struct disklabel *lp = sc->sc_dk.dk_label;
bzero(lp, sizeof(struct disklabel));
bzero(sc->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
lp->d_secsize = sc->blksize;
lp->d_ntracks = 1;
@ -710,12 +710,27 @@ mcdgetdisklabel(sc)
lp->d_secperunit * (lp->d_secsize / DEV_BSIZE);
lp->d_partitions[RAW_PART].p_fstype = FS_ISO9660;
lp->d_npartitions = RAW_PART + 1;
lp->d_magic = DISKMAGIC;
lp->d_magic2 = DISKMAGIC;
lp->d_checksum = dkcksum(lp);
}
/*
* This could have been taken from scsi/cd.c, but it is not clear
* whether the scsi cd driver is linked in.
*/
void
mcdgetdisklabel(sc)
struct mcd_softc *sc;
{
struct disklabel *lp = sc->sc_dk.dk_label;
bzero(sc->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
mcdgetdefaultlabel(sc, lp);
}
int
mcd_get_parms(sc)
struct mcd_softc *sc;

View File

@ -1,4 +1,4 @@
/* $NetBSD: wd.c,v 1.163 1997/08/27 11:25:14 bouyer Exp $ */
/* $NetBSD: wd.c,v 1.164 1997/10/08 23:10:10 thorpej Exp $ */
/*
* Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
@ -94,6 +94,7 @@ struct cfdriver wd_cd = {
NULL, "wd", DV_DISK
};
void wdgetdefaultlabel __P((struct wd_softc *, struct disklabel *));
void wdgetdisklabel __P((struct wd_softc *));
int wd_get_parms __P((struct wd_softc *));
void wdstrategy __P((struct buf *));
@ -496,21 +497,14 @@ wdclose(dev, flag, fmt, p)
return 0;
}
/*
* Fabricate a default disk label, and try to read the correct one.
*/
void
wdgetdisklabel(wd)
wdgetdefaultlabel(wd, lp)
struct wd_softc *wd;
struct disklabel *lp;
{
struct disklabel *lp = wd->sc_dk.dk_label;
struct wd_link *d_link = wd->d_link;
char *errstring;
WDDEBUG_PRINT(("wdgetdisklabel\n"));
bzero(lp, sizeof(struct disklabel));
bzero(wd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
lp->d_secsize = DEV_BSIZE;
lp->d_ntracks = d_link->sc_params.wdp_heads;
@ -537,6 +531,24 @@ wdgetdisklabel(wd)
lp->d_magic = DISKMAGIC;
lp->d_magic2 = DISKMAGIC;
lp->d_checksum = dkcksum(lp);
}
/*
* Fabricate a default disk label, and try to read the correct one.
*/
void
wdgetdisklabel(wd)
struct wd_softc *wd;
{
struct disklabel *lp = wd->sc_dk.dk_label;
struct wd_link *d_link = wd->d_link;
char *errstring;
WDDEBUG_PRINT(("wdgetdisklabel\n"));
bzero(wd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
wdgetdefaultlabel(wd, lp);
d_link->sc_badsect[0] = -1;
@ -662,7 +674,11 @@ wdioctl(dev, xfer, addr, flag, p)
else
d_link->sc_flags &= ~WDF_WLABEL;
return 0;
case DIOCGDEFLABEL:
wdgetdefaultlabel(wd, (struct disklabel *)addr);
return 0;
#ifdef notyet
case DIOCWFORMAT:
if ((flag & FWRITE) == 0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: cd.c,v 1.103 1997/10/01 01:18:44 enami Exp $ */
/* $NetBSD: cd.c,v 1.104 1997/10/08 23:05:22 thorpej Exp $ */
/*
* Copyright (c) 1994, 1995, 1997 Charles M. Hannum. All rights reserved.
@ -94,6 +94,7 @@ int cdlock __P((struct cd_softc *));
void cdunlock __P((struct cd_softc *));
void cdstart __P((void *));
void cdminphys __P((struct buf *));
void cdgetdefaultlabel __P((struct cd_softc *, struct disklabel *));
void cdgetdisklabel __P((struct cd_softc *));
void cddone __P((struct scsipi_xfer *));
u_long cd_size __P((struct cd_softc *, int));
@ -707,6 +708,10 @@ cdioctl(dev, cmd, addr, flag, p)
case DIOCWLABEL:
return (EBADF);
case DIOCGDEFLABEL:
cdgetdefaultlabel(cd, (struct disklabel *)addr);
return (0);
case CDIOCPLAYTRACKS: {
struct ioc_play_track *args = (struct ioc_play_track *)addr;
@ -878,21 +883,13 @@ cdioctl(dev, cmd, addr, flag, p)
#endif
}
/*
* Load the label information on the named device
* Actually fabricate a disklabel
*
* EVENTUALLY take information about different
* data tracks from the TOC and put it in the disklabel
*/
void
cdgetdisklabel(cd)
cdgetdefaultlabel(cd, lp)
struct cd_softc *cd;
struct disklabel *lp;
{
struct disklabel *lp = cd->sc_dk.dk_label;
bzero(lp, sizeof(struct disklabel));
bzero(cd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
lp->d_secsize = cd->params.blksize;
lp->d_ntracks = 1;
@ -923,6 +920,24 @@ cdgetdisklabel(cd)
lp->d_checksum = dkcksum(lp);
}
/*
* Load the label information on the named device
* Actually fabricate a disklabel
*
* EVENTUALLY take information about different
* data tracks from the TOC and put it in the disklabel
*/
void
cdgetdisklabel(cd)
struct cd_softc *cd;
{
struct disklabel *lp = cd->sc_dk.dk_label;
bzero(cd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
cdgetdefaultlabel(cd, lp);
}
/*
* Find out from the device what it's capacity is
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: sd.c,v 1.118 1997/10/01 01:19:17 enami Exp $ */
/* $NetBSD: sd.c,v 1.119 1997/10/08 23:05:24 thorpej Exp $ */
/*
* Copyright (c) 1994, 1995, 1997 Charles M. Hannum. All rights reserved.
@ -118,6 +118,7 @@ void sdattach __P((struct device *, struct device *, void *));
int sdlock __P((struct sd_softc *));
void sdunlock __P((struct sd_softc *));
void sdminphys __P((struct buf *));
void sdgetdefaultlabel __P((struct sd_softc *, struct disklabel *));
void sdgetdisklabel __P((struct sd_softc *));
void sdstart __P((void *));
void sddone __P((struct scsipi_xfer *));
@ -767,6 +768,10 @@ sdioctl(dev, cmd, addr, flag, p)
return ((sd->sc_link->flags & SDEV_REMOVABLE) == 0 ? ENOTTY :
scsipi_start(sd->sc_link, SSS_STOP|SSS_LOEJ, 0));
case DIOCGDEFLABEL:
sdgetdefaultlabel(sd, (struct disklabel *)addr);
return (0);
default:
if (SDPART(dev) != RAW_PART)
return (ENOTTY);
@ -778,28 +783,19 @@ sdioctl(dev, cmd, addr, flag, p)
#endif
}
/*
* Load the label information on the named device
*/
void
sdgetdisklabel(sd)
sdgetdefaultlabel(sd, lp)
struct sd_softc *sd;
struct disklabel *lp;
{
struct disklabel *lp = sd->sc_dk.dk_label;
char *errstring;
bzero(lp, sizeof(struct disklabel));
bzero(sd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
lp->d_secsize = sd->params.blksize;
lp->d_ntracks = sd->params.heads;
lp->d_nsectors = sd->params.sectors;
lp->d_ncylinders = sd->params.cyls;
lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
if (lp->d_secpercyl == 0) {
lp->d_secpercyl = 100;
/* as long as it's not 0 - readdisklabel divides by it (?) */
}
if (sd->type == T_OPTICAL)
strncpy(lp->d_typename, "SCSI optical", 16);
@ -821,6 +817,27 @@ sdgetdisklabel(sd)
lp->d_magic = DISKMAGIC;
lp->d_magic2 = DISKMAGIC;
lp->d_checksum = dkcksum(lp);
}
/*
* Load the label information on the named device
*/
void
sdgetdisklabel(sd)
struct sd_softc *sd;
{
struct disklabel *lp = sd->sc_dk.dk_label;
char *errstring;
bzero(sd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
sdgetdefaultlabel(sd, lp);
if (lp->d_secpercyl == 0) {
lp->d_secpercyl = 100;
/* as long as it's not 0 - readdisklabel divides by it (?) */
}
/*
* Call the generic disklabel extraction routine

View File

@ -1,4 +1,4 @@
/* $NetBSD: vnd.c,v 1.46 1997/08/26 18:12:58 thorpej Exp $ */
/* $NetBSD: vnd.c,v 1.47 1997/10/08 23:07:00 thorpej Exp $ */
/*-
* Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@ -172,6 +172,7 @@ void vndthrottle __P((struct vnd_softc *, struct vnode *));
void vndiodone __P((struct buf *));
void vndshutdown __P((void));
void vndgetdefaultlabel __P((struct vnd_softc *, struct disklabel *));
void vndgetdisklabel __P((dev_t));
static int vndlock __P((struct vnd_softc *));
@ -685,6 +686,7 @@ vndioctl(dev, cmd, data, flag, p)
case DIOCWDINFO:
case DIOCGPART:
case DIOCWLABEL:
case DIOCGDEFLABEL:
if ((vnd->sc_flags & VNF_INITED) == 0)
return (ENXIO);
}
@ -891,6 +893,10 @@ vndioctl(dev, cmd, data, flag, p)
vnd->sc_flags &= ~VNF_WLABEL;
break;
case DIOCGDEFLABEL:
vndgetdefaultlabel(vnd, (struct disklabel *)data);
break;
default:
return (ENOTTY);
}
@ -1034,23 +1040,15 @@ vnddump(dev, blkno, va, size)
return ENXIO;
}
/*
* Read the disklabel from a vnd. If one is not present, create a fake one.
*/
void
vndgetdisklabel(dev)
dev_t dev;
vndgetdefaultlabel(sc, lp)
struct vnd_softc *sc;
struct disklabel *lp;
{
struct vnd_softc *sc = &vnd_softc[vndunit(dev)];
char *errstring;
struct disklabel *lp = sc->sc_dkdev.dk_label;
struct cpu_disklabel *clp = sc->sc_dkdev.dk_cpulabel;
struct vndgeom *vng = &sc->sc_geom;
struct partition *pp;
int i;
bzero(lp, sizeof(*lp));
bzero(clp, sizeof(*clp));
lp->d_secperunit = sc->sc_size / (vng->vng_secsize / DEV_BSIZE);
lp->d_secsize = vng->vng_secsize;
@ -1075,6 +1073,24 @@ vndgetdisklabel(dev)
lp->d_magic = DISKMAGIC;
lp->d_magic2 = DISKMAGIC;
lp->d_checksum = dkcksum(lp);
}
/*
* Read the disklabel from a vnd. If one is not present, create a fake one.
*/
void
vndgetdisklabel(dev)
dev_t dev;
{
struct vnd_softc *sc = &vnd_softc[vndunit(dev)];
char *errstring;
struct disklabel *lp = sc->sc_dkdev.dk_label;
struct cpu_disklabel *clp = sc->sc_dkdev.dk_cpulabel;
int i;
bzero(clp, sizeof(*clp));
vndgetdefaultlabel(sc, lp);
/*
* Call the generic disklabel extraction routine.
@ -1100,6 +1116,8 @@ vndgetdisklabel(dev)
strncpy(lp->d_packname, "default label",
sizeof(lp->d_packname));
lp->d_checksum = dkcksum(lp);
}
}