Bite the bullet and allocate the devsw entry at compile time.

This commit is contained in:
Poul-Henning Kamp 1999-09-12 20:40:29 +00:00
parent 03a7efc234
commit 2016e4e906
4 changed files with 22 additions and 29 deletions

View File

@ -78,6 +78,7 @@ static struct cdevsw fla_cdevsw = {
/* maxio */ 0,
/* bmaj */ BDEV_MAJOR
};
static struct cdevsw fladisk_cdevsw;
void *
doc2k_malloc(int bytes)
@ -339,7 +340,7 @@ flaattach (device_t dev)
DEVSTAT_NO_ORDERED_TAGS,
DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER, 0x190);
sc->dev = disk_create(unit, &sc->disk, 0, &fla_cdevsw);
sc->dev = disk_create(unit, &sc->disk, 0, &fla_cdevsw, &fladisk_cdevsw);
sc->dev->si_drv1 = sc;
sc->unit = unit;

View File

@ -79,7 +79,9 @@ static struct cdevsw ad_cdevsw = {
/* maxio */ 0,
/* bmaj */ 30,
};
static struct cdevsw addisk_cdevsw;
static struct cdevsw fakewd_cdevsw;
static struct cdevsw fakewddisk_cdevsw;
/* misc defines */
#define UNIT(dev) (minor(dev)>>3 & 0x1f) /* assume 8 minor # per unit */
@ -228,9 +230,9 @@ ad_attach(void *notused)
DEVSTAT_NO_ORDERED_TAGS,
DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_IDE,
0x180);
dev1 = disk_create(adp->lun, &adp->disk, 0, &ad_cdevsw);
dev1 = disk_create(adp->lun, &adp->disk, 0, &ad_cdevsw, &addisk_cdevsw);
dev1->si_drv1 = adp;
dev1 = disk_create(adp->lun, &adp->disk, 0, &fakewd_cdevsw);
dev1 = disk_create(adp->lun, &adp->disk, 0, &fakewd_cdevsw, &fakewddisk_cdevsw);
dev1->si_drv1 = adp;
bufq_init(&adp->queue);

View File

@ -30,28 +30,21 @@ static d_ioctl_t diskioctl;
static d_psize_t diskpsize;
dev_t
disk_create(int unit, struct disk *dp, int flags, struct cdevsw *cdevsw)
disk_create(int unit, struct disk *dp, int flags, struct cdevsw *cdevsw, struct cdevsw *proto)
{
dev_t dev;
struct cdevsw *cds;
MALLOC(cds, struct cdevsw *, sizeof(*cds), M_DISK, M_WAITOK);
bzero(dp, sizeof(*dp));
dev = makedev(cdevsw->d_maj, 0);
if (!devsw(dev)) {
dp->d_open = cdevsw->d_open;
cdevsw->d_open = diskopen;
dp->d_close = cdevsw->d_close;
cdevsw->d_close = diskclose;
dp->d_ioctl = cdevsw->d_ioctl;
cdevsw->d_ioctl = diskioctl;
dp->d_strategy = cdevsw->d_strategy;
cdevsw->d_strategy = diskstrategy;
dp->d_psize = cdevsw->d_psize;
cdevsw->d_psize = diskpsize;
cdevsw_add(cdevsw);
*proto = *cdevsw;
proto->d_open = diskopen;
proto->d_close = diskclose;
proto->d_ioctl = diskioctl;
proto->d_strategy = diskstrategy;
proto->d_psize = diskpsize;
cdevsw_add(proto);
}
printf("Creating DISK %s%d\n", cdevsw->d_name, unit);
@ -61,6 +54,7 @@ disk_create(int unit, struct disk *dp, int flags, struct cdevsw *cdevsw)
dev->si_disk = dp;
dp->d_dev = dev;
dp->d_flags = flags;
dp->d_devsw = cdevsw;
return (dev);
}
@ -126,7 +120,7 @@ diskopen(dev_t dev, int oflags, int devtype, struct proc *p)
dev->si_drv2 = pdev->si_drv2;
if (!dsisopen(dp->d_slice))
error = dp->d_open(dev, oflags, devtype, p);
error = dp->d_devsw->d_open(dev, oflags, devtype, p);
if (error)
return(error);
@ -134,7 +128,7 @@ diskopen(dev_t dev, int oflags, int devtype, struct proc *p)
error = dsopen(dev, devtype, dp->d_flags, &dp->d_slice, &dp->d_label);
if (!dsisopen(dp->d_slice))
dp->d_close(dev, oflags, devtype, p);
dp->d_devsw->d_close(dev, oflags, devtype, p);
return(error);
}
@ -149,7 +143,7 @@ diskclose(dev_t dev, int fflag, int devtype, struct proc *p)
dp = dev->si_disk;
dsclose(dev, devtype, dp->d_slice);
if (dsisopen(dp->d_slice))
error = dp->d_close(dev, fflag, devtype, p);
error = dp->d_devsw->d_close(dev, fflag, devtype, p);
return (error);
}
@ -182,7 +176,7 @@ diskstrategy(struct buf *bp)
return;
}
dp->d_strategy(bp);
dp->d_devsw->d_strategy(bp);
return;
}
@ -196,7 +190,7 @@ diskioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct proc *p)
dp = dev->si_disk;
error = dsioctl(dev, cmd, data, fflag, &dp->d_slice);
if (error == ENOIOCTL)
error = dp->d_ioctl(dev, cmd, data, fflag, p);
error = dp->d_devsw->d_ioctl(dev, cmd, data, fflag, p);
return (error);
}

View File

@ -23,17 +23,13 @@
struct disk {
int d_flags;
d_open_t *d_open;
d_close_t *d_close;
d_ioctl_t *d_ioctl;
d_strategy_t *d_strategy;
d_psize_t *d_psize;
struct cdevsw *d_devsw;
dev_t d_dev;
struct diskslices *d_slice;
struct disklabel d_label;
};
dev_t disk_create __P((int unit, struct disk *disk, int flags, struct cdevsw *cdevsw));
dev_t disk_create __P((int unit, struct disk *disk, int flags, struct cdevsw *cdevsw, struct cdevsw *diskdevsw));
void disk_delete __P((dev_t dev));
int disk_dumpcheck __P((dev_t dev, u_int *count, u_int *blkno, u_int *secsize));
void disk_invalidate __P((struct disk *disk));