Introduce scsi_fill_cmd() which creates a scsi style "command data block" from a "struct disk_op_s" disk request.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/blockcmd.c | 53 +++++++++++++++++++++++------------------------------ src/hw/blockcmd.h | 1 + 2 files changed, 24 insertions(+), 30 deletions(-)
diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 99ebabc..004c58f 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -152,51 +152,44 @@ cdb_mode_sense_geom(struct disk_op_s *op, struct cdbres_mode_sense_geom *data) return process_op(op); }
-// Read sectors. -static int -cdb_read(struct disk_op_s *op) -{ - struct cdb_rwdata_10 cmd; - memset(&cmd, 0, sizeof(cmd)); - cmd.command = CDB_CMD_READ_10; - cmd.lba = cpu_to_be32(op->lba); - cmd.count = cpu_to_be16(op->count); - return cdb_cmd_data(op, &cmd, GET_GLOBALFLAT(op->drive_gf->blksize)); -} - -// Write sectors. -static int -cdb_write(struct disk_op_s *op) -{ - struct cdb_rwdata_10 cmd; - memset(&cmd, 0, sizeof(cmd)); - cmd.command = CDB_CMD_WRITE_10; - cmd.lba = cpu_to_be32(op->lba); - cmd.count = cpu_to_be16(op->count); - return cdb_cmd_data(op, &cmd, GET_GLOBALFLAT(op->drive_gf->blksize)); -} -
/**************************************************************** * Main SCSI commands ****************************************************************/
+// Create a scsi command request from a disk_op_s request int -scsi_process_op(struct disk_op_s *op) +scsi_fill_cmd(struct disk_op_s *op, void *cdbcmd, int maxcdb) { switch (op->command) { case CMD_READ: - return cdb_read(op); - case CMD_WRITE: - return cdb_write(op); + case CMD_WRITE: ; + struct cdb_rwdata_10 *cmd = cdbcmd; + memset(cmd, 0, maxcdb); + cmd->command = (op->command == CMD_READ ? CDB_CMD_READ_10 + : CDB_CMD_WRITE_10); + cmd->lba = cpu_to_be32(op->lba); + cmd->count = cpu_to_be16(op->count); + return GET_GLOBALFLAT(op->drive_gf->blksize); case CMD_SCSI: - return cdb_cmd_data(op, op->cdbcmd, op->blocksize); + memcpy(cdbcmd, op->cdbcmd, maxcdb); + return op->blocksize; default: - return default_process_op(op); + return -1; } }
int +scsi_process_op(struct disk_op_s *op) +{ + char cdbcmd[16]; + int blocksize = scsi_fill_cmd(op, cdbcmd, sizeof(cdbcmd)); + if (blocksize < 0) + return default_process_op(op); + return cdb_cmd_data(op, cdbcmd, blocksize); +} + +int scsi_is_ready(struct disk_op_s *op) { dprintf(6, "scsi_is_ready (drive=%p)\n", op->drive_gf); diff --git a/src/hw/blockcmd.h b/src/hw/blockcmd.h index df12a6d..9077e82 100644 --- a/src/hw/blockcmd.h +++ b/src/hw/blockcmd.h @@ -102,6 +102,7 @@ struct cdbres_mode_sense_geom { // blockcmd.c int cdb_is_read(u8 *cdbcmd, u16 blocksize); struct disk_op_s; +int scsi_fill_cmd(struct disk_op_s *op, void *cdbcmd, int maxcdb); int scsi_process_op(struct disk_op_s *op); int scsi_is_ready(struct disk_op_s *op); struct drive_s;