YggFileStreamImpl.mesa
Copyright Ó 1988 by Xerox Corporation. All rights reserved.
Bob Hagmann May 13, 1988 3:48:08 pm PDT
DIRECTORY
BasicTime USING [GMT],
FileStream USING [StreamFromOpenFile],
FS USING [FileType, Lock, OpenFile],
FSBackdoor USING [CreateProcsOpenFile, CreateFileProcs, FileProcs],
IO USING [STREAM],
Rope USING [Concat, ROPE],
YggDID USING [],
YggEnvironment USING [PageCount],
YggFile USING [Create, FileHandle, Open],
YggFilePageMgr USING [ReadPages, VMPageSet],
YggFileStream USING [];
YggFileStreamImpl: CEDAR PROGRAM
IMPORTS FileStream, FSBackdoor, Rope, YggFile, YggFilePageMgr
EXPORTS YggDID, YggFileStream
~
BEGIN
ROPE: TYPE ~ Rope.ROPE;
DID: PUBLIC TYPE ~ REF DIDRep;
DIDRep:
PUBLIC
TYPE ~
ROPE;
For Phase 0, the DIDRep is just a string that names a directory (without the trailing /).
FileProcs: REF FSBackdoor.FileProcs;
FileDataRep:
TYPE =
RECORD [
fullFName: ROPE, -- canonical form of name
openFile: YggFile.FileHandle
];
Exported procedures
OpenFileInDirectory:
PUBLIC
PROC[did:
DID, filePart: Rope.
ROPE]
RETURNS [fileHandle: YggFile.FileHandle ← NIL] = {
fileHandle ← YggFile.Open[Rope.Concat[did^, filePart]];
};
CreateFileInDirectory:
PUBLIC
PROC[did:
DID, filePart: Rope.
ROPE, initialSize:
YggEnvironment.PageCount] RETURNS [fileHandle: YggFile.FileHandle ← NIL] = {
fileHandle ← YggFile.Create[Rope.Concat[did^, filePart], initialSize];
};
OpenStreamInDirectory:
PUBLIC
PROC[did:
DID, filePart: Rope.
ROPE]
RETURNS [stream:
IO.
STREAM ←
NIL] = {
openFile: FS.OpenFile;
clientFile: REF FileDataRep;
fsOpenFile: FS.OpenFile;
clientFile ← NEW [FileDataRep ← [fullFName: Rope.Concat[did^, filePart]]];
clientFile.openFile ← OpenFileInDirectory[did, filePart];
openFile ← FSBackdoor.CreateProcsOpenFile[clientFile: clientFile, fileProcs: FileProcs];
stream ← FileStream.StreamFromOpenFile[fsOpenFile, $write];
};
FS file procs
GetClass:
PROC [clientFile:
REF]
RETURNS [
ATOM] = {
RETURN [$UnixFS];
};
SameFile:
PROC [clientFile1, clientFile2:
REF]
RETURNS [
BOOL] = {
ERROR;
};
GetName:
PROC [clientFile:
REF]
RETURNS [fullFName, attachedTo: Rope.
ROPE] = {
WITH clientFile
SELECT
FROM
fileData: REF FileDataRep => {
RETURN [fileData.fullFName, fileData.fullFName];
};
ENDCASE => ERROR;
};
GetInfo: PROC [clientFile: REF] RETURNS [keep: CARDINAL, pages, bytes: INT,
created: BasicTime.
GMT, lock:
FS.Lock, fileType:
FS.FileType] = {
ERROR;
};
SetPageCount:
PROC [clientFile:
REF, pages:
INT] = {
ERROR;
};
SetByteCountAndCreatedTime:
PROC [clientFile:
REF, bytes:
INT,
created: BasicTime.
GMT] = {
ERROR;
};
Read:
UNSAFE
PROC [clientFile:
REF, from, nPages:
INT, to:
LONG
POINTER] = {
WITH clientFile
SELECT
FROM
fileData: REF FileDataRep => {
vMPageSet: YggFilePageMgr.VMPageSet;
vMPageSet ← YggFilePageMgr.ReadPages[fileHandle: fileData.openFile, pageRun: [from, nPages]];
};
ENDCASE => ERROR;
};
Write:
PROC [clientFile:
REF, to:
INT, nPages:
INT, from:
LONG
POINTER] = {
ERROR;
};
Close:
PROC [clientFile:
REF] = {
ERROR;
};
Initialization
FileProcs ← FSBackdoor.CreateFileProcs[GetClass, SameFile, GetName, GetInfo, SetPageCount, SetByteCountAndCreatedTime, Read, Write, Close];
END.