From: David van Moolenbroek Date: Fri, 25 Nov 2011 13:56:46 +0000 (+0100) Subject: libblockdriver: allow for not handling partitions X-Git-Tag: v3.2.0~212 X-Git-Url: http://zhaoyanbai.com/repos/icons/debian/static/ChangeLog.txt?a=commitdiff_plain;h=e2758c67594ddd516692c2d0111a3400bf9ab8d8;p=minix.git libblockdriver: allow for not handling partitions Each block driver now gets to specify whether it is a disk block driver, which implies it wants the library to handle getting and setting partitions for it. --- diff --git a/common/include/minix/blockdriver.h b/common/include/minix/blockdriver.h index efd5261a5..ef0f00809 100644 --- a/common/include/minix/blockdriver.h +++ b/common/include/minix/blockdriver.h @@ -5,8 +5,15 @@ typedef int thread_id_t; +/* Types supported for the 'type' field of struct blockdriver. */ +typedef enum { + BLOCKDRIVER_TYPE_DISK, /* handle partition requests */ + BLOCKDRIVER_TYPE_OTHER /* do not handle partition requests */ +} blockdriver_type_t; + /* Entry points into the device dependent code of block drivers. */ struct blockdriver { + blockdriver_type_t bdr_type; _PROTOTYPE( int (*bdr_open), (dev_t minor, int access) ); _PROTOTYPE( int (*bdr_close), (dev_t minor) ); _PROTOTYPE( ssize_t (*bdr_transfer), (dev_t minor, int do_write, u64_t pos, diff --git a/drivers/ahci/ahci.c b/drivers/ahci/ahci.c index 2cc2d2310..4b5833b75 100644 --- a/drivers/ahci/ahci.c +++ b/drivers/ahci/ahci.c @@ -208,6 +208,7 @@ PRIVATE struct port_state *ahci_get_port(dev_t minor); /* AHCI driver table. */ PRIVATE struct blockdriver ahci_dtab = { + BLOCKDRIVER_TYPE_DISK, ahci_open, ahci_close, ahci_transfer, diff --git a/drivers/at_wini/at_wini.c b/drivers/at_wini/at_wini.c index 400e801c6..c0293e6be 100644 --- a/drivers/at_wini/at_wini.c +++ b/drivers/at_wini/at_wini.c @@ -200,6 +200,7 @@ FORWARD _PROTOTYPE( int at_in, (int line, u32_t port, unsigned long *value, /* Entry points to this driver. */ PRIVATE struct blockdriver w_dtab = { + BLOCKDRIVER_TYPE_DISK,/* handle partition requests */ w_do_open, /* open or mount request, initialize device */ w_do_close, /* release device */ w_transfer, /* do the I/O */ diff --git a/drivers/bios_wini/bios_wini.c b/drivers/bios_wini/bios_wini.c index a9375e0a8..547431196 100644 --- a/drivers/bios_wini/bios_wini.c +++ b/drivers/bios_wini/bios_wini.c @@ -70,6 +70,7 @@ FORWARD _PROTOTYPE( int w_ioctl, (dev_t minor, unsigned int request, /* Entry points to this driver. */ PRIVATE struct blockdriver w_dtab = { + BLOCKDRIVER_TYPE_DISK, /* handle partition requests */ w_do_open, /* open or mount request, initialize device */ w_do_close, /* release device */ w_transfer, /* do the I/O */ diff --git a/drivers/floppy/floppy.c b/drivers/floppy/floppy.c index 8bf2ba2b6..4347dab07 100644 --- a/drivers/floppy/floppy.c +++ b/drivers/floppy/floppy.c @@ -267,6 +267,7 @@ FORWARD _PROTOTYPE( void f_geometry, (dev_t minor, /* Entry points to this driver. */ PRIVATE struct blockdriver f_dtab = { + BLOCKDRIVER_TYPE_DISK, /* handle partition requests */ f_do_open, /* open or mount request, sense type of diskette */ f_do_close, /* nothing on a close */ f_transfer, /* do the I/O */ diff --git a/drivers/memory/memory.c b/drivers/memory/memory.c index f6c39beed..e1433f15e 100644 --- a/drivers/memory/memory.c +++ b/drivers/memory/memory.c @@ -76,6 +76,7 @@ PRIVATE struct chardriver m_cdtab = { /* Entry points to the BLOCK part of this driver. */ PRIVATE struct blockdriver m_bdtab = { + BLOCKDRIVER_TYPE_DISK,/* handle partition requests */ m_block_open, /* open or mount */ m_block_close, /* nothing on a close */ m_block_transfer, /* do the I/O */ diff --git a/lib/libblockdriver/driver.c b/lib/libblockdriver/driver.c index e7940cc42..2f8aed7a2 100644 --- a/lib/libblockdriver/driver.c +++ b/lib/libblockdriver/driver.c @@ -248,39 +248,20 @@ PRIVATE int do_vrdwt(struct blockdriver *bdp, message *mp, thread_id_t id) } /*===========================================================================* - * do_ioctl * + * do_dioctl * *===========================================================================*/ -PRIVATE int do_ioctl(struct blockdriver *bdp, message *mp) +PRIVATE int do_dioctl(struct blockdriver *bdp, dev_t minor, + unsigned int request, endpoint_t endpt, cp_grant_id_t grant) { -/* Carry out an I/O control request. For now, we handle setting/getting - * partitions here, forward block trace control requests to the tracing module, - * and let the driver handle any other requests. In the future, a stricter - * separation between block and disk I/O controls may become desirable, but we - * do not have any non-"disk" block drivers at this time. - */ +/* Carry out a disk-specific I/O control request. */ struct device *dv; struct partition entry; - unsigned int request; - cp_grant_id_t grant; - dev_t minor; - int r; - - minor = mp->BDEV_MINOR; - request = mp->BDEV_REQUEST; - grant = mp->BDEV_GRANT; + int r = EINVAL; switch (request) { - case BIOCTRACEBUF: - case BIOCTRACECTL: - case BIOCTRACEGET: - /* Block trace control. */ - r = trace_ctl(minor, request, mp->m_source, grant); - - break; - case DIOCSETP: /* Copy just this one partition table entry. */ - r = sys_safecopyfrom(mp->m_source, grant, 0, (vir_bytes) &entry, + r = sys_safecopyfrom(endpt, grant, 0, (vir_bytes) &entry, sizeof(entry), D); if (r != OK) return r; @@ -307,11 +288,53 @@ PRIVATE int do_ioctl(struct blockdriver *bdp, message *mp) entry.sectors = 32; } - r = sys_safecopyto(mp->m_source, grant, 0, (vir_bytes) &entry, - sizeof(entry), D); + r = sys_safecopyto(endpt, grant, 0, (vir_bytes) &entry, sizeof(entry), + D); break; + } + + return r; +} + +/*===========================================================================* + * do_ioctl * + *===========================================================================*/ +PRIVATE int do_ioctl(struct blockdriver *bdp, message *mp) +{ +/* Carry out an I/O control request. We forward block trace control requests + * to the tracing module, and handle setting/getting partitions when the driver + * has specified that it is a disk driver. + */ + dev_t minor; + unsigned int request; + cp_grant_id_t grant; + int r; + + minor = mp->BDEV_MINOR; + request = mp->BDEV_REQUEST; + grant = mp->BDEV_GRANT; + + switch (request) { + case BIOCTRACEBUF: + case BIOCTRACECTL: + case BIOCTRACEGET: + /* Block trace control. */ + r = trace_ctl(minor, request, mp->m_source, grant); + + break; + + case DIOCSETP: + case DIOCGETP: + /* Handle disk-specific IOCTLs only for disk-type drivers. */ + if (bdp->bdr_type == BLOCKDRIVER_TYPE_DISK) { + /* Disk partition control. */ + r = do_dioctl(bdp, minor, request, mp->m_source, grant); + + break; + } + /* fall-through */ default: if (bdp->bdr_ioctl) r = (*bdp->bdr_ioctl)(minor, request, mp->m_source, grant);