Most disk drivers only implement a couple of the available bios commands. Unify the common fallback handling code into a new function default_process_op() to reduce boiler-plate code.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 17 +++++++++++++++++ src/block.h | 1 + src/cdrom.c | 7 +------ src/hw/ahci.c | 9 +-------- src/hw/ata.c | 6 +----- src/hw/blockcmd.c | 8 +------- src/hw/ramdisk.c | 6 +----- src/hw/sdcard.c | 8 +------- src/hw/virtio-blk.c | 8 +------- 9 files changed, 25 insertions(+), 45 deletions(-)
diff --git a/src/block.c b/src/block.c index e534319..1d628f9 100644 --- a/src/block.c +++ b/src/block.c @@ -467,6 +467,23 @@ fill_edd(u16 seg, struct int13dpt_s *param_far, struct drive_s *drive_gf) * Disk driver dispatch ****************************************************************/
+// Fallback handler for command requests not implemented by drivers +int +default_process_op(struct disk_op_s *op) +{ + switch (op->command) { + case CMD_FORMAT: + case CMD_RESET: + case CMD_ISREADY: + case CMD_VERIFY: + case CMD_SEEK: + // Return success if the driver doesn't implement these commands + return DISK_RET_SUCCESS; + default: + return DISK_RET_EPARAM; + } +} + static int process_atapi_op(struct disk_op_s *op) { diff --git a/src/block.h b/src/block.h index 8182288..2fa52bd 100644 --- a/src/block.h +++ b/src/block.h @@ -102,6 +102,7 @@ void map_hd_drive(struct drive_s *drive); void map_cd_drive(struct drive_s *drive); struct int13dpt_s; int fill_edd(u16 seg, struct int13dpt_s *param_far, struct drive_s *drive_gf); +int default_process_op(struct disk_op_s *op); int process_op(struct disk_op_s *op); int send_disk_op(struct disk_op_s *op); int create_bounce_buf(void); diff --git a/src/cdrom.c b/src/cdrom.c index ba02340..bf1d2a6 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -100,13 +100,8 @@ process_cdemu_op(struct disk_op_s *op) case CMD_WRITE: case CMD_FORMAT: return DISK_RET_EWRITEPROTECT; - case CMD_VERIFY: - case CMD_RESET: - case CMD_SEEK: - case CMD_ISREADY: - return DISK_RET_SUCCESS; default: - return DISK_RET_EPARAM; + return default_process_op(op); } }
diff --git a/src/hw/ahci.c b/src/hw/ahci.c index 82fce42..ad813ce 100644 --- a/src/hw/ahci.c +++ b/src/hw/ahci.c @@ -306,15 +306,8 @@ process_ahci_op(struct disk_op_s *op) return ahci_disk_readwrite(op, 0); case CMD_WRITE: return ahci_disk_readwrite(op, 1); - case CMD_FORMAT: - case CMD_RESET: - case CMD_ISREADY: - case CMD_VERIFY: - case CMD_SEEK: - return DISK_RET_SUCCESS; default: - dprintf(1, "AHCI: unknown disk command %d\n", op->command); - return DISK_RET_EPARAM; + return default_process_op(op); } }
diff --git a/src/hw/ata.c b/src/hw/ata.c index d805706..d674f61 100644 --- a/src/hw/ata.c +++ b/src/hw/ata.c @@ -569,12 +569,8 @@ process_ata_op(struct disk_op_s *op) return DISK_RET_SUCCESS; case CMD_ISREADY: return isready(adrive_gf); - case CMD_FORMAT: - case CMD_VERIFY: - case CMD_SEEK: - return DISK_RET_SUCCESS; default: - return DISK_RET_EPARAM; + return default_process_op(op); } }
diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 3128f0a..ecfeb5d 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -174,14 +174,8 @@ scsi_process_op(struct disk_op_s *op) return cdb_read(op); case CMD_WRITE: return cdb_write(op); - case CMD_FORMAT: - case CMD_RESET: - case CMD_ISREADY: - case CMD_VERIFY: - case CMD_SEEK: - return DISK_RET_SUCCESS; default: - return DISK_RET_EPARAM; + return default_process_op(op); } }
diff --git a/src/hw/ramdisk.c b/src/hw/ramdisk.c index 6b44c83..67ba59c 100644 --- a/src/hw/ramdisk.c +++ b/src/hw/ramdisk.c @@ -101,11 +101,7 @@ process_ramdisk_op(struct disk_op_s *op) return ramdisk_copy(op, 0); case CMD_WRITE: return ramdisk_copy(op, 1); - case CMD_VERIFY: - case CMD_FORMAT: - case CMD_RESET: - return DISK_RET_SUCCESS; default: - return DISK_RET_EPARAM; + return default_process_op(op); } } diff --git a/src/hw/sdcard.c b/src/hw/sdcard.c index 626f042..965543c 100644 --- a/src/hw/sdcard.c +++ b/src/hw/sdcard.c @@ -218,14 +218,8 @@ process_sdcard_op(struct disk_op_s *op) return sdcard_readwrite(op, 0); case CMD_WRITE: return sdcard_readwrite(op, 1); - case CMD_FORMAT: - case CMD_RESET: - case CMD_ISREADY: - case CMD_VERIFY: - case CMD_SEEK: - return DISK_RET_SUCCESS; default: - return DISK_RET_EPARAM; + return default_process_op(op); } }
diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 0a02a03..92a5546 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -87,14 +87,8 @@ process_virtio_blk_op(struct disk_op_s *op) return virtio_blk_op(op, 0); case CMD_WRITE: return virtio_blk_op(op, 1); - case CMD_FORMAT: - case CMD_RESET: - case CMD_ISREADY: - case CMD_VERIFY: - case CMD_SEEK: - return DISK_RET_SUCCESS; default: - return DISK_RET_EPARAM; + return default_process_op(op); } }