Message type for CDEV_{OPEN,CLOSE}
Change-Id: Ie58511aef2da968129a405a4ad44d0330a2adcb2
This commit is contained in:
parent
0edd2b252a
commit
e7f5493031
8 changed files with 89 additions and 26 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
* Apr 02, 1992 constructed from AT wini and floppy driver (Kees J. Bot)
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <minix/drivers.h>
|
||||
#include <minix/chardriver.h>
|
||||
#include <minix/ds.h>
|
||||
|
@ -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)) {
|
||||
int 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_CDEV_RQ(m_ptr->m_type) && !is_open_dev(m_ptr->CDEV_MINOR)) {
|
||||
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(m_ptr->CDEV_MINOR);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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. */
|
||||
|
|
Loading…
Reference in a new issue