message tty_mess; /* buffer for all incoming messages */
int ipc_status;
- unsigned line;
+ int line;
int r;
register tty_t *tp;
/* 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
message tty_mess; /* buffer for all incoming messages */
int ipc_status;
- unsigned line;
+ int line;
int r;
register tty_t *tp;
/* 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;
/* 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);
/* 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 */
} 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 */
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;
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);
}
* 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>
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:
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);
return OK;
/* Call the close hook. */
- minor = m_ptr->CDEV_MINOR;
+ minor = m_ptr->m_vfs_lchardriver_openclose.minor;
return cdp->cdr_close(minor);
}
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;
+
+ /* Try to retrieve minor device number */
+ r = chardriver_get_minor(m_ptr, &minor);
- /* Mark the device as opened otherwise. */
- set_open_dev(m_ptr->CDEV_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. */
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;
+ }
+}
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. */