AlpineDirectoryBTree.mesa
Last Edited by: Maxwell, November 23, 1983 9:28 am
DIRECTORY
AlpineDirectory USING [Version, highest, all],
AlpineEnvironment,
AlpTransaction USING [Handle],
BTree USING [PathStk, Tree],
BTreeAlpineVM USING [Handle],
Rope USING [ROPE, Text];
AlpineDirectoryBTree: CEDAR DEFINITIONS = BEGIN
Each entry in the BTree consists of a nameBody, a version, a file or a link, and a keep. The nameBody consists of the sub-directorys and file name; it does not include the volume group name, server, or version number. All version parameters conform to AlpineDirectory.Version. The link may or may not include an explicit version number.
This interface deals mostly with EntryHandles. An EntryHandle contains a copy of the information found in a BTree entry. The suggest style is to use ReadEntry to obtain an entry, modify the parameters in the handle, and then use WriteEntry to put the changes back into the BTree. When you are through with the handle, free it with FreeEntryHandle. A subsequent call may reuse the handle and whatever state that is still valid.
Alpine guarantees atomicity between accesses in different transactions, and there are reader/writer locks in the BTree handle for concurrent accesses within a single transaction. This package guarantees that there is at most one BTree handle in use per BTree per transaction. (There may be more than one entry handle, but they will all use the same BTree handle.)
OPEN AD: AlpineDirectory, AE: AlpineEnvironment;
EntryHandle: TYPE = REF EntryRecord;
EntryRecord: TYPE = RECORD[
found: BOOLFALSE, -- whether or not the entry exists
name: Rope.ROPENIL, -- path name passed in by client
volume: Rope.Text ← NIL, -- the name of the volume group
owner: Rope.Text ← NIL, -- the name of the owner
nameBody: Rope.Text ← NIL, -- subdirectories and filename; no version
desiredVersion: AD.Version ← 0, -- version in the name (includes highest, lowest, and all)
pattern: Rope.ROPENIL, -- pattern used for enumerations
pVolume: Rope.Text ← NIL, -- pattern volume name
pOwner: Rope.Text ← NIL, -- pattern owner name
pNameBody: Rope.Text ← NIL, -- pattern nameBody
pVersion: AD.Version ← 0, -- pattern version (includes highest, lowest, and all)
trans: AlpTransaction.Handle,
volGroupID: AE.VolumeGroupID ← AE.nullVolumeGroupID,
btree: TreeRecord ← [], -- btree and backing storage
pathStk: BTree.PathStk ← NIL, -- a hint to the btree
usePathStk: BOOLFALSE, -- a hint to the btree
directory: BOOLFALSE, -- this is the entry for the directory btree
file: AE.UniversalFile ← AE.nullUniversalFile, -- actual file
link: Rope.Text ← NIL, -- actual link
version: AD.Version ← 0, -- actual version
keep: CARDINAL ← 0, -- actual keep
inUse: EntryHandle ← NIL, -- inUse = NIL => this handle is being used
recentlyInUse: BOOLFALSE -- one bit LRU marker
];
TreeRecord: TYPE = RECORD[
tree: BTree.Tree ← NIL,
storage: BTreeAlpineVM.Handle ← NIL]; -- the backing storage for the btree
ReadEntry: PROC
[trans: AlpTransaction.Handle, name: Rope.ROPE, defaultVersion: AD.Version ← AD.highest, desiredVersion: AD.Version ← AD.all]
RETURNS [entry: EntryHandle];
! Error {illegalFileName, damagedDirectory} plus errors that might be generated from AlpineOwner.ReadProperties, AlpineFile.Open, AlpineFile.Create, AlpineFile.WriteProperties, and AlpineOwner.WriteProperties.
Parses the name, opens the btree and constructs an entry handle for the information there.
If there is no version in the name then defaultVersion is used.
If desiredVersion is highest or lowest then it will override the version given in name.
NextEntry: PROC
[trans: AlpTransaction.Handle, pattern, start: Rope.ROPE, defaultVersion: AD.Version ← AD.all]
RETURNS [entry: EntryHandle];
! Error {illegalFileName, illegalPattern, damagedDirectory} plus errors that generated from AlpineOwner.ReadNext, AlpineOwner.ReadProperties, AlpineFile.Open, AlpineFile.Create, AlpineFile.WriteProperties, and AlpineOwner.WriteProperties.
Gets the entry for start and then enumerates until an entry matching pattern is found.
defaultVersion is the version used if pattern doesn't have a version on it.
WriteEntry: PROC
[entry: EntryHandle];
! Error {damagedDirectory}.
Writes the information stored in the handle into the BTree.
DeleteEntry: PROC
[entry: EntryHandle];
! Error {damagedDirectory}.
Removes the entry from the BTree.
GetDirectory: PROC
[trans: AlpTransaction.Handle, volume: Rope.ROPE, owner: AE.OwnerName]
RETURNS [directory: AE.UniversalFile];
! Errors generated by AlpineOwner.ReadProperties.
FreeEntryHandle: PROC
[entry: EntryHandle];
Allows the handle to be reused. It isn't a disaster if entry handles aren't freed.
FullPathName: PROC
[entry: EntryHandle]
RETURNS[name: Rope.ROPE];
END.