-- AltoFileDefs.Mesa  Edited by Sandman on June 30, 1980  4:43 PM
-- Copyright  Xerox Corporation 1979, 1980

DIRECTORY
  AltoDefs USING [BYTE, PageNumber];

AltoFileDefs: DEFINITIONS =
  BEGIN OPEN AltoDefs;

  TIME: TYPE = MACHINE DEPENDENT RECORD [high, low: CARDINAL];

  -- B A S I C  D I S K  S T U F F
  -- virtual disk address

  vDA: TYPE = RECORD [CARDINAL];

  -- vDAs with special meaning

  eofDA: vDA = vDA[177777B];
  fillinDA: vDA = vDA[177776B];

  -- virtual disk command

  vDC: TYPE = {
    ReadHLD, ReadLD, ReadD, WriteHLD, WriteLD, WriteD, SeekOnly, DoNothing};

  -- F I L E  D E S C R I P T O R S
  -- serial number

  SN: TYPE = MACHINE DEPENDENT RECORD [
    bits: SNBits, part1: [0..17777B], part2: CARDINAL];

  SNBits: TYPE = MACHINE DEPENDENT RECORD [directory, random, nolog: [0..1] ← 0];

  DefaultSNBits: SNBits = [0, 0, 0];
  DirSNBits: SNBits = [1, 0, 0];

  NullSN: SN = SN[[1, 0, 1], 17777B, 177777B];

  -- short file pointer

  FP: TYPE = RECORD [serial: SN, leaderDA: vDA];

  NullFP: FP = FP[serial: NullSN, leaderDA: eofDA];

  -- complete file pointer

  CFP: TYPE = MACHINE DEPENDENT RECORD [
    serial: SN, version: CARDINAL, blank: UNSPECIFIED, leaderDA: vDA];

  -- file hint

  FH: TYPE = RECORD [da: vDA, page: PageNumber];

  -- file index

  FI: TYPE = RECORD [page: PageNumber, byte: CARDINAL];

  -- file address

  FA: TYPE = MACHINE DEPENDENT RECORD [da: vDA, page: CARDINAL, byte: CARDINAL];

  -- complete file address

  CFA: TYPE = RECORD [fp: FP, fa: FA];

  -- L E A D E R  P A G E
  -- file properties (sans body)

  FIP: TYPE = MACHINE DEPENDENT RECORD [type, length: BYTE];

  -- leader page (page zero)

  LD: TYPE = MACHINE DEPENDENT RECORD [
    created, written, read: TIME,
    name: ARRAY [0..FilenameWords) OF UNSPECIFIED,
    props: ARRAY [0..210) OF UNSPECIFIED,
    spare: ARRAY
      [0..256 - 3*SIZE[TIME] - FilenameWords - 210 - 2 - SIZE[CFP] - SIZE[FA]) OF
      UNSPECIFIED,
    propBegin, propLength: BYTE,
    consecutive: BOOLEAN,
    blank: [0..177B],
    newSN: BYTE,
    dirFP: CFP,
    eofFA: FA];

  FilePropertyType: TYPE = BYTE;

  DiskShape: FilePropertyType = 1;
  PartitionName: FilePropertyType = 2;

  -- D I S K  D E S C R I P T O R
  -- disk configuration

  DISK: TYPE = MACHINE DEPENDENT RECORD [disks, tracks, heads, sectors: CARDINAL];

  -- disk descriptor (diskKD)

  KD: TYPE = MACHINE DEPENDENT RECORD [
    disk: DISK,
    lastSN: SN,
    changed: WORD,
    size: CARDINAL,
    versions: CARDINAL,
    freePages: CARDINAL, -- hint
    blank: ARRAY [0..6) OF UNSPECIFIED,
    table: ARRAY [0..0) OF WORD];

  -- D I R E C T O R Y
  -- file name lengths

  FilenameChars: INTEGER = 39;
  FilenameWords: INTEGER = 20;

  -- hardwired locators

  DirSN: CARDINAL = 100;
  DirDA: vDA = vDA[1];
  DirFP: FP = FP[SN[DirSNBits, 0, DirSN], DirDA];

  -- directory entry types

  DEfree: INTEGER = 0;
  DEfile: INTEGER = 1;
  DElast: INTEGER = 77B;

  -- directory entry (sans name)

  DV: TYPE = MACHINE DEPENDENT RECORD [
    type: [DEfree..DElast], length: [0..1777B], fp: CFP];

  END.