FileExtendTester.mesa
Last Edited by:
Bob Hagmann, April 1, 1985 12:22:14 pm PST
DIRECTORY
FS,
Random,
Rope,
VM;
FileExtendTester: CEDAR PROGRAM
IMPORTS FS, Random, VM
= BEGIN
DoTest: PROC [fileName: Rope.ROPE, numberOfExtends: INT ] = {
vmBuffer: VM.Interval ← VM.nullInterval;
{
ENABLE UNWIND => IF vmBuffer # VM.nullInterval THEN TRUSTED {
VM.Free[vmBuffer ! VM.AddressFault => CONTINUE;];
};
file: FS.OpenFile;
sizeNow: INT ← 100;
offset: INT ← 0;
dummy1, dummy2: INT ← 0;
bufferPointer: LONG POINTER;
randomStream: Random.RandomStream;
file ← FS.Create[name: fileName, setPages: TRUE, pages: sizeNow, setKeep: TRUE, keep: 100];
randomStream ← Random.Create[range: 10000, seed: -1] ;
offset ← Random.ChooseInt[randomStream, 1, 10000];
vmBuffer ← VM.Allocate[count: 1];
TRUSTED { bufferPointer ← VM.AddressForPageNumber[vmBuffer.page]; };
FOR page: INT IN [0..sizeNow) DO
intBuffer: LONG POINTER TO ARRAY [0..8) OF INT = LOOPHOLE[bufferPointer];
TRUSTED { intBuffer[0] ← offset+page;};
file.Write[to: page, nPages: 1, from: bufferPointer];
ENDLOOP;
TRUSTED {
FOR page: INT IN [0..sizeNow) DO
intBuffer: LONG POINTER TO ARRAY [0..8) OF INT = bufferPointer;
intBuffer[0] ← -1;
file.Read[from: page, nPages: 1, to: bufferPointer];
IF intBuffer[0] # offset+page THEN ERROR;
ENDLOOP;
};
FOR extent: INT IN [0..numberOfExtends) DO
intBuffer: LONG POINTER TO ARRAY [0..8) OF INT = LOOPHOLE[bufferPointer];
TRUSTED { intBuffer[0] ← offset+sizeNow;};
sizeNow ← sizeNow + 1;
file.SetPageCount[sizeNow];
file.Write[to: sizeNow-1, nPages: 1, from: bufferPointer];
ENDLOOP;
file.SetByteCountAndCreatedTime[bytes: FS.BytesForPages[sizeNow]];
TRUSTED {
FOR page: INT IN [0..sizeNow) DO
intBuffer: LONG POINTER TO ARRAY [0..8) OF INT = bufferPointer;
intBuffer[0] ← -1;
file.Read[from: page, nPages: 1, to: bufferPointer];
IF intBuffer[0] # offset+page THEN ERROR;
ENDLOOP;
};
file.Close[];
dummy1 ← sizeNow;
dummy2 ← sizeNow;
};
};
CheckFile: PROC [fileName: Rope.ROPE ] = {
vmBuffer: VM.Interval ← VM.nullInterval;
{
ENABLE UNWIND => IF vmBuffer # VM.nullInterval THEN TRUSTED {
VM.Free[vmBuffer ! VM.AddressFault => CONTINUE;];
};
file: FS.OpenFile;
size: INT ← 100;
offset: INT ← 0;
dummy1, dummy2: INT ← 0;
bufferPointer: LONG POINTER;
file ← FS.Open[name: fileName, lock: write];
vmBuffer ← VM.Allocate[count: 1];
TRUSTED { bufferPointer ← VM.AddressForPageNumber[vmBuffer.page]; };
[pages: size] ← file.GetInfo[];
TRUSTED {
FOR page: INT IN [0..size) DO
intBuffer: LONG POINTER TO ARRAY [0..8) OF INT = bufferPointer;
intBuffer[0] ← -1;
file.Read[from: page, nPages: 1, to: bufferPointer];
IF page = 0 THEN offset ← intBuffer[0] ELSE {
IF intBuffer[0] # offset+page THEN ERROR;
};
ENDLOOP;
};
file.SetPageCount[size+1];
file.SetPageCount[size];
file.Close[];
dummy1 ← size;
dummy2 ← size;
};
};
Start code
END.