YggFile.mesa
Copyright Ó 1988 by Xerox Corporation. All rights reserved.
Bob Hagmann January 20, 1989 3:40:55 pm PST
DIRECTORY
Basics USING [logBytesPerWord],
Camelot USING [optrT, tidT],
IO USING [STREAM],
Mach USING [pointerT],
YggDID USING [DID],
YggDIDMap USING [RunList],
YggInternal USING[FileHandle];
YggFile: CEDAR DEFINITIONS
= BEGIN
Introduction
This interface provides for creating, accessing and deleting files. Files are permanent objects recorded on Camelot recoverable backing storage segments. Each file consists of a number of pages from a variety of segments. The data pages of a file can be read and written. Files can be extended or contracted.
Errors
RC: TYPE = { -- extension of "Reason" for internal use.
ok,
inconsistent, -- the volume's (or file's) permanent data structures look inconsistent
software, -- i.e. label-check. The page on disk is not the one the software expected.
hardware, -- the disk hardware/microcode detected a hard disk error
unknownFile, -- the file does not exist (possibly deleted since it was opened)
unknownPage, -- the page would be beyond the end of the file
volumeFull -- the volume has no free pages (and one is needed!)
};
Reason: TYPE = RC[SUCC[ok]..LAST[RC]]; -- error reason
Error: ERROR [why: Reason, diskPage: INT ← -1];
Types and Constants
PageNumber: TYPE = RECORD[INT];
Actually, [0..LAST[INT]). The file-relative number of a data page. The first data page of a file is numbered 0.
PageCount: TYPE = INT;
Actually [0..LAST[INT]]. Represents file sizes.
Add: PROC[p: PageNumber, n: PageCount] RETURNS[PageNumber] = INLINE
{ RETURN[ [p+n] ] }; -- "n" may be negative --
bytesPerPage: NAT = 4096;
logBytesPerPage: NAT = 12;
wordsPerPage: NAT = bytesPerPage/BYTES[CARD32];
logWordsPerPage: NAT = logBytesPerPage-Basics.logBytesPerWord;
The number of bytes in each data page of a file.
PagesForBytes: PROC [bytes: CARD] RETURNS [pages: PageCount];
BytesForPages: PROC [pages: PageCount] RETURNS [bytes: CARD];
PagesForWords: PROC [words: CARD] RETURNS [pages: PageCount];
WordsForPages: PROC [pages: PageCount] RETURNS [words: CARD];
FileHandle: TYPE = YggInternal.FileHandle;
FileHandleRep: TYPE;
The runtime representation of a file. NIL never represents a valid file.
Files
Open: PROC [runList: YggDIDMap.RunList, byteSize: INT, did: YggDID.DID, fileUse: ATOM, verifyLeaderNow: BOOLFALSE] RETURNS [file: FileHandle];
Open the file with this run list. If verifyLeaderNow is true, verify that the leader matches the runList now, instead of delaying the access.
Create: PROC [size: PageCount, did: YggDID.DID, fileUse: ATOM, nearToDid: YggDID.DID, tid: Camelot.tidT] RETURNS [FileHandle];
Delete: PROC [file: FileHandle, tid: Camelot.tidT];
Destroys the file.
Info: PROC [file: FileHandle, tid: Camelot.tidT] RETURNS [did: YggDID.DID, size: PageCount, byteSize: INT, runList: YggDIDMap.RunList];
SetSize: PROC [file: FileHandle, size: PageCount, tid: Camelot.tidT];
SetByteSize: PROC [file: FileHandle, byteSize: PageCount, tid: Camelot.tidT];
Locate: PROC [file: FileHandle, tid: Camelot.tidT, from: PageNumber, nPages: PageCount] RETURNS [runList: YggDIDMap.RunList];
Read: UNSAFE PROC [file: FileHandle, tid: Camelot.tidT, from: PageNumber, nPages: PageCount, to: LONG POINTER];
Write: UNSAFE PROC [file: FileHandle, tid: Camelot.tidT, to: PageNumber, nPages: PageCount, from: LONG POINTER];
Server stats
ServerInfo: PROC RETURNS [blockSize: CARD, secondaryBlocks: CARD, secondaryBlocksFree: CARD, tertiaryBlocks: CARD, tertiaryBlocksFree: CARD];
Info about the server
Streams
FileFromComponentFiles: PROC [componentFiles: LIST OF YggInternal.FileHandle, fileUse: ATOM] RETURNS [file: YggInternal.FileHandle];
Select a file
FileUseFromComponentFiles: PROC [componentFiles: LIST OF YggInternal.FileHandle] RETURNS [fileUses: LIST OF ATOM];
Find the uses of all the files
StreamFromOpenFileAndTid: PROC[file: FileHandle, tid: Camelot.tidT, readOnly: BOOLFALSE] RETURNS [stream: IO.STREAM];
DID Map
OpenDIDMapFile: PROC RETURNS [file: YggInternal.FileHandle];
GetMaxDIDAddress: PROC RETURNS [optr: Camelot.optrT, address: Mach.pointerT];
Transactions
PreCommit: PROC[tid: Camelot.tidT];
Commit: PROC[tid: Camelot.tidT];
Abort: PROC[tid: Camelot.tidT]
END.