DIRECTORY FS USING [defaultStreamBufferParms, defaultStreamOptions, ErrorDesc, ExtendFileProc, InitialPosition, Lock, OpenFile, StreamBufferParms, StreamOptions], IO USING [STREAM, UnsafeBlock]; FileStream: CEDAR DEFINITIONS = BEGIN STREAM: TYPE = IO.STREAM; UnsafeBlock: TYPE = IO.UnsafeBlock; OpenFile: TYPE = FS.OpenFile; StreamFromOpenFile: PROC [openFile: FS.OpenFile, accessRights: FS.Lock _ $read, initialPosition: FS.InitialPosition _ $start, streamOptions: FS.StreamOptions _ FS.defaultStreamOptions, streamBufferParms: FS.StreamBufferParms _ FS.defaultStreamBufferParms, extendFileProc: FS.ExtendFileProc _ NIL ] RETURNS [STREAM]; StreamFromOpenStream: PROC [self: STREAM] RETURNS [STREAM]; GetChar: PROC [self: STREAM] RETURNS [CHAR]; GetBlock: PROC [self: STREAM, block: REF TEXT, startIndex: NAT, count: NAT] RETURNS [nBytesRead: NAT]; UnsafeGetBlock: UNSAFE PROC [self: STREAM, block: UnsafeBlock] RETURNS [nBytesRead: INT]; EndOf: PROC [self: STREAM] RETURNS [BOOL]; CharsAvail: PROC [self: STREAM, wait: BOOL] RETURNS [INT]; Backup: PROC [self: STREAM, char: CHAR]; PutChar: PROC [self: STREAM, char: CHAR]; PutBlock: PROC [self: STREAM, block: REF READONLY TEXT, startIndex: NAT, count: NAT]; UnsafePutBlock: PROC [self: STREAM, block: UnsafeBlock]; Flush: PROC [self: STREAM]; EraseChar: PROC [self: STREAM, char: CHAR]; Reset: PROC [self: STREAM]; Close: PROC [self: STREAM, abort: BOOL]; GetIndex: PROC [self: STREAM] RETURNS [index: INT]; SetIndex: PROC [self: STREAM, index: INT]; GetLength: PROC [self: STREAM] RETURNS [length: INT]; SetLength: PROC [self: STREAM, length: INT]; OpenFileFromStream: PROC [self: STREAM] RETURNS [FS.OpenFile]; ErrorFromStream: PROC [self: STREAM] RETURNS [FS.ErrorDesc]; SaveStreamError: PROC [self: STREAM, error: FS.ErrorDesc]; SetStreamClassData: PROC [self: STREAM, data: REF ANY]; GetStreamClassData: PROC [self: STREAM] RETURNS [data: REF ANY]; FinalizationProc: TYPE = PROC [openFile: FS.OpenFile, data: REF ANY, closed: BOOL]; SetFinalizationProc: PROC [self: STREAM, proc: FinalizationProc]; GetFinalizationProc: PROC [self: STREAM] RETURNS [proc: FinalizationProc]; END. NFileStream.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Taft, November 22, 1983 10:03 am Russ Atkinson (RRA) February 4, 1985 2:51:30 pm PST Doug Wyatt, February 27, 1985 11:47:15 am PST Interface to the generic file stream facilities. The FileStream facilities are generic in the sense that they are implemented entirely in terms of the generic FS operations, and therefore are applicable to any class of FS.OpenFile (workstation or Alpine). This interface is intended to be imported by the implementations of the specific file stream classes, namely the workstation FS and AlpineFS, and not directly by ordinary clients. Error handling All errors from this package are reported by FS.Error or IO.Error. For FS.Error, the code ATOMs that may be passed are a subset of the ones defined in FS. Only codes in ErrorGroups $client, $lock, and $user are documented below; others can be assumed to arise during any attempted file system access due to conditions not directly under the control of the client or user. Creating a file stream The procedures in this section create a generic stream on an FS.OpenFile of any class, and returns an IO.STREAM handle of class $FS (generic file stream) on which stream operations may be performed. The intended caller of this procedure is the StreamOpen, StreamFromOpenFile, or StreamFromOpenStream procedure of a particular file stream class implementation, namely the workstation FS or AlpineFS. That implementation may modify or extend the semantics by replacing the StreamProcs record in the STREAM object, supplying its own stream procedures for operations that have specialized semantics and using the generic operations from FileStream for the rest. As a practical matter, it is expected that workstation FS streams will employ the generic operations exclusively, and only AlpineFS streams will have special class-specific implementations of certain operations. (To put it another way, the semantics of Alpine streams are a superset of the semantics of workstation FS streams.) ! client: FS.Error[$notImplemented, $wrongLock]; ! user: FS.Error[$cantUpdateTiogaFile]; Creates a new stream on the open file. If accessRights=$read then PutChar, PutBlock, UnsafePutBlock, and SetLength are disallowed on the resulting stream. InitialPosition specifies the initial value of streamIndex: start means 0, end means the file's byte count. ! client: FS.Error[$notImplemented]; Given an existing file stream open for writing (accessRights=$write), creates a new stream on the same file with accessRights=$read. The two streams are then independently positionable, but are internally linked together so that the reader sees data written by the writer. At most one read stream may be linked in this way with any given write stream. Generic operations These are the procedures referenced from the StreamProcs record of the STREAM that FileStream.Create returns. They are also exported explicitly to the FileStream interface so that they may be called directly from the file stream class implementation. For example, for a particular stream class Flush may perform actions in addition to the generic Flush (which just writes out dirty buffers). The Flush procedure for that stream class will call FileStream.Flush directly as part of its implementation. ! IO.EndOfStream, IO.Error[$StreamClosed, $Failure]; ! IO.Error[$StreamClosed, $Failure]; ! IO.Error[$StreamClosed, $Failure]; ! IO.Error[$StreamClosed]; ! IO.Error[$StreamClosed]; ! IO.Error[$StreamClosed, $Failure, $IllegalBackup]; ! IO.Error[$NotImplementedForThisStream, $StreamClosed, $Failure]; ! IO.Error[$NotImplementedForThisStream, $StreamClosed, $Failure]; ! IO.Error[$NotImplementedForThisStream, $StreamClosed, $Failure]; ! IO.Error[$NotImplementedForThisStream, $StreamClosed, $Failure]; ! IO.Error[$NotImplementedForThisStream, $StreamClosed, $Failure, $IllegalBackup]; ! IO.Error[$StreamClosed, $Failure]; ! IO.Error[$StreamClosed, $Failure]; ! IO.Error[$StreamClosed]; ! IO.EndOfStream, IO.Error[$StreamClosed, $Failure, $BadIndex]; ! IO.Error[$StreamClosed]; ! IO.Error[$StreamClosed, $Failure, $BadIndex]; File stream specific operations These procedures apply to all file streams, but are not in the cluster for IO.STREAM so must be called explicitly. The following procedures are intended simply to be re-exported to FS and AlpineFS: ! IO.Error[$NotImplementedForThisStream]; Returns the OpenFile associated with this stream, which must be a file stream. ! IO.Error[$NotImplementedForThisStream]; Returns the error information about the most recent FS-level error involving this stream, which must be a file stream. This procedure is intended to be called by a client who just caught IO.Error[$Failure, self] and wants more detailed information about what went wrong. The remaining procedures are intended to be called only by FS stream class implementations. ! IO.Error[$NotImplementedForThisStream]; Saves the ErrorDesc from an FS.Error for later retrieval by the client. This procedure is intended for use by an FS stream class implementation when it catches FS.Error and raises IO.Error itself. The StreamData record is the same for all classes of file streams, and its representation is private to the generic FileStream implementation. If a particular file stream class requires a place to keep class-specific information, it should define its own private data record and associate it with the stream by means of the following procedures. ! IO.Error[$NotImplementedForThisStream]; ! IO.Error[$NotImplementedForThisStream]; Returns NIL if SetStreamClassData has not been called for this stream instance. Finalization of file streams must be performed in a context in which the STREAM is not known, only the StreamData. Consequently, if any stream class specific finalization is to be performed, it is necessary to register a procedure that will be called as part of StreamData finalization procedure. The procedure is passed only the OpenFile and the the stream class specific data, not the FileStream StreamData record (which is private to FileStream); and it must not call any FileStream facilities or raise any signals. Note: this stuff will go away if the IO package is changed to perform finalization for all STREAMs and call Close on any that haven't already been closed. Data is the stream class data that was established by SetStreamClassData. Closed is TRUE if the stream has already been closed by a client call to IO.Close, and FALSE if the stream is being finalized without the client's having explicitly closed it. ! IO.Error[$NotImplementedForThisStream]; ! IO.Error[$NotImplementedForThisStream]; Returns NIL if SetFinalizationProc has not been called for this stream instance. Κ– "Cedar" style˜code™Kšœ Οmœ1™K™)K™N—š  œžœžœžœžœ ˜