From 2092e486943363de7af11f47da784058a40a7312 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 13 Aug 2018 01:28:32 -0500 Subject: [PATCH] Add support for reporting the disk's block count. --- driver.c | 40 ++++++++++++++++++++++++++++++---------- netdiskerror.h | 1 + session.h | 2 ++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/driver.c b/driver.c index 8aa636a..1b8bf99 100644 --- a/driver.c +++ b/driver.c @@ -212,10 +212,14 @@ static enum NetDiskError CheckTwoImg(Session *sess) { return UNSUPPORTED_2IMG_FILE; if (hdr->dataLength % BLOCK_SIZE != 0) return UNSUPPORTED_2IMG_FILE; - - // TODO more checks sess->dataOffset = hdr->dataOffset; + sess->dataLength = hdr->dataLength; + + /* Sweet16 apparently may generate images with erroneous dataLength of 0 */ + if (hdr->dataLength == 0) { + sess->dataLength = hdr->nBlocks * BLOCK_SIZE; + } return OPERATION_SUCCESSFUL; } @@ -254,7 +258,6 @@ static Word DoMountURL(struct GSOSDP *dp) { err = DoHTTPRequest(sess, 0, sizeof(sess->fileHeader) - 1); if (err != OPERATION_SUCCESSFUL) { - // TODO arrange for more detailed error reporting EndNetDiskSession(sess); dp->transferCount = 0; mountURLRec->result = err; @@ -275,6 +278,18 @@ static Word DoMountURL(struct GSOSDP *dp) { return drvrIOError; } + if (sess->dataOffset == 0) { + /* No encapsulating disk image - treat this as raw blocks */ + sess->dataLength = sess->totalLength; + } + + if (sess->dataLength % BLOCK_SIZE != 0) { + dp->transferCount = 0; + mountURLRec->result = NOT_MULTIPLE_OF_BLOCK_SIZE; + return drvrIOError; + } + dp->dibPointer->blockCount = sess->dataLength / BLOCK_SIZE; + dp->dibPointer->extendedDIBPtr = sess; //TODO report disk switch @@ -298,7 +313,6 @@ static Word DoRead(struct GSOSDP *dp) { enum NetDiskError err = DoHTTPRequest(sess, readStart, readEnd); if (err != OPERATION_SUCCESSFUL) { - // TODO arrange for more detailed error reporting dp->transferCount = 0; return drvrIOError; } @@ -314,22 +328,27 @@ static Word DoRead(struct GSOSDP *dp) { } static Word DoStatus(struct GSOSDP *dp) { + Session *sess = dp->dibPointer->extendedDIBPtr; + DeviceStatusRec *dsRec = (DeviceStatusRec*)dp->statusListPtr; + if (dp->requestCount < 2) { dp->transferCount = 0; return drvrBadParm; } - //TODO handle actual disk, and disk-switched logic - /* no disk in drive, ... */ - if (dp->dibPointer->extendedDIBPtr != NULL) { - ((DeviceStatusRec*)dp->statusListPtr)->statusWord = 0x8014; + //TODO disk-switched logic + if (sess != NULL) { + dsRec->statusWord = 0x0014; } else { - ((DeviceStatusRec*)dp->statusListPtr)->statusWord = 0; + dsRec->statusWord = 0; } if (dp->requestCount < 6) { dp->transferCount = 2; return 0; } - ((DeviceStatusRec*)dp->statusListPtr)->numBlocks = 0; + dsRec->numBlocks = dp->dibPointer->blockCount; + if (dsRec->numBlocks == 0) { + dsRec->statusWord |= 0x8000; + } dp->requestCount = 6; return 0; } @@ -337,6 +356,7 @@ static Word DoStatus(struct GSOSDP *dp) { static Word DoEject(struct GSOSDP *dp) { EndNetDiskSession(dp->dibPointer->extendedDIBPtr); dp->dibPointer->extendedDIBPtr = NULL; + dp->dibPointer->blockCount = 0; dp->transferCount = 0; return 0; diff --git a/netdiskerror.h b/netdiskerror.h index d3c565c..5006e8a 100644 --- a/netdiskerror.h +++ b/netdiskerror.h @@ -38,6 +38,7 @@ enum NetDiskError { /* File format errors */ UNSUPPORTED_2IMG_FILE = 600, + NOT_MULTIPLE_OF_BLOCK_SIZE }; diff --git a/session.h b/session.h index 3b5e08b..99479ab 100644 --- a/session.h +++ b/session.h @@ -51,6 +51,8 @@ typedef struct Session { /* Offset of disk image blocks within file */ LongWord dataOffset; + /* Length of disk image data */ + LongWord dataLength; /* Buffer for initial bytes of file (which may be a disk image header) */ union {