SunNFSClientStub.mesa
Demers, November 4, 1987 0:03:44 am PST
DIRECTORY
RefText USING [New, ReleaseScratch],
RuntimeError USING [BoundsFault],
SunNFS USING [Cookie, cookieSize, create, CreateProc, FAttr, FHandle, fhSize, FileName, FType, getattr, GetattrProc, link, LinkProc, lookup, LookupProc, maxData, maxNameLen, maxPathLen, mkdir, MkdirProc, null, NullProc, program, programVersion, read, readdir, ReaddirProc, readlink, ReadlinkProc, ReadProc, remove, RemoveProc, rename, RenameProc, rmdir, RmdirProc, SAttr, setattr, SetattrProc, Stat, statfs, StatfsProc, symlink, SymlinkProc, write, WriteProc],
SunNFSClient USING [],
SunRPC USING [Error, GetAlign, GetBlock, GetCard32, GetEphemeralRefText, GetRefText, Handle, PutAlign, PutBlock, PutCard32, PutRefText, ReleaseReply, SendCallAndReceiveReply, StartCall]
;
SunNFSClientStub: CEDAR PROGRAM
IMPORTS RefText, RuntimeError, SunRPC
EXPORTS SunNFSClient
~ {
Types
Handle: TYPE ~ SunRPC.Handle;
Parameters
maxData: CARDINAL ~ SunNFS.maxData;
maxPathLen: CARDINAL ~ SunNFS.maxPathLen;
maxNameLen: CARDINAL ~ SunNFS.maxNameLen;
cookieSize: CARDINAL ~ SunNFS.cookieSize;
fhSize: CARDINAL ~ SunNFS.fhSize;
fastTimeout: CARD ← 500;
mediumTimeout: CARD ← 2000;
slowTimeout: CARD ← 5000;
defaultRetries: CARD ← 5;
noRetries: CARD ← 0;
Procedures
Null: PUBLIC SunNFS.NullProc -- [h: Handle, c: Conversation] -- ~ {
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.null];
[] ← SunRPC.SendCallAndReceiveReply[h, fastTimeout, defaultRetries];
SunRPC.ReleaseReply[h];
};
Getattr: PUBLIC SunNFS.GetattrProc -- [h: Handle, c: Conversation, file: FHandle] RETURNS [reply: AttrStat] -- ~ {
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.getattr];
PutFHandle[h, file];
[] ← SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
Get AttrStat
IF (reply.status ← GetStat[h]) = ok THEN reply.attributes ← GetFAttr[h];
SunRPC.ReleaseReply[h];
};
Setattr: PUBLIC SunNFS.SetattrProc -- [h: Handle, c: Conversation, file: FHandle, attributes: SAttr] RETURNS [reply: AttrStat] -- ~ {
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.setattr];
PutFHandle[h, file];
PutSAttr[h, attributes];
[] ← SunRPC.SendCallAndReceiveReply[h, mediumTimeout, noRetries];
Get AttrStat
IF (reply.status ← GetStat[h]) = ok THEN reply.attributes ← GetFAttr[h];
SunRPC.ReleaseReply[h];
};
Lookup: PUBLIC SunNFS.LookupProc -- [h: Handle, c: Conversation, which: DirOpArgs] RETURNS [reply: DirOpRes] -- ~ {
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.lookup];
Put DirOpArgs
PutFHandle[h, which.dir];
SunRPC.PutRefText[h, which.name];
[] ← SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
Get DirOpRes
IF (reply.status ← GetStat[h]) = ok THEN {
reply.file ← GetFHandle[h];
reply.attributes ← GetFAttr[h];
};
SunRPC.ReleaseReply[h];
};
Readlink: PUBLIC SunNFS.ReadlinkProc -- [h: Handle, c: Conversation, file: FHandle] RETURNS [status: Stat, data: Path] -- ~ {
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.readlink];
PutFHandle[h, file];
[] ← SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
IF (status ← GetStat[h]) = ok THEN {
data ← SunRPC.GetRefText[h];
};
SunRPC.ReleaseReply[h];
};
Read: PUBLIC SunNFS.ReadProc -- [h: Handle, c: Conversation, file: FHandle, offset, count, bOffset: CARD, block: REF TEXT] RETURNS [reply: AttrStat] -- ~ {
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.read];
PutFHandle[h, file];
SunRPC.PutCard32[h, offset];
SunRPC.PutCard32[h, count];
SunRPC.PutCard32[h, 0]; -- totalcount (obsolete)
[] ← SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
IF (reply.status ← GetStat[h]) = ok THEN {
bytes: CARD;
reply.attributes ← GetFAttr[h];
bytes ← SunRPC.GetCard32[h];
SunRPC.GetBlock[h, block, bOffset, bytes];
SunRPC.GetAlign[h];
};
SunRPC.ReleaseReply[h];
};
Write: PUBLIC SunNFS.WriteProc -- [h: Handle, c: Conversation, file: FHandle, offset, count, bOffset: CARD, block: REF TEXT] RETURNS [reply: AttrStat] -- ~ {
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.write];
PutFHandle[h, file];
SunRPC.PutCard32[h, 0]; -- beginoffset (obsolete)
SunRPC.PutCard32[h, offset];
SunRPC.PutCard32[h, count]; -- totalcount (obsolete)
SunRPC.PutCard32[h, count];
SunRPC.PutBlock[h, block, bOffset, count];
SunRPC.PutAlign[h, 0];
[] ← SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
IF (reply.status ← GetStat[h]) = ok THEN reply.attributes ← GetFAttr[h];
SunRPC.ReleaseReply[h];
};
Create: PUBLIC SunNFS.CreateProc -- [h: Handle, c: Conversation, where: DirOpArgs, attributes: SAttr] RETURNS [reply: DirOpRes] -- ~ {
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.create];
Put DirOpArgs
PutFHandle[h, where.dir];
SunRPC.PutRefText[h, where.name];
PutSAttr[h, attributes];
[] ← SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
Get DirOpRes
IF (reply.status ← GetStat[h]) = ok THEN {
reply.file ← GetFHandle[h];
reply.attributes ← GetFAttr[h];
};
SunRPC.ReleaseReply[h];
};
Remove: PUBLIC SunNFS.RemoveProc -- [h: Handle, c: Conversation, which: DirOpArgs] RETURNS [status: Stat] -- ~ {
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.remove];
Put DirOpArgs
PutFHandle[h, which.dir];
SunRPC.PutRefText[h, which.name];
[] ← SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
status ← GetStat[h];
SunRPC.ReleaseReply[h];
};
Rename: PUBLIC SunNFS.RenameProc -- [h: Handle, c: Conversation, from, to: DirOpArgs] RETURNS [status: Stat] -- ~ {
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.rename];
Put DirOpArgs
PutFHandle[h, from.dir];
SunRPC.PutRefText[h, from.name];
Put DirOpArgs
PutFHandle[h, to.dir];
SunRPC.PutRefText[h, to.name];
[] ← SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
status ← GetStat[h];
SunRPC.ReleaseReply[h];
};
Link: PUBLIC SunNFS.LinkProc -- [h: Handle, c: Conversation, to: FHandle, as: DirOpArgs] RETURNS [status: Stat] -- ~ {
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.link];
PutFHandle[h, to];
Put DirOpArgs
PutFHandle[h, as.dir];
SunRPC.PutRefText[h, as.name];
[] ← SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
status ← GetStat[h];
SunRPC.ReleaseReply[h];
};
Symlink: PUBLIC SunNFS.SymlinkProc -- [h: Handle, c: Conversation, from: DirOpArgs, to: Path, attributes: SAttr] RETURNS [status: Stat] -- ~ {
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.symlink];
Put DirOpArgs
PutFHandle[h, from.dir];
SunRPC.PutRefText[h, from.name];
SunRPC.PutRefText[h, to];
PutSAttr[h, attributes];
[] ← SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
status ← GetStat[h];
SunRPC.ReleaseReply[h];
};
Mkdir: PUBLIC SunNFS.MkdirProc -- [h: Handle, c: Conversation, where: DirOpArgs, attributes: SAttr] RETURNS [reply: DirOpRes] -- ~ {
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.mkdir];
Put DirOpArgs
PutFHandle[h, where.dir];
SunRPC.PutRefText[h, where.name];
PutSAttr[h, attributes];
[] ← SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
Get DirOpRes
IF (reply.status ← GetStat[h]) = ok THEN {
reply.file ← GetFHandle[h];
reply.attributes ← GetFAttr[h];
};
SunRPC.ReleaseReply[h];
};
Rmdir: PUBLIC SunNFS.RmdirProc -- [h: Handle, c: Conversation, which: DirOpArgs] RETURNS [status: Stat] -- ~ {
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.rmdir];
Put DirOpArgs
PutFHandle[h, which.dir];
SunRPC.PutRefText[h, which.name];
[] ← SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
status ← GetStat[h];
SunRPC.ReleaseReply[h];
};
nilCookie: SunNFS.Cookie;
Readdir: PUBLIC SunNFS.ReaddirProc -- [h: Handle, c: Conversation, dir: FHandle, cookie: Cookie, count: CARD, eachDirEntry: EachDirEntryProc] RETURNS [status: Stat, eof: BOOL, newCookie: Cookie] -- ~ {
fileNameBuf: SunNFS.FileName ← NIL;
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.readdir];
PutFHandle[h, dir];
IF cookie = NIL THEN {
IF (cookie ← nilCookie) = NIL THEN {
cookie ← RefText.New[cookieSize];
cookie.length ← cookieSize;
FOR i: CARDINAL IN [0..cookieSize) DO cookie[i] ← VAL[0] ENDLOOP;
nilCookie ← cookie;
};
};
SunRPC.PutBlock[h, cookie, 0, cookie.length];
SunRPC.PutCard32[h, count];
[] ← SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
IF (status ← GetStat[h]) = ok THEN {
eof ← FALSE;
newCookie ← RefText.New[cookieSize];
WHILE (SunRPC.GetCard32[h] # 0) -- valid -- DO
fileid: CARD ← SunRPC.GetCard32[h];
fileNameBuf ← SunRPC.GetEphemeralRefText[h, fileNameBuf];
SunRPC.GetBlock[h, newCookie, 0, cookieSize];
SunRPC.GetAlign[h];
IF NOT eachDirEntry[fileid, fileNameBuf].continue THEN GOTO Quit;
ENDLOOP;
eof ← (SunRPC.GetCard32[h] # 0);
EXITS
Quit => NULL;
};
IF fileNameBuf # NIL THEN RefText.ReleaseScratch[fileNameBuf];
SunRPC.ReleaseReply[h];
};
Statfs: PUBLIC SunNFS.StatfsProc -- [h: Handle, c: Conversation, file: FHandle] RETURNS [reply: FSAttrStat] -- ~ {
SunRPC.StartCall[h, c, SunNFS.program, SunNFS.programVersion, SunNFS.statfs];
PutFHandle[h, file];
[] ← SunRPC.SendCallAndReceiveReply[h, mediumTimeout, defaultRetries];
IF (reply.status ← GetStat[h]) = ok THEN {
reply.attributes.tsize ← SunRPC.GetCard32[h];
reply.attributes.bsize ← SunRPC.GetCard32[h];
reply.attributes.blocks ← SunRPC.GetCard32[h];
reply.attributes.bfree ← SunRPC.GetCard32[h];
reply.attributes.bavail ← SunRPC.GetCard32[h];
};
SunRPC.ReleaseReply[h];
};
PutSAttr: PROC [h: SunRPC.Handle, sAttr: SunNFS.SAttr] ~ {
SunRPC.PutCard32[h, sAttr.mode];
SunRPC.PutCard32[h, sAttr.uid];
SunRPC.PutCard32[h, sAttr.gid];
SunRPC.PutCard32[h, sAttr.size];
SunRPC.PutCard32[h, sAttr.atime.seconds];
SunRPC.PutCard32[h, sAttr.atime.useconds];
SunRPC.PutCard32[h, sAttr.mtime.seconds];
SunRPC.PutCard32[h, sAttr.mtime.useconds];
};
PutFHandle: PROC [h: SunRPC.Handle, fH: SunNFS.FHandle] ~ INLINE {
SunRPC.PutBlock[h, fH, 0, fH.length];
};
GetFType: PROC [h: SunRPC.Handle] RETURNS [fType: SunNFS.FType] ~ {
fType ← VAL[CARDINAL[SunRPC.GetCard32[h]]];
};
GetFAttr: PROC [h: SunRPC.Handle] RETURNS [attr: SunNFS.FAttr] ~ {
attr.type ← GetFType[h
! RuntimeError.BoundsFault => { attr.type ← non; CONTINUE }];
attr.mode ← SunRPC.GetCard32[h];
attr.nlink ← SunRPC.GetCard32[h];
attr.uid ← SunRPC.GetCard32[h];
attr.gid ← SunRPC.GetCard32[h];
attr.size ← SunRPC.GetCard32[h];
attr.blocksize ← SunRPC.GetCard32[h];
attr.rdev ← SunRPC.GetCard32[h];
attr.blocks ← SunRPC.GetCard32[h];
attr.fsid ← SunRPC.GetCard32[h];
attr.fileid ← SunRPC.GetCard32[h];
attr.atime.seconds ← SunRPC.GetCard32[h];
attr.atime.useconds ← SunRPC.GetCard32[h];
attr.mtime.seconds ← SunRPC.GetCard32[h];
attr.mtime.useconds ← SunRPC.GetCard32[h];
attr.ctime.seconds ← SunRPC.GetCard32[h];
attr.ctime.useconds ← SunRPC.GetCard32[h];
};
GetFHandle: PROC [h: SunRPC.Handle] RETURNS [fH: SunNFS.FHandle] ~ {
fH ← RefText.New[fhSize];
SunRPC.GetBlock[h, fH, 0, fhSize];
};
GetStat: PROC [h: SunRPC.Handle] RETURNS [stat: SunNFS.Stat] ~ INLINE {
ENABLE RuntimeError.BoundsFault => ERROR SunRPC.Error[$protocolError];
stat ← GetStatInner[h];
};
GetStatInner: PROC [h: SunRPC.Handle] RETURNS [SunNFS.Stat] ~ {
RETURN[VAL[CARDINAL[SunRPC.GetCard32[h]]]];
};
}...