-- File.mesa (last edited by: Levin on: August 24, 1982 5:14 pm)

DIRECTORY
  Inline USING [BITAND],
  System USING [FileID, nullID, VolumeID],
  Transaction USING [Handle, nullHandle];

File: DEFINITIONS IMPORTS Inline, Transaction =

BEGIN

-- File identifiers, capabilities, and types

ID: TYPE = System.FileID;      -- = RECORD [System.UniversalID]
Capability: TYPE = PRIVATE RECORD [fID: ID, permissions: Permissions];

Permissions: TYPE = [0..32);    -- simulate SET OF {read, write, grow, shrink, delete}
read: Permissions = 1;
write: Permissions = 2;
grow: Permissions = 4;
shrink: Permissions = 8;
delete: Permissions = 16;

nullID: ID = [System.nullID];
nullCapability: Capability = Capability[nullID, 0];

ShowCapability: SAFE PROC [file: Capability] RETURNS [fID: ID, permissions: Permissions] =
  TRUSTED INLINE {RETURN[file.fID, file.permissions]};

LimitPermissions: SAFE PROC [originalFC: Capability, maxPermissions: Permissions]
  RETURNS [lesserFC: Capability] = TRUSTED INLINE
  {RETURN[[originalFC.fID, LOOPHOLE[Inline.BITAND[originalFC.permissions, maxPermissions]]]]};

Type: TYPE = RECORD [CARDINAL];


-- Addressing within a file

maxPagesPerFile: LONG CARDINAL = 8388607; -- = 223 - 1

PageNumber: TYPE = LONG CARDINAL; -- simulate TYPE = [0..maxPagesPerFile);

firstPageNumber: PageNumber = 0;
lastPageNumber: PageNumber = maxPagesPerFile-1;

PageCount: TYPE = LONG CARDINAL; -- simulate TYPE = [0..maxPagesPerFile];

firstPageCount: PageCount = 0;
lastPageCount: PageCount = maxPagesPerFile;


-- Creating, deleting, and moving files

Create: SAFE PROC [
  volume: System.VolumeID, initialSize: PageCount, type: Type, transaction: Transaction.Handle ← Transaction.nullHandle]
  RETURNS [file: Capability];

Delete: PROC [file: Capability, transaction: Transaction.Handle ← Transaction.nullHandle];

Move: PROC [
  file: Capability, volume: System.VolumeID, transaction: Transaction.Handle ← Transaction.nullHandle];


-- Immutable files

MakeImmutable: PROCEDURE [
  file: Capability, transaction: Transaction.Handle ← Transaction.nullHandle];

ReplicateImmutable: SAFE PROC [
  file: Capability, volume: System.VolumeID, transaction: Transaction.Handle ← Transaction.nullHandle];

DeleteImmutable: PROCEDURE [
  file: Capability, volume: System.VolumeID, transaction: Transaction.Handle ← Transaction.nullHandle];


-- Attributes of files

GetSize: SAFE PROC [file: Capability, transaction: Transaction.Handle ← Transaction.nullHandle]
  RETURNS [size: PageCount];

SetSize: PROCEDURE [
  file: Capability, size: PageCount, transaction: Transaction.Handle ← Transaction.nullHandle];

GetAttributes: SAFE PROC [
  file: Capability, transaction: Transaction.Handle ← Transaction.nullHandle]
  RETURNS [type: Type, immutable, temporary: BOOLEAN, volume: System.VolumeID];

MakePermanent: SAFE PROC [
  file: Capability, transaction: Transaction.Handle ← Transaction.nullHandle];


-- Locating files

IsOnVolume: SAFE PROC [file: Capability, volume: System.VolumeID];


-- Signals and errors

Unknown: ERROR [file: Capability];

Error: ERROR [type: ErrorType];

ErrorType: TYPE = {
  insufficientPermissions, immutable, nonuniqueID, notImmutable, reservedType};



END.

LOG

Time: May 5, 1978  9:16 AM	By: Lauer	Action: Created file from Pilot Functional Spec
Time: June 21, 1978  3:17 PM	By: Lauer	Action: Changed value of maxPagesPerFile to correct specification; changed name of "type" parameter to procedure Create
Time: August 3, 1978  12:51 PM	By: Lauer	Action: Added nullID
Time: August 18, 1978  11:54 AM	By: Horsley	Action: Added reservedType to ErrorType
Time: March 7, 1979  10:42 AM	By: Redell	Action: Changed PageNumber and PageCount to LONG CARDINAL, as allowed by Mesa 5.0
Time: March 30, 1979  4:48 PM	By: Redell	Action: Converted ShowCapability and LimitPermissions to inline procedures
Time: April 3, 1979  12:40 PM	By: Redell	Action: Converted LimitPermissions to use Mopcodes directly to avoid importing InlineDefs
Time: March 31, 1980  4:26 PM	By: Gobbel	Action: Added transaction handles
Time: April 15, 1980  3:59 PM	By: Gobbel	Action: Added nullTransactionHandle.
Time: June 16, 1980  2:17 PM	By: McJones	Action: Cleanup
Time: August 24, 1982 5:14 pm	By: Levin	Action: Make things SAFE.