detach(9E) エントリポイントは、 attach(9E) の逆の操作を行うものです。detach() では、attach() で割り当てられたすべてのリソースを解放する必要があります。成功した場合、detach はscsi_unprobe (9F) を呼び出す必要があります。次の例では、ターゲットドライバの detach() ルーチンを示します。
使用例 17-3 SCSI ターゲットドライバの detach (9E) ルーチンstatic int xxdetach(dev_info_t *dip, ddi_detach_cmd_t cmd) { struct xxstate *xsp; switch (cmd) { case DDI_DETACH: /* * Normal detach(9E) operations, such as getting a * pointer to the state structure */ scsi_free_consistent_buf(xsp->rqsbuf); scsi_destroy_pkt(xsp->rqs); xsp->sdp->sd_private = (caddr_t)NULL; xsp->sdp->sd_sense = NULL; scsi_unprobe(xsp->sdp); /* * Remove minor nodes. * Free resources, such as the state structure and properties. */ return (DDI_SUCCESS); case DDI_SUSPEND: /* For information, see the "Directory Memory Access (DMA)" */ /* chapter in this book. */ default: return (DDI_FAILURE); } }