mirror of
https://github.com/sheumann/NetDisk.git
synced 2024-11-23 22:37:02 +00:00
Add GS/OS block cache support.
This commit is contained in:
parent
314f408b5e
commit
55b199f83b
42
driver.c
42
driver.c
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <gsos.h>
|
#include <gsos.h>
|
||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
#include "driverwrapper.h"
|
#include "driverwrapper.h"
|
||||||
@ -250,6 +251,7 @@ static Word DoMountURL(struct GSOSDP *dp) {
|
|||||||
mountURLRec->result = OUT_OF_MEMORY;
|
mountURLRec->result = OUT_OF_MEMORY;
|
||||||
return drvrNoResrc;
|
return drvrNoResrc;
|
||||||
}
|
}
|
||||||
|
sess->useCache = TRUE;
|
||||||
|
|
||||||
err = SetURL(sess, mountURLRec->url, TRUE, FALSE);
|
err = SetURL(sess, mountURLRec->url, TRUE, FALSE);
|
||||||
if (err != OPERATION_SUCCESSFUL) {
|
if (err != OPERATION_SUCCESSFUL) {
|
||||||
@ -334,6 +336,33 @@ static Word DoRead(struct GSOSDP *dp) {
|
|||||||
return drvrBadBlock;
|
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);
|
enum NetDiskError err = DoHTTPRequest(sess, readStart, readEnd);
|
||||||
if (err != OPERATION_SUCCESSFUL) {
|
if (err != OPERATION_SUCCESSFUL) {
|
||||||
dp->transferCount = 0;
|
dp->transferCount = 0;
|
||||||
@ -362,6 +391,19 @@ static Word DoRead(struct GSOSDP *dp) {
|
|||||||
return drvrIOError;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,9 @@ typedef struct Session {
|
|||||||
/* Length of disk image data */
|
/* Length of disk image data */
|
||||||
LongWord dataLength;
|
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) */
|
/* Buffer for initial bytes of file (which may be a disk image header) */
|
||||||
union {
|
union {
|
||||||
unsigned char buf[32];
|
unsigned char buf[32];
|
||||||
|
Loading…
Reference in New Issue
Block a user