From 1abf16c567f6d8852012e9e8da88032d33d9cb1f Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Fri, 3 Dec 2004 00:19:02 +0000 Subject: [PATCH] add scsi support to load_image() --- second/load.c | 66 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/second/load.c b/second/load.c index 7db2726..3eca8c8 100644 --- a/second/load.c +++ b/second/load.c @@ -9,30 +9,50 @@ #include "bank.h" #include "misc.h" #include "glue.h" +#include "head.h" #include "load.h" -char* load_image(int unit, unsigned long offset, unsigned long size) +#ifdef SCSI_SUPPORT +#include "scsi.h" +static char* load_container(struct emile_container* container, char* image) { + char* base = image; + int target; + int i; int err; - char* image; - ParamBlockRec_t param_block; - if (size == 0) - return NULL; + target = container->unit_id; - image = malloc_contiguous(size + 4); - if (image == 0) + i = 0; + while (container->blocks[i].count != 0) { - free(image); - return NULL; + err = scsi_READ(target, container->blocks[i].offset, + container->blocks[i].count, + image, + container->block_size * container->blocks[i].count); + if (err != noErr) + { + free(image); + return NULL; + } + + image += container->block_size * container->blocks[i].count; + i++; } - image = (char*)(((unsigned long)image + 3) & 0xFFFFFFFC); + return base; +} +#else /* SCSI_SUPPORT */ + +static char* load_blocks(unsigned long offset, unsigned long size, char *image) +{ + int err; + ParamBlockRec_t param_block; memset(¶m_block, 0, sizeof(param_block)); param_block.ioBuffer = (unsigned long)image; - param_block.ioVRefNum = unit; + param_block.ioVRefNum = 1; param_block.ioRefNum = -5; param_block.ioReqCount = size; param_block.ioPosMode = fsFromStart; @@ -47,3 +67,27 @@ char* load_image(int unit, unsigned long offset, unsigned long size) return image; } +#endif /* SCSI_SUPPORT */ + +char* load_image(unsigned long offset, unsigned long size) +{ + char* image; + + if (size == 0) + return NULL; + + image = malloc_contiguous(size + 4); + if (image == 0) + { + free(image); + return NULL; + } + + image = (char*)(((unsigned long)image + 3) & 0xFFFFFFFC); + +#ifdef SCSI_SUPPORT + return load_container((struct emile_container*)offset, image); +#else + return load_blocks(offset, size, image); +#endif +}