PROC [fileName: Rope.
{
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;
};