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.
This commit is contained in:
David van Moolenbroek 2011-11-25 14:56:46 +01:00
parent a03f679e88
commit e2758c6759
7 changed files with 62 additions and 27 deletions

View file

@ -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,

View file

@ -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,

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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);