-/* $OpenBSD: ramdisk.c,v 1.43 2008/07/12 19:58:48 miod Exp $ */
+/* $OpenBSD: ramdisk.c,v 1.44 2008/08/22 03:12:37 deraadt Exp $ */
/* $NetBSD: ramdisk.c,v 1.8 1996/04/12 08:30:09 leo Exp $ */
/*
struct rd_softc {
struct device sc_dev; /* REQUIRED first entry */
- struct disk sc_dkdev; /* hook for generic disk handling */
+ struct disk sc_dk; /* hook for generic disk handling */
struct rd_conf sc_rd;
#if RAMDISK_SERVER
struct buf *sc_buflist;
* This is called if we are configured as a pseudo-device
*/
void
-rdattach(n)
- int n;
+rdattach(int n)
{
struct rd_softc *sc;
struct cfdata *cf;
#endif
/* XXX: Are we supposed to provide a default? */
- if (n <= 1)
+ if (n < 1)
n = 1;
if (n > RD_MAX_UNITS)
n = RD_MAX_UNITS;
}
void
-rd_attach(parent, self, aux)
- struct device *parent, *self;
- void *aux;
+rd_attach(struct device *parent, struct device *self, void *aux)
{
struct rd_softc *sc = (struct rd_softc *)self;
/*
* Initialize and attach the disk structure.
*/
- sc->sc_dkdev.dk_driver = &rddkdriver;
- sc->sc_dkdev.dk_name = sc->sc_dev.dv_xname;
- disk_attach(&sc->sc_dkdev);
+ sc->sc_dk.dk_driver = &rddkdriver;
+ sc->sc_dk.dk_name = sc->sc_dev.dv_xname;
+ disk_attach(&sc->sc_dk);
}
/*
dev_type_dump(rddump);
int
-rddump(dev, blkno, va, size)
- dev_t dev;
- daddr64_t blkno;
- caddr_t va;
- size_t size;
+rddump(dev_t dev, daddr64_t blkno, caddr_t va, size_t size)
{
- return ENODEV;
+ return (ENODEV);
}
daddr64_t
/* Disallow control units. */
unit = DISKUNIT(dev);
if (unit >= ramdisk_ndevs)
- return 0;
+ return (0);
sc = ramdisk_devs[unit];
if (sc == NULL)
- return 0;
+ return (0);
if (sc->sc_type == RD_UNCONFIGURED)
- return 0;
+ return (0);
- rdgetdisklabel(dev, sc, sc->sc_dkdev.dk_label, 0);
+ rdgetdisklabel(dev, sc, sc->sc_dk.dk_label, 0);
part = DISKPART(dev);
- if (part >= sc->sc_dkdev.dk_label->d_npartitions)
- return 0;
- else
- return DL_GETPSIZE(&sc->sc_dkdev.dk_label->d_partitions[part]) *
- (sc->sc_dkdev.dk_label->d_secsize / DEV_BSIZE);
+ if (part >= sc->sc_dk.dk_label->d_npartitions)
+ return (0);
+ return (DL_GETPSIZE(&sc->sc_dk.dk_label->d_partitions[part]) *
+ (sc->sc_dk.dk_label->d_secsize / DEV_BSIZE));
}
int
-rdopen(dev, flag, fmt, proc)
- dev_t dev;
- int flag, fmt;
- struct proc *proc;
+rdopen(dev_t dev, int flag, int fmt, struct proc *proc)
{
int unit;
struct rd_softc *sc;
unit = DISKUNIT(dev);
if (unit >= ramdisk_ndevs)
- return ENXIO;
+ return (ENXIO);
sc = ramdisk_devs[unit];
if (sc == NULL)
- return ENXIO;
+ return (ENXIO);
/*
* The control device is not exclusive, and can
* open uninitialized units (so you can setconf).
*/
if (RD_IS_CTRL(dev))
- return 0;
+ return (0);
#ifdef RAMDISK_HOOKS
/* Call the open hook to allow loading the device. */
* enforce initialized, exclusive open.
*/
if (sc->sc_type == RD_UNCONFIGURED)
- return ENXIO;
+ return (ENXIO);
/*
* Make sure we have read the disklabel.
*/
- rdgetdisklabel(dev, sc, sc->sc_dkdev.dk_label, 0);
-
- return 0;
+ rdgetdisklabel(dev, sc, sc->sc_dk.dk_label, 0);
+ return (0);
}
int
-rdclose(dev, flag, fmt, proc)
- dev_t dev;
- int flag, fmt;
- struct proc *proc;
+rdclose(dev_t dev, int flag, int fmt, struct proc *proc)
{
-
- return 0;
+ return (0);
}
int
-rdread(dev, uio, flags)
- dev_t dev;
- struct uio *uio;
- int flags;
+rdread(dev_t dev, struct uio *uio, int flags)
{
return (physio(rdstrategy, NULL, dev, B_READ, minphys, uio));
}
int
-rdwrite(dev, uio, flags)
- dev_t dev;
- struct uio *uio;
- int flags;
+rdwrite(dev_t dev, struct uio *uio, int flags)
{
return (physio(rdstrategy, NULL, dev, B_WRITE, minphys, uio));
}
* by passing them to the server process.
*/
void
-rdstrategy(bp)
- struct buf *bp;
+rdstrategy(struct buf *bp)
{
- int unit;
+ int unit, s;
struct rd_softc *sc;
caddr_t addr;
size_t off, xfer;
- int s;
unit = DISKUNIT(bp->b_dev);
sc = ramdisk_devs[unit];
/* Sort rogue requests out */
if (sc == NULL || bp->b_blkno < 0 ||
- (bp->b_bcount % sc->sc_dkdev.dk_label->d_secsize) != 0) {
+ (bp->b_bcount % sc->sc_dk.dk_label->d_secsize) != 0) {
bp->b_error = EINVAL;
goto bad;
}
/* Do not write on "no trespassing" areas... */
- if (bounds_check_with_label(bp, sc->sc_dkdev.dk_label, 1) <= 0)
+ if (bounds_check_with_label(bp, sc->sc_dk.dk_label, 1) <= 0)
goto bad;
switch (sc->sc_type) {
}
int
-rdioctl(dev, cmd, data, flag, proc)
- dev_t dev;
- u_long cmd;
- int flag;
- caddr_t data;
- struct proc *proc;
+rdioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *proc)
{
- int unit;
struct disklabel *lp;
struct rd_softc *sc;
struct rd_conf *urd;
- int error;
+ int unit = DISKUNIT(dev), error;
- unit = DISKUNIT(dev);
sc = ramdisk_devs[unit];
urd = (struct rd_conf *)data;
break;
lp = malloc(sizeof(*lp), M_TEMP, M_WAITOK);
rdgetdisklabel(dev, sc, lp, 0);
- bcopy(lp, sc->sc_dkdev.dk_label, sizeof(*lp));
+ bcopy(lp, sc->sc_dk.dk_label, sizeof(*lp));
free(lp, M_TEMP);
- return 0;
+ return (0);
case DIOCGPDINFO:
if (sc->sc_type == RD_UNCONFIGURED)
break;
rdgetdisklabel(dev, sc, (struct disklabel *)data, 1);
- return 0;
+ return (0);
case DIOCGDINFO:
- if (sc->sc_type == RD_UNCONFIGURED) {
+ if (sc->sc_type == RD_UNCONFIGURED)
break;
- }
- *(struct disklabel *)data = *(sc->sc_dkdev.dk_label);
- return 0;
+ *(struct disklabel *)data = *(sc->sc_dk.dk_label);
+ return (0);
case DIOCGPART:
- ((struct partinfo *)data)->disklab = sc->sc_dkdev.dk_label;
+ ((struct partinfo *)data)->disklab = sc->sc_dk.dk_label;
((struct partinfo *)data)->part =
- &sc->sc_dkdev.dk_label->d_partitions[DISKPART(dev)];
- return 0;
+ &sc->sc_dk.dk_label->d_partitions[DISKPART(dev)];
+ return (0);
case DIOCWDINFO:
case DIOCSDINFO:
- if (sc->sc_type == RD_UNCONFIGURED) {
+ if (sc->sc_type == RD_UNCONFIGURED)
break;
- }
if ((flag & FWRITE) == 0)
- return EBADF;
+ return (EBADF);
- error = setdisklabel(sc->sc_dkdev.dk_label,
+ error = setdisklabel(sc->sc_dk.dk_label,
(struct disklabel *)data, /*sd->sc_dk.dk_openmask : */0);
if (error == 0) {
if (cmd == DIOCWDINFO)
error = writedisklabel(DISKLABELDEV(dev),
- rdstrategy, sc->sc_dkdev.dk_label);
+ rdstrategy, sc->sc_dk.dk_label);
}
-
- return error;
+ return (error);
case DIOCWLABEL:
- if (sc->sc_type == RD_UNCONFIGURED) {
+ if (sc->sc_type == RD_UNCONFIGURED)
break;
- }
if ((flag & FWRITE) == 0)
- return EBADF;
- return 0;
+ return (EBADF);
+ return (0);
case RD_GETCONF:
/* If this is not the control device, punt! */
- if (RD_IS_CTRL(dev) == 0) {
+ if (RD_IS_CTRL(dev) == 0)
break;
- }
*urd = sc->sc_rd;
- return 0;
+ return (0);
case RD_SETCONF:
/* If this is not the control device, punt! */
- if (RD_IS_CTRL(dev) == 0) {
+ if (RD_IS_CTRL(dev) == 0)
break;
- }
/* Can only set it once. */
- if (sc->sc_type != RD_UNCONFIGURED) {
+ if (sc->sc_type != RD_UNCONFIGURED)
break;
- }
switch (urd->rd_type) {
case RD_KMEM_ALLOCATED:
- return rd_ioctl_kalloc(sc, urd, proc);
+ return (rd_ioctl_kalloc(sc, urd, proc));
#if RAMDISK_SERVER
case RD_UMEM_SERVER:
- return rd_ioctl_server(sc, urd, proc);
+ return (rd_ioctl_server(sc, urd, proc));
#endif
default:
break;
break;
default:
- return ENOTTY;
+ return (ENOTTY);
}
- return EINVAL;
+ return (EINVAL);
}
void
* Just allocate some kernel memory and return.
*/
int
-rd_ioctl_kalloc(sc, urd, proc)
- struct rd_softc *sc;
- struct rd_conf *urd;
- struct proc *proc;
+rd_ioctl_kalloc(struct rd_softc *sc, struct rd_conf *urd, struct proc *proc)
{
vaddr_t addr;
vsize_t size;
size = urd->rd_size;
addr = uvm_km_zalloc(kernel_map, size);
if (!addr)
- return ENOMEM;
+ return (ENOMEM);
/* This unit is now configured. */
sc->sc_addr = (caddr_t)addr; /* kernel space */
sc->sc_size = (size_t)size;
sc->sc_type = RD_KMEM_ALLOCATED;
- return 0;
+ return (0);
}
int
rd_probe(struct device *parent, void *match_, void *aux)
{
- return 0;
+ return (0);
}
int
rd_detach(struct device *self, int flags)
{
- return 0;
+ return (0);
}
int
rd_activate(struct device *self, enum devact act)
{
- return 0;
+ return (0);
}
#if RAMDISK_SERVER
* Set config, then become the I/O server for this unit.
*/
int
-rd_ioctl_server(sc, urd, proc)
- struct rd_softc *sc;
- struct rd_conf *urd;
- struct proc *proc;
+rd_ioctl_server(struct rd_softc *sc, struct rd_conf *urd, struct proc *proc)
{
vaddr_t end;
int error;
end = (vaddr_t) (urd->rd_addr + urd->rd_size);
if ((end >= VM_MAXUSER_ADDRESS) || (end < ((vaddr_t) urd->rd_addr)) )
- return EINVAL;
+ return (EINVAL);
/* This unit is now configured. */
sc->sc_addr = urd->rd_addr; /* user space */
sc->sc_type = RD_UNCONFIGURED;
sc->sc_addr = 0;
sc->sc_size = 0;
-
return (error);
}
int rd_sleep_pri = PWAIT | PCATCH;
int
-rd_server_loop(sc)
- struct rd_softc *sc;
+rd_server_loop(struct rd_softc *sc)
{
struct buf *bp;
caddr_t addr; /* user space address */
size_t off; /* offset into "device" */
size_t xfer; /* amount to transfer */
- int error;
- int s;
+ int error, s;
for (;;) {
/* Wait for some work to arrive. */
while (sc->sc_buflist == NULL) {
error = tsleep((caddr_t)sc, rd_sleep_pri, "rd_idle", 0);
if (error)
- return error;
+ return (error);
}
/* Unlink buf from head of list. */