diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2007-06-18 20:49:20 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2007-06-18 20:49:20 +0000 |
commit | ff69e42a25f7827983c4551bf5186e40f03a6637 (patch) | |
tree | 06d4b92a284edf4d8730f6d4703eafa343dfd191 /sys/dev/ramdisk.c | |
parent | f0b7317625d2cde975b8675a357c9d963d776d54 (diff) |
Implement DIOCRLDINFO, DIOCGPDINFO and DIOCGPART. Tweak DIOCGDINFO to
avoid unnecessary rdgetdisklabel() call.
requested by & ok deraadt@
Diffstat (limited to 'sys/dev/ramdisk.c')
-rw-r--r-- | sys/dev/ramdisk.c | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/sys/dev/ramdisk.c b/sys/dev/ramdisk.c index 842966d6c02..0d9adfa801f 100644 --- a/sys/dev/ramdisk.c +++ b/sys/dev/ramdisk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ramdisk.c,v 1.34 2007/06/08 05:27:58 deraadt Exp $ */ +/* $OpenBSD: ramdisk.c,v 1.35 2007/06/18 20:49:19 krw Exp $ */ /* $NetBSD: ramdisk.c,v 1.8 1996/04/12 08:30:09 leo Exp $ */ /* @@ -99,7 +99,8 @@ struct rd_softc { void rdattach(int); void rd_attach(struct device *, struct device *, void *); -void rdgetdisklabel(dev_t, struct rd_softc *); +void rdgetdisklabel(dev_t, struct rd_softc *, struct disklabel *, + struct cpu_disklabel *, int); /* * Some ports (like i386) use a swapgeneric that wants to @@ -235,7 +236,8 @@ rdsize(dev_t dev) if (sc->sc_type == RD_UNCONFIGURED) return 0; - rdgetdisklabel(dev, sc); + rdgetdisklabel(dev, sc, sc->sc_dkdev.dk_label, sc->sc_dkdev.dk_cpulabel, + 0); part = DISKPART(dev); if (part >= sc->sc_dkdev.dk_label->d_npartitions) return 0; @@ -403,12 +405,36 @@ rdioctl(dev, cmd, data, flag, proc) urd = (struct rd_conf *)data; switch (cmd) { + case DIOCRLDINFO: + if (sc->sc_type == RD_UNCONFIGURED) { + break; + } + rdgetdisklabel(dev, sc, sc->sc_dkdev.dk_label, + sc->sc_dkdev.dk_cpulabel, 0); + return 0; + + case DIOCGPDINFO: { + struct cpu_disklabel osdep; + + if (sc->sc_type == RD_UNCONFIGURED) { + break; + } + rdgetdisklabel(dev, sc, (struct disklabel *)data, + &osdep, 1); + return 0; + } + case DIOCGDINFO: if (sc->sc_type == RD_UNCONFIGURED) { break; } - rdgetdisklabel(dev, sc); - bcopy(sc->sc_dkdev.dk_label, data, sizeof(struct disklabel)); + *(struct disklabel *)data = *(sc->sc_dkdev.dk_label); + return 0; + + case DIOCGPART: + ((struct partinfo *)data)->disklab = sc->sc_dkdev.dk_label; + ((struct partinfo *)data)->part = + &sc->sc_dkdev.dk_label->d_partitions[DISKPART(dev)]; return 0; case DIOCWDINFO: @@ -472,12 +498,11 @@ rdioctl(dev, cmd, data, flag, proc) } void -rdgetdisklabel(dev_t dev, struct rd_softc *sc) +rdgetdisklabel(dev_t dev, struct rd_softc *sc, struct disklabel *lp, + struct cpu_disklabel *clp, int spoofonly) { - struct disklabel *lp = sc->sc_dkdev.dk_label; - - bzero(sc->sc_dkdev.dk_label, sizeof(struct disklabel)); - bzero(sc->sc_dkdev.dk_cpulabel, sizeof(struct cpu_disklabel)); + bzero(lp, sizeof(struct disklabel)); + bzero(clp, sizeof(struct cpu_disklabel)); lp->d_secsize = DEV_BSIZE; lp->d_ntracks = 1; @@ -504,8 +529,7 @@ rdgetdisklabel(dev_t dev, struct rd_softc *sc) /* * Call the generic disklabel extraction routine */ - readdisklabel(DISKLABELDEV(dev), rdstrategy, sc->sc_dkdev.dk_label, - sc->sc_dkdev.dk_cpulabel, 0); + readdisklabel(DISKLABELDEV(dev), rdstrategy, lp, clp, spoofonly); } /* |