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