Add GS/OS block cache support.

This commit is contained in:
Stephen Heumann 2018-10-01 21:49:00 -05:00
parent 314f408b5e
commit 55b199f83b
2 changed files with 45 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <gsos.h>
#include "driver.h"
#include "driverwrapper.h"
@ -250,6 +251,7 @@ static Word DoMountURL(struct GSOSDP *dp) {
mountURLRec->result = OUT_OF_MEMORY;
return drvrNoResrc;
}
sess->useCache = TRUE;
err = SetURL(sess, mountURLRec->url, TRUE, FALSE);
if (err != OPERATION_SUCCESSFUL) {
@ -334,6 +336,33 @@ static Word DoRead(struct GSOSDP *dp) {
return drvrBadBlock;
}
LongWord firstBlockNum;
LongWord endBlockNum;
unsigned char *bufferPtr;
Boolean useCache = sess->useCache
&& (int)dp->cachePriority > 0
&& (dp->fstNum & 0x8000) == 0
&& dp->blockSize == BLOCK_SIZE;
if (useCache) {
firstBlockNum = dp->blockNum;
endBlockNum = firstBlockNum + dp->requestCount / BLOCK_SIZE;
bufferPtr = dp->bufferPtr;
for (; dp->blockNum < endBlockNum; dp->blockNum++) {
if (!CacheFindBlk()) {
goto skipCache;
}
memmove(bufferPtr, dp->cachePointer, BLOCK_SIZE);
bufferPtr += BLOCK_SIZE;
}
dp->blockNum = firstBlockNum;
dp->transferCount = dp->requestCount;
return 0;
skipCache:
useCache = (dp->blockNum == firstBlockNum);
dp->blockNum = firstBlockNum;
}
enum NetDiskError err = DoHTTPRequest(sess, readStart, readEnd);
if (err != OPERATION_SUCCESSFUL) {
dp->transferCount = 0;
@ -362,6 +391,19 @@ static Word DoRead(struct GSOSDP *dp) {
return drvrIOError;
}
if (useCache && sess->readCount == 0) {
bufferPtr = dp->bufferPtr;
dp->blockNum = firstBlockNum;
for (; dp->blockNum < endBlockNum; dp->blockNum++) {
if (!CacheAddBlk()) {
break;
}
memmove(dp->cachePointer, bufferPtr, BLOCK_SIZE);
bufferPtr += BLOCK_SIZE;
}
dp->blockNum = firstBlockNum;
}
return 0;
}

View File

@ -55,6 +55,9 @@ typedef struct Session {
/* Length of disk image data */
LongWord dataLength;
/* Should the GS/OS block cache be used? */
Boolean useCache;
/* Buffer for initial bytes of file (which may be a disk image header) */
union {
unsigned char buf[32];