[Top] [Prev] [Next]

styx

Fcall, convS2M, convD2M, convM2S, convM2D, fcallconv, dirconv, dirmodeconv - C interface to Inferno file protocol

Synopsis

#include <lib9.h>
#include <styx.h>
int convS2M    (Fcall *f, char *ap)
int convD2M    (Dir  *d, char *ap)
int convM2S    (char *ap, Fcall *f, int n)
int convM2D    (char *ap, Dir *d)
int dirconv    (va_list *arg, Fconv*)
int fcallconv  (va_list *arg, Fconv*)
int dirmodeconv(va_list *arg, Fconv*)

Description

These C language routines, which reside in the lib9 library convert messages in the machine-independent format of the Inferno file protocol, Styx, to and from a more convenient form, an Fcall structure:

typedef struct Fcall {
     char   type;
     short  fid;
     ushort tag;
     ushort oldtag;      /* T-Flush */
     Qid    qid;         /* R-Attach, R-Walk, R-Open, R-Create */
     char   uname[NAMELEN]; /* T-Attach */
     char   aname[NAMELEN]; /* T-Attach */
     char   ename[ERRLEN];  /* R-Error */
     long   perm;           /* T-Create */
     short  newfid;         /* T-Clone */
     char   name[NAMELEN];  /* T-Walk, T-Create */
     char   mode;           /* T-Create, T-Open */
     long   offset;         /* T-Read, T-Write */
     long   count;          /* T-Read, T-Write, R-Read */
     char   *data;          /* T-Write, R-Read */
     char   stat[DIRLEN];   /* T-Wstat, R-Stat */
 } Fcall; 

This structure is defined in <styx.h>. See the other pages in this section of the manual for a full description of Styx messages and their encoding. For all message types, the type member of an Fcall structure holds one of Tnop, Rnop, Tattach, Rattach, etc. (defined in an enumerated type in <styx.h>). The fid member is used by most messages, and tag is used by all messages. The other fields are used selectively by the message types given in comments.
convM2S (ap, f, n)

The convM2S function takes a Styx message at ap of length n, and uses it to fill in Fcall structure f. If the passed message including any data for Twrite and Rread messages is formatted properly, the return value is n; otherwise it is 0.

For Twrite and Tread messages, f ->data is set to a pointer into the argument message, not a copy.

convS2M (f, ap)

The convS2M does the reverse conversion of the convM2S function, turning f into a message starting at ap. The length of the resulting message is returned.

For Twrite and Rread messages, f ->count bytes starting at f ->data are copied into the message.

The constant MAXMSG (128) is the length of the longest message, excluding data. The constant MAXFDATA (8192) is the maximum count in a read or write message. Thus messages are guaranteed to be shorter than MAXMSG+MAXFDATA bytes long.

Another structure is Dir, used by the routines described in stat.
convM2D (ap, d)

The convM2D function converts the machine-independent form starting at ap into d and returns the length of the encoding.

convD2M (d, ap)

The convD2M function does the reverse translation of the convM2D function. also returning the length of the encoding.

dirconv (arg, Fconv)

Convert a directory buffer, Dir*, to a string representation.

The Inferno emulator installs this function with format letter 'D'.

fcallconv (arg, Fconv)

Convert an Fcall structure, Fcall*, to a string representation.

The Inferno emulator installs this function with format letter 'F'. Moreover, this function assumes that dirconv has been installed, by the Inferno emulator, with format letter 'D'.

dirmodeconv (arg, Fconv)

Convert an long value, to a string representation of the corresponding file mode value.

See Also

Limbo Modules, stat, and Inferno File Protocol, Styx Notes

The offset and directory length fields have 8 bytes in the protocol, but these routines assume they fit into a long.

The convS2M function should check for counts exceeding MAXFMSG.



[Top] [Prev] [Next]

infernosupport@lucent.com
Copyright © 1996,Lucent Technologies, Inc. All rights reserved.