mirror of
https://github.com/marciot/mac-tip.git
synced 2024-06-14 04:29:29 +00:00
Automatically adjust buffer size based on available memory.
This commit is contained in:
parent
1af5e74aea
commit
b5f0328beb
|
@ -72,7 +72,7 @@ struct DEFECT_LIST_HEADER {
|
|||
#define DRIVE_A_SUPPORT_BIAS 32 // reduce total by 32 for DRIVE A support
|
||||
|
||||
#define BYTES_PER_SECTOR 512
|
||||
#define MAX_SECTORS_PER_TEST 25
|
||||
#define MAX_SECTORS_PER_TEST 128
|
||||
|
||||
#define BADNESS_THRESHOLD 10
|
||||
|
||||
|
@ -89,6 +89,7 @@ struct DEFECT_LIST_HEADER {
|
|||
|
||||
#define CHECK_CONDITION 0x02
|
||||
|
||||
TipPage CurrentPage;
|
||||
long CurrentDevice = -1; // the device that's been recognized
|
||||
long DriveCount = 0;
|
||||
|
||||
|
@ -108,6 +109,7 @@ long TestingPhase = 0; // 0 = not testing, no data ...
|
|||
long PercentComplete;
|
||||
long FirstLBASector;
|
||||
long NumberOfLBAs;
|
||||
long AdapterMaxSectors;
|
||||
long LastLBAOnCartridge;
|
||||
long SecondsElapsed;
|
||||
long SoftErrors;
|
||||
|
@ -922,13 +924,24 @@ Exit:
|
|||
*******************************************************************************/
|
||||
|
||||
void TestTheDisk() {
|
||||
void *pPatternBuffer = malloc(MAX_SECTORS_PER_TEST * BYTES_PER_SECTOR);
|
||||
void *pUserDataBuffer = malloc(MAX_SECTORS_PER_TEST * BYTES_PER_SECTOR);
|
||||
// setup the initital maximum tranfer ...
|
||||
AdapterMaxSectors = MAX_SECTORS_PER_TEST; // limit to our max
|
||||
|
||||
if(pPatternBuffer == NULL || pUserDataBuffer == NULL) {
|
||||
printf("Allocation error\n");
|
||||
void *pDataBuffer = 0;
|
||||
for(;;) {
|
||||
pDataBuffer = malloc(AdapterMaxSectors * BYTES_PER_SECTOR * 2);
|
||||
if(pDataBuffer) break;
|
||||
AdapterMaxSectors >>= 2; // we need to make it smaller
|
||||
if(AdapterMaxSectors == 0) {
|
||||
printf("Test buffer allocation failed!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Allocated buffer of %ld bytes\n", AdapterMaxSectors * BYTES_PER_SECTOR);
|
||||
|
||||
void *pPatternBuffer = pDataBuffer;
|
||||
void *pUserDataBuffer = (char*) pDataBuffer + AdapterMaxSectors * BYTES_PER_SECTOR;
|
||||
|
||||
StopApplicationTimer();
|
||||
|
||||
|
@ -950,7 +963,7 @@ void TestTheDisk() {
|
|||
do {
|
||||
ProcessPendingMessages();
|
||||
|
||||
NumberOfLBAs = MAX_SECTORS_PER_TEST;
|
||||
NumberOfLBAs = AdapterMaxSectors;
|
||||
|
||||
if(LastLBAOnCartridge) {
|
||||
if (FirstLBASector + NumberOfLBAs > LastLBAOnCartridge + 1) {
|
||||
|
@ -967,7 +980,7 @@ void TestTheDisk() {
|
|||
|
||||
// get a random pattern of data to write
|
||||
const long DataPattern = rand();
|
||||
memset(pPatternBuffer, DataPattern, MAX_SECTORS_PER_TEST * BYTES_PER_SECTOR);
|
||||
memset(pPatternBuffer, DataPattern, AdapterMaxSectors * BYTES_PER_SECTOR);
|
||||
|
||||
// update the cartridge's status
|
||||
GetSpareSectorCounts(false); // update the Cart's Condition
|
||||
|
@ -1005,8 +1018,7 @@ void TestTheDisk() {
|
|||
// show that we're post-test
|
||||
|
||||
GetOut:
|
||||
free(pPatternBuffer);
|
||||
free(pUserDataBuffer);
|
||||
free(pDataBuffer);
|
||||
|
||||
TestingPhase = UNTESTED;
|
||||
UnlockAllMedia();
|
||||
|
|
Loading…
Reference in New Issue
Block a user