mirror of
https://github.com/sheumann/NetDisk.git
synced 2024-11-27 19:49:38 +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 <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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user