-- File DBFile.mesa
-- Last edited by:
--   MBrown on February 7, 1983 12:10 pm
--   Cattell on July 12, 1982 12:26 pm
--   Willie-Sue on February 3, 1983 10:40 am

  DIRECTORY
    DBCommon,
    Rope USING [ROPE];

DBFile: DEFINITIONS = BEGIN
  ROPE: TYPE = Rope.ROPE;
  Trans: TYPE = DBCommon.Trans;
  VersionOptions: TYPE = DBCommon.VersionOptions;
  OpenFileHandle: TYPE = DBCommon.OpenFileHandle;

  --    Transactions

  FileServerFromFileName: PROC [file: ROPE] RETURNS [server: ROPE];

  CreateTransaction: PROC [server: ROPE] RETURNS [t: Trans];      
    -- Creates a new transaction on the given server, and returns it.  Also returns
    --the welcome text from the file server.

  FinishTransaction: PROC [t: Trans, abort: BOOL, continue: BOOL];
    -- If NOT abort AND continue, then t continues as a valid transaction, all open
    --files remain open, etc, but all updates are committed.

  --    Files

  PagesFromBytes: PROC [bytes: INT] RETURNS [pages: CARDINAL];

  OpenFile: PROC [t: Trans, file: ROPE,
    version: VersionOptions, discardFileContents: BOOL, nPagesInitial: INT, noLog: BOOL]
    RETURNS [f: OpenFileHandle, createdFile: BOOL];
    --  Creates an "open file" f, that is used to access file "file" under transaction "t".
    -- If version = NewFileOnly or None, will create file of nPagesInitial pages if necessary.
    -- (The full path name must contain enough information, and must be consistent with
    -- transaction t).  If discardFileContents, then the contents of the open file are
    -- undefined (and performance may be considerably better).  If noLog, then file updates
    -- need not be recoverable until after transaction commit.

  ReadFilePage: PROC [f: OpenFileHandle, p: CARDINAL, corePage: LONG POINTER];
  --  Reads page p of file f into corePage.  The page size is given by
  --DBCommon.WordsPerPage.

  WriteFilePage: PROC [f: OpenFileHandle, p: CARDINAL, corePage: LONG POINTER];
  --  Writes corePage onto page p of file f.  Raises ERROR if the user who opened f does
  --not have write access to f.  The page size is given by DBCommon.WordsPerPage.

  GetSize: PROC [f: OpenFileHandle] RETURNS [nPages: CARDINAL];
  -- Returns the size of the file (in pages).
  -- If the length of the file is not multiple of 512 bytes, ERROR Fatal[IllegalFileLength] is
  --raised.

  SetSize: PROC [f: OpenFileHandle, nPages: CARDINAL];
  --  Sets the size (number of pages) of the file.


  END.


--  Module History

Created by MBrown on January 4, 1980  2:46 PM
-- Adopted in meeting of 4 January.

Changed by Suzuki on January 14, 1980  2:33 PM
-- Suffixes Defs are deleted

Changed by Suzuki on January 14, 1980  3:48 PM
-- Added EnumerateBrokenReadLocks.

Changed by Suzuki on January 24, 1980  9:01 AM
-- Changed the arguments to BeginTransaction.

Changed by Suzuki on January 24, 1980  9:47 AM
-- Added the procedure ReleaseBrokenReadLock.

Changed by MBrown on August 5, 1980  11:02 PM
-- Added the procedure CloseFile, for use by CloseDatabase.

Changed by MBrown on August 29, 1980  2:51 PM
-- Added the server parm to BeginTransaction, for use in contacting test Juniper
--servers.

Changed by MBrown on September 3, 1980  9:41 PM
-- Changed type of lfh to POINTER for now; later this will come from UserPineDefs, NOT
--ServerPineDefs as it was before.  Ran through formatter.

Changed by MBrown on December 11, 1980  7:16 PM
-- Flushed RegisterUser.

Changed by MBrown on February 26, 1981  9:44 PM
-- Defined types Transaction and FileHandle for multiple file systems (the big LOOPHOLE).

Changed by MBrown on 19-Jun-81 14:29:22
-- STRING -> Rope.Ref.

Changed by Willie-Sue on June 24, 1982 12:10 pm
--  Rope.Ref -> Rope.ROPE

Changed by Cattell on July 12, 1982 12:26 pm
-- Changed definition of File and Transaction.  File is now FileHandle because of
--conflict with File interface.  Transaction is now DBCommon.Transaction because
--of conflict with Transaction interface.  Files are now variant records, as are
--transactions.  These changes affect DBFileJuniperImpl, DBFilePilotImpl,
--DBCommon, etc.

Changed by MBrown on November 29, 1982 10:48 am
--  Major changes to allow simultaneous access to multiple file servers.

Changed by Willie-Sue on February 3, 1983 10:40 am
--  Added noLog arg to OpenFile.