diff --git a/drivers/pty/tty.c b/drivers/pty/tty.c index 32094602f..ed4f31c9d 100644 --- a/drivers/pty/tty.c +++ b/drivers/pty/tty.c @@ -100,7 +100,7 @@ int main(void) message tty_mess; /* buffer for all incoming messages */ int ipc_status; - unsigned line; + int line; int r; register tty_t *tp; @@ -140,7 +140,9 @@ int main(void) /* Only device requests should get to this point. * All requests have a minor device number. */ - line = tty_mess.CDEV_MINOR; + if (OK != chardriver_get_minor(&tty_mess, &line)) + continue; + if (line - PTYPX_MINOR < NR_PTYS && tty_mess.m_type != CDEV_IOCTL) { /* Terminals and pseudo terminals belong together. We can only diff --git a/drivers/tty/tty.c b/drivers/tty/tty.c index 5470f6d72..51519cc46 100644 --- a/drivers/tty/tty.c +++ b/drivers/tty/tty.c @@ -149,7 +149,7 @@ int main(void) message tty_mess; /* buffer for all incoming messages */ int ipc_status; - unsigned line; + int line; int r; register tty_t *tp; @@ -222,7 +222,9 @@ int main(void) /* Only device requests should get to this point. * All requests have a minor device number. */ - line = tty_mess.CDEV_MINOR; + if (OK != chardriver_get_minor(&tty_mess, &line)) + continue; + if (line == VIDEO_MINOR) { do_video(&tty_mess, ipc_status); continue; diff --git a/include/minix/chardriver.h b/include/minix/chardriver.h index 880ab824b..48f67ae84 100644 --- a/include/minix/chardriver.h +++ b/include/minix/chardriver.h @@ -24,6 +24,7 @@ struct chardriver { /* Functions defined by libchardriver. */ void chardriver_announce(void); +int chardriver_get_minor(message *m, devminor_t *minor); void chardriver_process(struct chardriver *cdp, message *m_ptr, int ipc_status); void chardriver_terminate(void); diff --git a/include/minix/com.h b/include/minix/com.h index 24e5c9d1b..210975317 100644 --- a/include/minix/com.h +++ b/include/minix/com.h @@ -1011,7 +1011,6 @@ /* Field names for block device messages. */ #define CDEV_MINOR m10_i1 /* minor device number */ -#define CDEV_ACCESS m10_i2 /* access bits for open requests */ #define CDEV_GRANT m10_i2 /* grant ID of buffer */ #define CDEV_OPS m10_i2 /* requested select operations */ #define CDEV_COUNT m10_i3 /* number of bytes to transfer */ diff --git a/include/minix/ipc.h b/include/minix/ipc.h index 029194ecb..ed12ca229 100644 --- a/include/minix/ipc.h +++ b/include/minix/ipc.h @@ -1574,6 +1574,16 @@ typedef struct { } mess_vfs_fs_utime; _ASSERT_MSG_SIZE(mess_vfs_fs_utime); +typedef struct { + endpoint_t id; + endpoint_t user; + devminor_t minor; + int access; + + uint8_t padding[40]; +} mess_vfs_lchardriver_openclose; +_ASSERT_MSG_SIZE(mess_vfs_lchardriver_openclose); + typedef struct { int status; uint32_t id; /* should be cdev_id_t */ @@ -1861,6 +1871,8 @@ typedef struct { mess_vfs_lc_lseek m_vfs_lc_lseek; + mess_vfs_lchardriver_openclose m_vfs_lchardriver_openclose; + mess_vfs_utimens m_vfs_utimens; mess_vm_vfs_mmap m_vm_vfs_mmap; mess_vmmcp m_vmmcp; diff --git a/lib/libblockdriver/driver.c b/lib/libblockdriver/driver.c index 42bca46aa..55e716f49 100644 --- a/lib/libblockdriver/driver.c +++ b/lib/libblockdriver/driver.c @@ -370,7 +370,7 @@ static void do_char_open(message *m_ptr, int ipc_status) m_reply.m_type = CDEV_REPLY; m_reply.m_lchardriver_vfs_reply.status = ENXIO; - m_reply.m_lchardriver_vfs_reply.id = m_ptr->CDEV_ID; + m_reply.m_lchardriver_vfs_reply.id = m_ptr->m_vfs_lchardriver_openclose.id; send_reply(m_ptr->m_source, &m_reply, ipc_status); } diff --git a/lib/libchardriver/chardriver.c b/lib/libchardriver/chardriver.c index 6b9361c3d..ab7f604f0 100644 --- a/lib/libchardriver/chardriver.c +++ b/lib/libchardriver/chardriver.c @@ -43,6 +43,8 @@ * Apr 02, 1992 constructed from AT wini and floppy driver (Kees J. Bot) */ +#include + #include #include #include @@ -235,6 +237,12 @@ static void chardriver_reply(message *mess, int ipc_status, int r) switch (mess->m_type) { case CDEV_OPEN: case CDEV_CLOSE: + reply_mess.m_type = CDEV_REPLY; + reply_mess.m_lchardriver_vfs_reply.status = r; + reply_mess.m_lchardriver_vfs_reply.id = + mess->m_vfs_lchardriver_openclose.id; + break; + case CDEV_READ: case CDEV_WRITE: case CDEV_IOCTL: @@ -272,9 +280,9 @@ static int do_open(struct chardriver *cdp, message *m_ptr) return OK; /* Call the open hook. */ - minor = m_ptr->CDEV_MINOR; - access = m_ptr->CDEV_ACCESS; - user_endpt = m_ptr->CDEV_USER; + minor = m_ptr->m_vfs_lchardriver_openclose.minor; + access = m_ptr->m_vfs_lchardriver_openclose.access; + user_endpt = m_ptr->m_vfs_lchardriver_openclose.user; r = cdp->cdr_open(minor, access, user_endpt); @@ -301,7 +309,7 @@ static int do_close(struct chardriver *cdp, message *m_ptr) return OK; /* Call the close hook. */ - minor = m_ptr->CDEV_MINOR; + minor = m_ptr->m_vfs_lchardriver_openclose.minor; return cdp->cdr_close(minor); } @@ -473,16 +481,26 @@ void chardriver_process(struct chardriver *cdp, message *m_ptr, int ipc_status) return; } - /* We might get spurious requests if the driver has been restarted. Deny any - * requests on devices that have not previously been opened. - */ - if (IS_CDEV_RQ(m_ptr->m_type) && !is_open_dev(m_ptr->CDEV_MINOR)) { - /* Ignore spurious requests for unopened devices. */ - if (m_ptr->m_type != CDEV_OPEN) - return; /* do not send a reply */ + if (IS_CDEV_RQ(m_ptr->m_type)) { + int minor; - /* Mark the device as opened otherwise. */ - set_open_dev(m_ptr->CDEV_MINOR); + /* Try to retrieve minor device number */ + r = chardriver_get_minor(m_ptr, &minor); + + if (OK != r) + return; + + /* We might get spurious requests if the driver has been restarted. + * Deny any requests on devices that have not previously been opened. + */ + if (!is_open_dev(minor)) { + /* Ignore spurious requests for unopened devices. */ + if (m_ptr->m_type != CDEV_OPEN) + return; /* do not send a reply */ + + /* Mark the device as opened otherwise. */ + set_open_dev(minor); + } } /* Call the appropriate function(s) for this request. */ @@ -540,3 +558,29 @@ void chardriver_task(struct chardriver *cdp) chardriver_process(cdp, &mess, ipc_status); } } + +/*===========================================================================* + * chardriver_get_minor * + *===========================================================================*/ +int chardriver_get_minor(message *m, devminor_t *minor) +{ + assert(NULL != m); + assert(NULL != minor); + + switch(m->m_type) + { + case CDEV_OPEN: + case CDEV_CLOSE: + *minor = m->m_vfs_lchardriver_openclose.minor; + return OK; + case CDEV_READ: + case CDEV_WRITE: + case CDEV_IOCTL: + case CDEV_CANCEL: + case CDEV_SELECT: + *minor = m->CDEV_MINOR; + return OK; + default: + return EINVAL; + } +} diff --git a/servers/vfs/device.c b/servers/vfs/device.c index 99118d48e..3803eab5f 100644 --- a/servers/vfs/device.c +++ b/servers/vfs/device.c @@ -403,14 +403,17 @@ static int cdev_opcl( memset(&dev_mess, 0, sizeof(dev_mess)); dev_mess.m_type = op; - dev_mess.CDEV_MINOR = minor_dev; - dev_mess.CDEV_ID = who_e; + dev_mess.m_vfs_lchardriver_openclose.minor = minor_dev; + dev_mess.m_vfs_lchardriver_openclose.id = who_e; if (op == CDEV_OPEN) { - dev_mess.CDEV_USER = who_e; - dev_mess.CDEV_ACCESS = 0; - if (flags & R_BIT) dev_mess.CDEV_ACCESS |= CDEV_R_BIT; - if (flags & W_BIT) dev_mess.CDEV_ACCESS |= CDEV_W_BIT; - if (flags & O_NOCTTY) dev_mess.CDEV_ACCESS |= CDEV_NOCTTY; + dev_mess.m_vfs_lchardriver_openclose.user = who_e; + dev_mess.m_vfs_lchardriver_openclose.access = 0; + if (flags & R_BIT) + dev_mess.m_vfs_lchardriver_openclose.access |= CDEV_R_BIT; + if (flags & W_BIT) + dev_mess.m_vfs_lchardriver_openclose.access |= CDEV_W_BIT; + if (flags & O_NOCTTY) + dev_mess.m_vfs_lchardriver_openclose.access |= CDEV_NOCTTY; } /* Send the request to the driver. */