--- wikisrc/users/mlelstv/disk-driver-template.mdwn 2015/12/21 10:08:45 1.3 +++ wikisrc/users/mlelstv/disk-driver-template.mdwn 2015/12/21 10:25:04 1.4 @@ -7,6 +7,16 @@ ## Declaration

+static dev_type_open(xxxopen);
+static dev_type_close(xxxclose);
+static dev_type_read(xxxread);
+static dev_type_write(xxxwrite);
+static dev_type_ioctl(xxxioctl);
+static dev_type_strategy(xxxstrategy);
+static dev_type_dump(xxxdump);
+static dev_type_size(xxxsize);
+static dev_type_discard(xxxdiscard);
+
 const struct bdevsw xxx_bdevsww= {
 	.d_open = xxxopen,
 	.d_close = xxxclose,
@@ -33,6 +43,13 @@ const struct cdevsw xxx_cdevsw = {
 	.d_flag = D_DISK
 };
 
+static void     xxxminphys(struct buf *bp);
+static int      xxxdiskstart(device_t, struct buf *bp);
+static void     xxx_iosize(device_t, int *);
+static int      xxx_dumpblocks(device_t, void *, daddr_t, int);
+static int      xxx_lastclose(device_t);
+static int      xxx_discard(device_t, off_t, off_t);
+
 static const struct dkdriver xxxdkdriver = {
 	.d_open = xxxopen,
 	.d_close = xxxclose,
@@ -45,24 +62,16 @@ static const struct dkdriver xxxdkdriver
 	.d_discard = xxx_discard
 };
 
+static int      xxx_match(device_t, cfdata_t, void *);
+static void     xxx_attach(device_t, device_t, void *);
+static int      xxx_detach(device_t, int);
+
+CFATTACH_DECL3_NEW(xxx, sizeof(struct xxx_softc),
+    xxx_match, xxx_attach, xxx_detach, NULL, NULL, NULL, DVF_DETACH_SHUTDOWN);
+    extern struct cfdriver xxx_cd;  
 extern struct   cfdriver xxx_cd;
 
-static dev_type_open(xxxopen);
-static dev_type_close(xxxclose);
-static dev_type_read(xxxread);
-static dev_type_write(xxxwrite);
-static dev_type_ioctl(xxxioctl);
-static dev_type_strategy(xxxstrategy);
-static dev_type_dump(xxxdump);
-static dev_type_size(xxxsize);
-static dev_type_discard(xxxdiscard);
-
-static void     xxxminphys(struct buf *bp);
-static int      xxxdiskstart(device_t, struct buf *bp);
-static void     xxx_iosize(device_t, int *);
-static int      xxx_dumpblocks(device_t, void *, daddr_t, int);
-static int      xxx_lastclose(device_t);
-static int      xxx_discard(device_t, off_t, off_t);
+static int      xxxdone(struct buf *);
 
 
 #define DEVPROLOG \
@@ -215,7 +224,40 @@ xxxdone(struct xxx_softc *sc, struct buf
 
 ----
 
-##  DK driver interface
+## Autoconf interface
+
+

+static int
+xxx_match(device_t self, cfdata_t cfdata, void *aux)
+{
+	return 1;
+}
+
+static void
+xxx_attach(device_t parent, device_t self, void *aux)
+{
+}
+
+static void
+xxx_detach(device_t self, int flags)
+{
+	struct xxx_softc *sc = device_private(self);
+	struct dk_softc *dksc = &sc->sc_dksc;
+
+	dkwedge_delall(&dksc->sc_dkdev);
+
+	dk_drain(dksc);
+	bufq_free(dksc->sc_bufq);
+
+	dk_detach(dksc);
+	disk_detach(&dksc->sc_dkdev);
+	disk_destroy(&dksc->sc_dkdev);
+}
+
+ +---- + +## DK driver interface

 static int