minix/drivers/floppy/liveupdate.c
David van Moolenbroek b4d909d415 Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.

The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.

After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
  in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
  reintroduced

As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.

Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-23 14:06:37 +01:00

78 lines
2.9 KiB
C

#include "floppy.h"
/* State management variables. */
EXTERN u16_t f_busy;
EXTERN int motor_status;
EXTERN unsigned f_drive;
EXTERN int last_was_write;
#define BSY_IO 1 /* busy doing I/O */
/* State management helpers. */
#define IS_REQUEST_PENDING(b) ((b) == BSY_IO)
#define IS_READ_PENDING(b, c) \
(IS_REQUEST_PENDING((b)) && (c) == DEV_GATHER_S)
#define IS_WRITE_PENDING(b, c) \
(IS_REQUEST_PENDING((b)) && (c) == DEV_SCATTER_S)
#define IS_MOTOR_RUNNING(s, d) ((s) & (1 << (d)))
/* Custom states definition. */
#define FL_STATE_MOTOR_OFF (SEF_LU_STATE_CUSTOM_BASE + 0)
#define FL_STATE_IS_CUSTOM(s) ((s) == FL_STATE_MOTOR_OFF)
/*===========================================================================*
* sef_cb_lu_prepare *
*===========================================================================*/
PUBLIC int sef_cb_lu_prepare(int state)
{
int is_ready;
/* Check if we are ready for the target state. */
is_ready = FALSE;
switch(state) {
/* Standard states. */
case SEF_LU_STATE_REQUEST_FREE:
case SEF_LU_STATE_PROTOCOL_FREE:
is_ready = (!IS_REQUEST_PENDING(f_busy));
break;
/* Custom states. */
case FL_STATE_MOTOR_OFF:
is_ready = (!IS_REQUEST_PENDING(f_busy)
&& !IS_MOTOR_RUNNING(motor_status, f_drive));
break;
}
/* Tell SEF if we are ready. */
return is_ready ? OK : ENOTREADY;
}
/*===========================================================================*
* sef_cb_lu_state_isvalid *
*===========================================================================*/
PUBLIC int sef_cb_lu_state_isvalid(int state)
{
return SEF_LU_STATE_IS_STANDARD(state) || FL_STATE_IS_CUSTOM(state);
}
/*===========================================================================*
* sef_cb_lu_state_dump *
*===========================================================================*/
PUBLIC void sef_cb_lu_state_dump(int state)
{
sef_lu_dprint("floppy: live update state = %d\n", state);
sef_lu_dprint("floppy: f_busy = %d\n", f_busy);
sef_lu_dprint("floppy: motor_status = 0x%02X\n", motor_status);
sef_lu_dprint("floppy: f_drive = %d\n", f_drive);
sef_lu_dprint("floppy: last_was_write = %d\n", last_was_write);
sef_lu_dprint("floppy: SEF_LU_STATE_WORK_FREE(%d) reached = %d\n",
SEF_LU_STATE_WORK_FREE, TRUE);
sef_lu_dprint("floppy: SEF_LU_STATE_REQUEST_FREE(%d) reached = %d\n",
SEF_LU_STATE_REQUEST_FREE, (!IS_REQUEST_PENDING(f_busy)));
sef_lu_dprint("floppy: SEF_LU_STATE_PROTOCOL_FREE(%d) reached = %d\n",
SEF_LU_STATE_PROTOCOL_FREE, (!IS_REQUEST_PENDING(f_busy)));
sef_lu_dprint("floppy: FL_STATE_MOTOR_OFF(%d) reached = %d\n",
FL_STATE_MOTOR_OFF, (!IS_REQUEST_PENDING(f_busy)
&& !IS_MOTOR_RUNNING(motor_status, f_drive)));
}