GeneralFS.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Doug Terry, November 18, 1985 3:37:08 pm PST
Interface for opening and creating FS files regardless of whether thay are actually managed by FS, AlpineFS, or StableFS. The following heuristics are used to guess the class of the file from the file's server name:
1) a file whose server name contains ".alpine" is presumed to be an Alpine file.
2) the special server name "StableStorage" identifies a file residing in stable storage; the file name syntax is [StableStorage]<bank>copy.broadside where bank in [0..15], copy in [0..3], and broadside in [0..1].
3) any other file is presumed to be an ordinary FS file.
The operations provided herein are syntactically identical to those defined in FS. Clients that need to pass parameters particular to AlpineFS.Open, for instance, should access that interface directly.
DIRECTORY
BasicTime USING [GMT, nullGMT],
FS USING [AccessOptions, ByteCount, defaultStreamBufferParms, defaultStreamOptions, ExtendFileProc, Lock, OpenFile, StreamBufferParms, StreamOptions],
IO USING [STREAM],
Rope USING [ROPE];
GeneralFS: CEDAR DEFINITIONS
= BEGIN
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
Errors
Clients of GeneralFS should be prepared to catch ERROR FS.Error.
Opening Files
OpenFile: TYPE = FS.OpenFile;
Open: PROC [name: ROPE,
lock: FS.Lock ← $read,
wantedCreatedTime: BasicTime.GMT ← BasicTime.nullGMT,
remoteCheck: BOOLTRUE,
wDir: ROPENIL
] RETURNS [OpenFile];
Calls either FS.Open, AlpineFS.Open, or StableFS.Open depending on the file name.
Client errors: $noCache, $globalWriteLock
User errors: $nonCedarVolume, $unknownServer, $unknownVolume, $unknownFile, $unknownCreatedTime, $illegalName, $patternNotAllowed
Create: PROC [name: ROPE,
setPages: BOOLTRUE, pages: INT ← 0,
setKeep: BOOLFALSE, keep: CARDINAL ← 1,
wDir: ROPENIL
] RETURNS [OpenFile];
Calls either FS.Create, AlpineFS.Create, or StableFS.Create depending on the file name.
Client errors: $zeroKeep
User errors: $nonCedarVolume, $unknownServer, $unknownVolume, $illegalName, $patternNotAllowed, $versionSpecified, $globalCreation
OpenOrCreate: PROC [name: ROPE,
keep: CARDINAL ← 1, pages: INT ← 5, wDir: ROPENIL
] RETURNS [OpenFile];
This procedures is a convenience for a client that wishes to open an existing file for write, as is the case for log files. Performs GeneralFS.Open[name: name, lock: write, wDir: wDir]. If FS.Error[$unknownFile] results then GeneralFS.Create[name: name, pages: pages, keep: keep, wDir: wDir] is called.
Client errors: $noCache, $globalWriteLock, $zeroKeep
User errors: $nonCedarVolume, $unknownServer, $unknownVolume, $unknownCreatedTime, $illegalName, $patternNotAllowed, $versionSpecified, $globalCreation
Creating File Streams
StreamOpen: PROC [fileName: ROPE,
accessOptions: FS.AccessOptions ← $read,
streamOptions: FS.StreamOptions ← FS.defaultStreamOptions,
keep: CARDINAL ← 1,
createByteCount: FS.ByteCount ← 2560,
streamBufferParms: FS.StreamBufferParms ← FS.defaultStreamBufferParms,
extendFileProc: FS.ExtendFileProc ← NIL,
wantedCreatedTime: BasicTime.GMT ← BasicTime.nullGMT,
remoteCheck: BOOLTRUE,
wDir: ROPENIL
] RETURNS [STREAM];
Create a new stream by (1) generating an FS.OpenFile from fileName, keep, and createByteCount, then (2) creating a stream on this FS.OpenFile.
(1) If accessOptions = $read, perform GeneralFS.Open[name: fileName, wantedCreatedTime: wantedCreatedTime, remoteCheck: remoteCheck, wDir: wDir]. If accessOptions = $create, perform GeneralFS.Create[name: fileName, keep: keep, pages: FS.PagesForBytes[createByteCount], wDir: wDir]. If accessOptions = $append, perform GeneralFS.OpenOrCreate[name: fileName, keep: keep, pages: FS.PagesForBytes[createByteCount], wDir: wDir]. If accessOptions = $write, perform GeneralFS.Open[name: fileName, lock: $write, wantedCreatedTime: wantedCreatedTime, remoteCheck: remoteCheck, wDir: wDir]. Any FS.Error raised by a call to GeneralFS.Open, GeneralFS.Create, or GeneralFS.OpenOrCreate will propogate through GeneralFS.StreamOpen.
(2) Perform FS.StreamFromOpenFile[ ... , streamOptions, streamBufferParms, extendFileProc] on the resulting FS.OpenFile. The value of accessOptions determines the set of operations allowed on the stream (disallowed operations raise IO.Error[$NotImplementedForThisStream, stream] when called), and the initial streamIndex, as follows:
read: PutChar, PutBlock, UnsafePutBlock, and SetLength are disallowed, and the initial streamIndex is 0.
create: all operations are allowed, the length is set to zero at stream creation time, and the initial streamIndex is 0.
append: all operations are allowed, and the initial streamIndex is the file's byte count.
write: all operations are allowed, and the initial streamIndex is 0.
Client errors: $noCache, $globalWriteLock, $zeroKeep
User errors: $nonCedarVolume, $unknownServer, $unknownVolume, $unknownFile, $illegalName, $patternNotAllowed, $versionSpecified, $globalCreation, $cantUpdateTiogaFile
END.