VM: munmap used by VM for itself is no longer used
[minix.git] / lib / libblockdriver / driver_st.c
blob3fb10632ec9ec6501963fef0238df65a050f1ef9
1 /* This file contains the singlethreaded device driver interface.
3 * Changes:
4 * Aug 27, 2011 extracted from driver.c (A. Welzel)
6 * The entry points into this file are:
7 * blockdriver_task: the main message loop of the driver
8 * blockdriver_terminate: break out of the main message loop
9 * blockdriver_handle_msg: handle a single received message
10 * blockdriver_receive_mq: message receive interface with message queueing
11 * blockdriver_mq_queue: queue an incoming message for later processing
14 #include <minix/drivers.h>
15 #include <minix/blockdriver.h>
17 #include "const.h"
18 #include "driver.h"
19 #include "mq.h"
21 static int running;
23 /*===========================================================================*
24 * blockdriver_receive_mq *
25 *===========================================================================*/
26 int blockdriver_receive_mq(message *m_ptr, int *status_ptr)
28 /* receive() interface for drivers with message queueing. */
30 /* Any queued messages? */
31 if (mq_dequeue(SINGLE_THREAD, m_ptr, status_ptr))
32 return OK;
34 /* Fall back to standard receive() interface otherwise. */
35 return driver_receive(ANY, m_ptr, status_ptr);
38 /*===========================================================================*
39 * blockdriver_terminate *
40 *===========================================================================*/
41 void blockdriver_terminate(void)
43 /* Break out of the main driver loop after finishing the current request. */
45 running = FALSE;
48 /*===========================================================================*
49 * blockdriver_task *
50 *===========================================================================*/
51 void blockdriver_task(struct blockdriver *bdp)
53 /* Main program of any block device driver task. */
54 int r, ipc_status;
55 message mess;
57 running = TRUE;
59 /* Here is the main loop of the disk task. It waits for a message, carries
60 * it out, and sends a reply.
62 while (running) {
63 if ((r = blockdriver_receive_mq(&mess, &ipc_status)) != OK)
64 panic("blockdriver_receive_mq failed: %d", r);
66 blockdriver_process(bdp, &mess, ipc_status);
70 /*===========================================================================*
71 * blockdriver_process *
72 *===========================================================================*/
73 void blockdriver_process(struct blockdriver *bdp, message *m_ptr,
74 int ipc_status)
76 /* Handle the given received message. */
77 int r;
79 /* Process the notification or request. */
80 if (is_ipc_notify(ipc_status)) {
81 blockdriver_handle_notify(bdp, m_ptr);
83 /* Do not reply to notifications. */
84 } else {
85 r = blockdriver_handle_request(bdp, m_ptr, SINGLE_THREAD);
87 blockdriver_reply(m_ptr, ipc_status, r);
91 /*===========================================================================*
92 * blockdriver_mq_queue *
93 *===========================================================================*/
94 int blockdriver_mq_queue(message *m, int status)
96 /* Queue a message for later processing. */
98 return mq_enqueue(SINGLE_THREAD, m, status);