mkfs, mkproto: minor improvements
[minix.git] / drivers / log / liveupdate.c
blobe1d114ab703c7a5f2c0955dfb0934edd92b8e395
1 #include "log.h"
3 /* State management variables. */
4 #define NR_DEVS 1 /* number of minor devices */
5 EXTERN struct logdevice logdevices[NR_DEVS];
7 /* State management helpers. */
8 static int is_read_pending;
9 static int is_select_callback_pending;
10 static void load_state_info(void)
12 int i, found_pending;
13 struct logdevice *log;
15 /* Check if reads or select callbacks are pending. */
16 is_read_pending = FALSE;
17 is_select_callback_pending = FALSE;
18 found_pending = FALSE;
19 for (i = 0; i < NR_DEVS && !found_pending; i++) {
20 log = &logdevices[i];
21 if(log->log_source != NONE) {
22 is_read_pending = TRUE;
24 if(log->log_selected) {
25 is_select_callback_pending = TRUE;
28 found_pending = (is_read_pending && is_select_callback_pending);
32 /* Custom states definition. */
33 #define LOG_STATE_SELECT_PROTOCOL_FREE (SEF_LU_STATE_CUSTOM_BASE + 0)
34 #define LOG_STATE_IS_CUSTOM(s) ((s) == LOG_STATE_SELECT_PROTOCOL_FREE)
36 /*===========================================================================*
37 * sef_cb_lu_prepare *
38 *===========================================================================*/
39 int sef_cb_lu_prepare(int state)
41 int is_ready;
43 /* Load state information. */
44 load_state_info();
46 /* Check if we are ready for the target state. */
47 is_ready = FALSE;
48 switch(state) {
49 /* Standard states. */
50 case SEF_LU_STATE_REQUEST_FREE:
51 is_ready = (!is_read_pending);
52 break;
54 case SEF_LU_STATE_PROTOCOL_FREE:
55 is_ready = (!is_read_pending && !is_select_callback_pending);
56 break;
58 /* Custom states. */
59 case LOG_STATE_SELECT_PROTOCOL_FREE:
60 is_ready = (!is_select_callback_pending);
61 break;
64 /* Tell SEF if we are ready. */
65 return is_ready ? OK : ENOTREADY;
68 /*===========================================================================*
69 * sef_cb_lu_state_isvalid *
70 *===========================================================================*/
71 int sef_cb_lu_state_isvalid(int state)
73 return SEF_LU_STATE_IS_STANDARD(state) || LOG_STATE_IS_CUSTOM(state);
76 /*===========================================================================*
77 * sef_cb_lu_state_dump *
78 *===========================================================================*/
79 void sef_cb_lu_state_dump(int state)
81 /* Load state information. */
82 load_state_info();
84 sef_lu_dprint("log: live update state = %d\n", state);
85 sef_lu_dprint("log: is_read_pending = %d\n", is_read_pending);
86 sef_lu_dprint("log: is_select_callback_pending = %d\n",
87 is_select_callback_pending);
89 sef_lu_dprint("log: SEF_LU_STATE_WORK_FREE(%d) reached = %d\n",
90 SEF_LU_STATE_WORK_FREE, TRUE);
91 sef_lu_dprint("log: SEF_LU_STATE_REQUEST_FREE(%d) reached = %d\n",
92 SEF_LU_STATE_REQUEST_FREE, (!is_read_pending));
93 sef_lu_dprint("log: SEF_LU_STATE_PROTOCOL_FREE(%d) reached = %d\n",
94 SEF_LU_STATE_PROTOCOL_FREE, (!is_read_pending
95 && !is_select_callback_pending));
96 sef_lu_dprint("log: LOG_STATE_SELECT_PROTOCOL_FREE(%d) reached = %d\n",
97 LOG_STATE_SELECT_PROTOCOL_FREE, (!is_select_callback_pending));