styx: aqwari.net/net/styx/styxproto Index | Examples | Files

package styxproto

import "aqwari.net/net/styx/styxproto"

Package styxproto provides low-level routines for parsing and producing 9P2000 messages.

The styxproto package is to be used for making higher-level 9P2000 libraries. The parsing routines within make very few assumptions or decisions, so that it may be used for a wide variety of higher-level packages. When decoding messages, memory usage is bounded using a fixed-size buffer. This allows servers using the styxproto package to have predictable resource usage based on the number of connections.

To minimize allocations, the styxproto package does not decode messages. Instead, messages are validated and wrapped with convenient accessor methods.

Index

Examples

Package Files

decoder.go doc.go encoder.go enum.go errors.go limits.go pack.go parse.go proto.go qid.go stat.go verify.go

Constants

const (
    OREAD   = 0  // open read-only
    OWRITE  = 1  // open write-only
    ORDWR   = 2  // open read-write
    OEXEC   = 3  // execute (== read but check execute permission)
    OTRUNC  = 16 // or'ed in (except for exec), truncate file first
    OCEXEC  = 32 // or'ed in, close on exec
    ORCLOSE = 64 // or'ed in, remove on close
)

Flags for the mode field in Topen and Tcreate messages

const (
    DMDIR    = 0x80000000 // mode bit for directories
    DMAPPEND = 0x40000000 // mode bit for append only files
    DMEXCL   = 0x20000000 // mode bit for exclusive use files
    DMMOUNT  = 0x10000000 // mode bit for mounted channel
    DMAUTH   = 0x08000000 // mode bit for authentication file
    DMTMP    = 0x04000000 // mode bit for non-backed-up file
    DMREAD   = 0x4        // mode bit for read permission
    DMWRITE  = 0x2        // mode bit for write permission
    DMEXEC   = 0x1        // mode bit for execute permission

    // Mask for the type bits
    DMTYPE = DMDIR | DMAPPEND | DMEXCL | DMMOUNT | DMTMP

    // Mask for the permissions bits
    DMPERM = DMREAD | DMWRITE | DMEXEC
)

File modes

const (
    QTDIR    = 0x80 // directories
    QTAPPEND = 0x40 // append only files
    QTEXCL   = 0x20 // exclusive use files
    QTMOUNT  = 0x10 // mounted channel
    QTAUTH   = 0x08 // authentication file (afid)
    QTTMP    = 0x04 // non-backed-up file
    QTFILE   = 0x00
)

A Qid's type field represents the type of a file (directory, etc.), represented as a bit vector corresponding to the high 8 bits of the file's mode word.

const DefaultBufSize = 8192

DefaultBufSize is the default buffer size used in a Decoder

const DefaultMaxSize = 8 * megabyte

DefaultMaxSize is the default maximum size of a 9P message.

const IOHeaderSize = 4 + 1 + 2 + 4 + 8 + 4

IOHeaderSize is the length of all fixed-width fields in a Twrite or Tread message. Twrite and Tread messages are defined as

size[4] Twrite tag[2] fid[4] offset[8] count[4] data[count]
size[4] Tread  tag[2] fid[4] offset[8] count[4]
const MaxAttachLen = 255

MaxAttachLen is the maximum length (in bytes) of the aname field of Tattach and Tauth requests.

const MaxErrorLen = 512

MaxErrorLen is the maximum length (in bytes) of the Ename field in an Rerror message.

const MaxFileLen = 1<<63 - 1

MaxFileLen is the maximum length of a single file. While the 9P protocol supports files with a length of up to 8 EB (exabytes), to reduce the risk of overflow errors, the styxproto package only supports lengths of up to 4 EB so that it may fit within a signed 64-bit integer.

const MaxFilenameLen = 255

MaxFilenameLen is the maximum length of a file name in bytes

const MaxOffset = 1<<63 - 1

MaxOffset is the maximum value of the offset field in Tread and Twrite requests

const MaxStatLen = minStatLen + MaxFilenameLen + (MaxUidLen * 3)

MaxStatLen is the maximum size of a Stat structure.

const MaxUidLen = 45

MaxUidLen is the maximum length (in bytes) of a username or group identifier.

const MaxVersionLen = 20

MaxVersionLen is the maximum length of the protocol version string in bytes

const MaxWElem = 16

MaxWElem is the maximum allowed number of path elements in a Twalk request

const MinBufSize = MaxWElem*(MaxFilenameLen+2) + 13 + 4

MinBufSize is the minimum size (in bytes) of the internal buffers in a Decoder.

const NoFid = ^uint32(0)

NoFid is a reserved fid used in a Tattach request for the afid field, that indicates that the client does not wish to authenticate his session.

const NoTag = ^uint16(0)

NoTag is the tag for Tversion and Rversion requests.

const QidLen = 13

QidLen is the length of a Qid in bytes.

Variables

var ErrMaxSize = errors.New("message exceeds msize")

ErrMaxSize is returned during the parsing process if a message exceeds the maximum size negotiated during the Tversion/Rversion transaction.

func Write Uses

func Write(w io.Writer, m Msg) (written int64, err error)

Write writes the 9P protocol message to w. It returns the number of bytes written, along with any errors.

type BadMessage Uses

type BadMessage struct {
    Err error // the reason the message is invalid
    // contains filtered or unexported fields
}

BadMessage represents an invalid message.

func (BadMessage) Len Uses

func (m BadMessage) Len() int64

func (BadMessage) String Uses

func (m BadMessage) String() string

func (BadMessage) Tag Uses

func (m BadMessage) Tag() uint16

Tag returns the tag of the errant message. Servers should cite the same tag when replying with an Rerror message.

type Decoder Uses

type Decoder struct {
    // MaxSize is the maximum size message that a Decoder will accept. If
    // MaxSize is -1, a Decoder will accept any size message.
    MaxSize int64
    // contains filtered or unexported fields
}

A Decoder provides an interface for reading a stream of 9P messages from an io.Reader. Successive calls to the Next method of a Decoder will fetch and validate 9P messages from the input stream, until EOF is encountered, or another error is encountered.

A Decoder is not safe for concurrent use. Usage of any Decoder method should be delegated to a single thread of execution or protected by a mutex.

Code:

l, err := net.Listen("tcp", ":564")
if err != nil {
    log.Fatal(err)
}
rwc, err := l.Accept()
if err != nil {
    log.Fatal(err)
}

d := styxproto.NewDecoder(rwc)
e := styxproto.NewEncoder(rwc)
for d.Next() {
    switch msg := d.Msg().(type) {
    case styxproto.Tversion:
        log.Printf("Client wants version %s", msg.Version())
        e.Rversion(8192, "9P2000")
    case styxproto.Tread:
        e.Rread(msg.Tag(), []byte("data data"))
    case styxproto.Twrite:
        log.Printf("Receiving %d bytes from client", msg.Count())
        io.Copy(ioutil.Discard, msg)
    }
}

func NewDecoder Uses

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a Decoder with an internal buffer of size DefaultBufSize.

func NewDecoderSize Uses

func NewDecoderSize(r io.Reader, bufsize int) *Decoder

NewDecoderSize returns a Decoder with an internal buffer of size max(MinBufSize, bufsize) bytes. A Decoder with a larger buffer can provide more 9P messages at once, if they are available. This may improve performance on connections that are heavily multiplexed, where there messages from independent sessions that can be handled in any order.

func (*Decoder) Err Uses

func (s *Decoder) Err() error

Err returns the first error encountered during parsing. If the underyling io.Reader was closed in the middle of a message, Err will return io.ErrUnexpectedEOF. Otherwise, io.EOF is not considered to be an error, and is not relayed by Err.

Invalid messages are not considered errors, and are represented in the Messages slice as values of type BadMessage. Only problems with the underlying io.Reader are considered errors.

func (*Decoder) Msg Uses

func (s *Decoder) Msg() Msg

Msg returns the last 9P message decoded in the stream. It returns a non-nil message if and only if the last call to the Decoder's Next method returned true. The return value of Msg is only valid until the next call to a decoder's Next method.

func (*Decoder) Next Uses

func (s *Decoder) Next() bool

Next fetches the next 9P message from the Decoder's underlying io.Reader. If an error is encountered reading from the underlying stream, Next will return false, and the Decoder's Err method will return the first error encountered.

If Next returns true, the Msg method of the Decoder will return the decoded 9P message.

func (*Decoder) Reset Uses

func (s *Decoder) Reset(r io.Reader)

Reset resets a Decoder with a new io.Reader.

type Encoder Uses

type Encoder struct {
    MaxSize int64
    // contains filtered or unexported fields
}

An Encoder writes 9P messages to an underlying io.Writer.

func NewEncoder Uses

func NewEncoder(w io.Writer) *Encoder

NewEncoder creates a new Encoder that writes 9P messages to w. Encoders are safe to use from multiple goroutines. An Encoder does not perform any buffering of messages.

func (*Encoder) Err Uses

func (enc *Encoder) Err() error

Err returns the first error encountered by an Encoder when writing data to its underlying io.Writer.

func (*Encoder) Flush Uses

func (enc *Encoder) Flush() error

Flush flushes any buffered data to the underlying io.Writer.

func (*Encoder) Rattach Uses

func (enc *Encoder) Rattach(tag uint16, qid Qid)

Rattach writes a new Rattach message to the underlying io.Writer.

func (*Encoder) Rauth Uses

func (enc *Encoder) Rauth(tag uint16, qid Qid)

Rauth writes a new Rauth message to the underlying io.Writer.

func (*Encoder) Rclunk Uses

func (enc *Encoder) Rclunk(tag uint16)

Rclunk writes an Rclunk message to the underlying io.Writer.

func (*Encoder) Rcreate Uses

func (enc *Encoder) Rcreate(tag uint16, qid Qid, iounit uint32)

Rcreate writes a new Rcreate message to the underlying io.Writer.

func (*Encoder) Rerror Uses

func (enc *Encoder) Rerror(tag uint16, errfmt string, v ...interface{})

Rerror writes a new Rerror message to the underlying io.Writer. Errfmt may be a printf-style format string, with values filled in from the argument list v. If the error string is longer than MaxErrorLen bytes, it is truncated.

func (*Encoder) Rflush Uses

func (enc *Encoder) Rflush(tag uint16)

Rflush writes a new Rflush message to the underlying io.Writer.

func (*Encoder) Ropen Uses

func (enc *Encoder) Ropen(tag uint16, qid Qid, iounit uint32)

Ropen writes a new Ropen message to the underlying io.Writer.

func (*Encoder) Rread Uses

func (enc *Encoder) Rread(tag uint16, data []byte) (n int, err error)

Rread writes a new Rread message to the underlying io.Writer. If len(data) is greater than the Encoder's Msize, it is broken up into multiple Rread messages. Rread returns the number of bytes written, plus any IO errors encountered.

func (*Encoder) Rremove Uses

func (enc *Encoder) Rremove(tag uint16)

Rremove writes an Rremove message to the underlying io.Writer.

func (*Encoder) Rstat Uses

func (enc *Encoder) Rstat(tag uint16, stat Stat)

Rstat writes an Rstat message to the underlying io.Writer. If the Stat is larger than the maximum size allowed by the NewStat function, a run-time panic occurs.

func (*Encoder) Rversion Uses

func (enc *Encoder) Rversion(msize uint32, version string)

Rversion writes an Rversion message to the underlying io.Writer. If the version string is longer than MaxVerisonLen, it is truncated.

func (*Encoder) Rwalk Uses

func (enc *Encoder) Rwalk(tag uint16, wqid ...Qid) error

Rwalk writes a new Rwalk message to the underlying io.Writer. An error is returned if wqid has more than MaxWElem elements.

func (*Encoder) Rwrite Uses

func (enc *Encoder) Rwrite(tag uint16, count int64)

Rwrite writes an Rwrite message to the underlying io.Writer. If count is greater than the maximum value of a 32-bit unsigned integer, a run-time panic occurs.

func (*Encoder) Rwstat Uses

func (enc *Encoder) Rwstat(tag uint16)

Rwstat writes an Rwstat message to the underlying io.Writer.

func (*Encoder) Tattach Uses

func (enc *Encoder) Tattach(tag uint16, fid, afid uint32, uname, aname string)

Tattach writes a new Tattach message to the underlying io.Writer. If the client does not want to authenticate, afid should be NoFid. The uname and aname parameters will be truncated if they are longer than MaxUidLen and MaxAttachLen, respectively.

func (*Encoder) Tauth Uses

func (enc *Encoder) Tauth(tag uint16, afid uint32, uname, aname string)

Tauth writes a Tauth message to enc's underlying io.Writer. The uname and aname parameters will be truncated if they are longer than MaxUidLen and MaxAttachLen, respectively.

func (*Encoder) Tclunk Uses

func (enc *Encoder) Tclunk(tag uint16, fid uint32)

Tclunk writes a Tclunk message to the underlying io.Writer.

func (*Encoder) Tcreate Uses

func (enc *Encoder) Tcreate(tag uint16, fid uint32, name string, perm uint32, mode uint8)

Tcreate writes a new Tcreate message to the underlying io.Writer. If name is longer than MaxFilenameLen, it is truncated.

func (*Encoder) Tflush Uses

func (enc *Encoder) Tflush(tag, oldtag uint16)

Tflush writes a new Tflush message to the underlying io.Writer.

func (*Encoder) Topen Uses

func (enc *Encoder) Topen(tag uint16, fid uint32, mode uint8)

NewTopen writes a new Topen message to the underlying io.Writer.

func (*Encoder) Tread Uses

func (enc *Encoder) Tread(tag uint16, fid uint32, offset, count int64) error

Tread writes a new Tread message to the underlying io.Writer. An error is returned if count is greater than the maximum value of a 32-bit unsigned integer.

func (*Encoder) Tremove Uses

func (enc *Encoder) Tremove(tag uint16, fid uint32)

Tremove writes a Tremove message to the underlying io.Writer.

func (*Encoder) Tstat Uses

func (enc *Encoder) Tstat(tag uint16, fid uint32)

Tstat writes a Tstat message to the underlying io.Writer.

func (*Encoder) Tversion Uses

func (enc *Encoder) Tversion(msize uint32, version string)

Tversion writes a Tversion message to the underlying io.Writer. The Tag of the written message will be NoTag. If the version string is longer than MaxVersionLen, it is truncated.

func (*Encoder) Twalk Uses

func (enc *Encoder) Twalk(tag uint16, fid, newfid uint32, wname ...string) error

Twalk writes a new Twalk message to the underlying io.Writer. An error is returned if wname is longer than MaxWElem elements, or if any single element in wname is longer than MaxFilenameLen bytes long.

func (*Encoder) Twrite Uses

func (enc *Encoder) Twrite(tag uint16, fid uint32, offset int64, data []byte) (int, error)

Twrite writes a Twrite message to the underlying io.Writer. An error is returned if the message cannot fit inside a single 9P message.

func (*Encoder) Twstat Uses

func (enc *Encoder) Twstat(tag uint16, fid uint32, stat Stat)

Twstat writes a Twstat message to the underlying io.Writer. If the Stat is larger than the maximum size allowed by the NewStat function, a run-time panic occurs.

type Msg Uses

type Msg interface {
    // Tag is a transaction identifier. No two pending T-messages may
    // use the same tag. All R-messages must reference the T-message
    // being answered by using the same tag.
    Tag() uint16

    // Len returns the total length of the message in bytes.
    Len() int64
    // contains filtered or unexported methods
}

A Msg is a 9P message. 9P messages are sent by clients (T-messages) and servers (R-messages).

type Qid Uses

type Qid []byte

A Qid represents the server's unique identification for the file being accessed: two files on the same server hierarchy are the same if and only if their qids are the same.

func NewQid Uses

func NewQid(buf []byte, qtype uint8, version uint32, path uint64) (Qid, []byte, error)

NewQid writes the 9P representation of a Qid to buf. If buf is not long enough to hold a Qid (13 bytes), io.ErrShortBuffer is returned. NewQid returns any remaining space in buf after the Qid has been written.

Code:

buf := make([]byte, 13)
qid, buf, err := styxproto.NewQid(buf, 1, 369, 0x84961)
if err != nil {
    log.Fatal(err)
}
fmt.Println(qid)

Output:

type=1 ver=369 path=84961

func (Qid) Path Uses

func (q Qid) Path() uint64

Path is an integer unique among all files in the hierarchy. If a file is deleted and recreated with the same name in the same directory, the old and new path components of the qids should be different.

func (Qid) String Uses

func (q Qid) String() string

func (Qid) Type Uses

func (q Qid) Type() uint8

Type returns the type of a file (directory, etc)

func (Qid) Version Uses

func (q Qid) Version() uint32

Version is a version number for a file; typically, it is incremented every time a file is modified. By convention, synthetic files usually have a verison number of 0. Traditional files have a version number that is a hash of their modification time.

type Rattach Uses

type Rattach []byte

The Rattach message contains a server's reply to a Tattach request. As a result of the attach transaction, the client will have a connection to the root directory of the desired file tree, represented by the returned qid.

func (Rattach) Len Uses

func (m Rattach) Len() int64

func (Rattach) Qid Uses

func (m Rattach) Qid() Qid

Qid is the qid of the root of the file tree. Qid is associated with the fid of the corresponding Tattach request.

func (Rattach) String Uses

func (m Rattach) String() string

func (Rattach) Tag Uses

func (m Rattach) Tag() uint16

type Rauth Uses

type Rauth []byte

Servers that require authentication will reply to Tauth requests with an Rauth message. If a server does not require authentication, it can reply to a Tauth message with an Rerror message.

func (Rauth) Aqid Uses

func (m Rauth) Aqid() Qid

The aqid of an Rauth message must be of type QTAUTH.

func (Rauth) Len Uses

func (m Rauth) Len() int64

func (Rauth) String Uses

func (m Rauth) String() string

func (Rauth) Tag Uses

func (m Rauth) Tag() uint16

type Rclunk Uses

type Rclunk []byte

func (Rclunk) Len Uses

func (m Rclunk) Len() int64

func (Rclunk) String Uses

func (m Rclunk) String() string

func (Rclunk) Tag Uses

func (m Rclunk) Tag() uint16

type Rcreate Uses

type Rcreate []byte

func (Rcreate) IOunit Uses

func (m Rcreate) IOunit() int64

func (Rcreate) Len Uses

func (m Rcreate) Len() int64

func (Rcreate) Qid Uses

func (m Rcreate) Qid() Qid

func (Rcreate) String Uses

func (m Rcreate) String() string

func (Rcreate) Tag Uses

func (m Rcreate) Tag() uint16

type Rerror Uses

type Rerror []byte

The Rerror message (there is no Terror) is used to return an error string describing the failure of a transaction.

func (Rerror) Ename Uses

func (m Rerror) Ename() []byte

Ename is a UTF-8 string describing the error that occured.

func (Rerror) Err Uses

func (m Rerror) Err() error

Err creates a new value of type error using an Rerror message.

func (Rerror) Len Uses

func (m Rerror) Len() int64

func (Rerror) String Uses

func (m Rerror) String() string

func (Rerror) Tag Uses

func (m Rerror) Tag() uint16

An Rerror message replaces the corresponding reply message that would accom- pany a successful call; its tag is that of the failing request.

type Rflush Uses

type Rflush []byte

A server should answer a Tflush message immediately with an Rflush message that echoes the tag (not oldtag) of the Tflush message. If it recognizes oldtag as the tag of a pending transaction, it should abort any pending response and discard that tag. A Tflush can never be responded to with an Rerror message.

func (Rflush) Len Uses

func (m Rflush) Len() int64

func (Rflush) String Uses

func (m Rflush) String() string

func (Rflush) Tag Uses

func (m Rflush) Tag() uint16

type Ropen Uses

type Ropen []byte

An Ropen message contains a servers response to a Topen request. An Ropen message is only sent if the server determined that the requesting user had the proper permissions required for the Topen to succeed, otherwise Rerror is returned.

func (Ropen) IOunit Uses

func (m Ropen) IOunit() int64

The iounit field returned by open and create may be zero. If it is not, it is the maximum number of bytes that are guaranteed to be read from or written to the file without breaking the I/O transfer into multiple 9P messages

func (Ropen) Len Uses

func (m Ropen) Len() int64

func (Ropen) Qid Uses

func (m Ropen) Qid() Qid

Qid contains the unique identifier of the opened file.

func (Ropen) String Uses

func (m Ropen) String() string

func (Ropen) Tag Uses

func (m Ropen) Tag() uint16

type Rread Uses

type Rread struct {
    // contains filtered or unexported fields
}

The Rread message returns the bytes requested by a Tread message. The data portion of an Rread message can be consumed using the io.Reader interface.

func (Rread) Count Uses

func (m Rread) Count() int64

func (Rread) Len Uses

func (m Rread) Len() int64

func (Rread) Read Uses

func (m Rread) Read(p []byte) (int, error)

Read copies len(p) bytes from an Rread message's data field into p. It returns the number of bytes copied and an error, if any.

func (Rread) String Uses

func (m Rread) String() string

func (Rread) Tag Uses

func (m Rread) Tag() uint16

If a Tread requests asks for more data than can fit within a single 9P message, multiple Rread messages will be generated that cite the tag of a single Tread request.

type Rremove Uses

type Rremove []byte

func (Rremove) Len Uses

func (m Rremove) Len() int64

func (Rremove) String Uses

func (m Rremove) String() string

func (Rremove) Tag Uses

func (m Rremove) Tag() uint16

type Rstat Uses

type Rstat []byte

func (Rstat) Len Uses

func (m Rstat) Len() int64

func (Rstat) Stat Uses

func (m Rstat) Stat() Stat

func (Rstat) String Uses

func (m Rstat) String() string

func (Rstat) Tag Uses

func (m Rstat) Tag() uint16

type Rversion Uses

type Rversion []byte

An Rversion reply is sent in response to a Tversion request. It contains the version of the protocol that the server has chosen, and the maximum size of all successive messages.

func (Rversion) Len Uses

func (m Rversion) Len() int64

Len returns the length of the Rversion message in bytes.

func (Rversion) Msize Uses

func (m Rversion) Msize() int64

Msize returns the maximum size (in bytes) of any 9P message that it will send or accept, and must be equal to or less than the maximum suggested in the preceding Tversion message. After the Rversion message is received, both sides of the connection must honor this limit.

func (Rversion) String Uses

func (m Rversion) String() string

func (Rversion) Tag Uses

func (m Rversion) Tag() uint16

Tag must return the tag of the corresponding Tversion message, NoTag.

func (Rversion) Version Uses

func (m Rversion) Version() []byte

Version identifies the level of the protocol that the server supports. If a server does not understand the protocol version sent in a Tversion message, Version will return the string "unknown". A server may choose to specify a version that is less than or equal to that supported by the client.

type Rwalk Uses

type Rwalk []byte

An Rwalk message contains a server's reply to a successful Twalk request. If the first path in the corresponding Twalk request cannot be walked, an Rerror message is returned instead.

func (Rwalk) Len Uses

func (m Rwalk) Len() int64

func (Rwalk) Nwqid Uses

func (m Rwalk) Nwqid() int

Nwqid must always be equal to or lesser than Nwname of the corresponding Twalk request. Only if Nwqid is equal to Nwname is the Newfid of the Twalk request established. Nwqid must always be greater than zero.

func (Rwalk) String Uses

func (m Rwalk) String() string

func (Rwalk) Tag Uses

func (m Rwalk) Tag() uint16

func (Rwalk) Wqid Uses

func (m Rwalk) Wqid(n int) Qid

Wqid contains the Qid values of each path in the walk requested by the client, up to the first failure.

type Rwrite Uses

type Rwrite []byte

func (Rwrite) Count Uses

func (m Rwrite) Count() uint32

func (Rwrite) Len Uses

func (m Rwrite) Len() int64

func (Rwrite) String Uses

func (m Rwrite) String() string

func (Rwrite) Tag Uses

func (m Rwrite) Tag() uint16

type Rwstat Uses

type Rwstat []byte

func (Rwstat) Len Uses

func (m Rwstat) Len() int64

func (Rwstat) String Uses

func (m Rwstat) String() string

func (Rwstat) Tag Uses

func (m Rwstat) Tag() uint16

type Stat Uses

type Stat []byte

The Stat structure describes a directory entry. It is contained in Rstat and Twstat messages. Tread requests on directories return a Stat structure for each directory entry. A Stat implements the os.FileInfo interface.

func NewStat Uses

func NewStat(buf []byte, name, uid, gid, muid string) (Stat, []byte, error)

NewStat creates a new Stat structure. The name, uid, gid, and muid fields affect the size of the stat-structure and should be considered read-only once the Stat is created. An error is returned if name is more than MaxFilenameLen bytes long or uid, gid, or muid are more than MaxUidLen bytes long. Additional fields in the Stat structure can be set by using the appropriate Set method on the Stat value.

Code:

buf := make([]byte, 100)
s, buf, err := styxproto.NewStat(buf, "messages.log", "root", "wheel", "")
if err != nil {
    log.Fatal(err)
}
s.SetLength(309)
s.SetMode(0640)
fmt.Println(s)

Output:

type=0 dev=0 qid="type=0 ver=0 path=0" mode=640 atime=0 mtime=0 length=309 name="messages.log" uid="root" gid="wheel" muid=""

func (Stat) Atime Uses

func (s Stat) Atime() uint32

Atime returns the last access time for the file, in seconds since the epoch.

func (Stat) Dev Uses

func (s Stat) Dev() uint32

The 4-byte dev field contains implementation-specific data that is outside the scope of the 9P protocol. In Plan 9, it holds an identifier for the block device that stores the file.

func (Stat) Gid Uses

func (s Stat) Gid() []byte

Gid returns the group of the file.

func (Stat) Length Uses

func (s Stat) Length() int64

Length returns the length of the file in bytes.

func (Stat) Mode Uses

func (s Stat) Mode() uint32

Mode contains the permissions and flags set for the file. Permissions follow the unix model; the 3 least-significant 3-bit triads describe read, write, and execute access for owners, group members, and other users, respectively.

func (Stat) Mtime Uses

func (s Stat) Mtime() uint32

Mtime returns the last time the file was modified, in seconds since the epoch.

func (Stat) Muid Uses

func (s Stat) Muid() []byte

Muid returns the name of the user who last modified the file

func (Stat) Name Uses

func (s Stat) Name() []byte

Name returns the name of the file.

func (Stat) Qid Uses

func (s Stat) Qid() Qid

Qid returns the unique identifier of the file.

func (Stat) SetAtime Uses

func (s Stat) SetAtime(t uint32)

func (Stat) SetDev Uses

func (s Stat) SetDev(d uint32)

func (Stat) SetLength Uses

func (s Stat) SetLength(n int64)

func (Stat) SetMode Uses

func (s Stat) SetMode(m uint32)

func (Stat) SetMtime Uses

func (s Stat) SetMtime(t uint32)

func (Stat) SetQid Uses

func (s Stat) SetQid(q Qid)

func (Stat) SetType Uses

func (s Stat) SetType(t uint16)

func (Stat) String Uses

func (s Stat) String() string

func (Stat) Type Uses

func (s Stat) Type() uint16

The 2-byte type field contains implementation-specific data that is outside the scope of the 9P protocol.

func (Stat) Uid Uses

func (s Stat) Uid() []byte

Uid returns the name of the owner of the file.

type Tattach Uses

type Tattach []byte

The attach message serves as a fresh introduction from a user on the client machine to the server.

func (Tattach) Afid Uses

func (m Tattach) Afid() uint32

On servers that require authentication, afid serves to authenticate a user, and must have been established in a previous Tauth request. If a client does not wish to authenticate, afid should be set to NoFid.

func (Tattach) Aname Uses

func (m Tattach) Aname() []byte

Aname is the name of the file tree that the client wants to access.

func (Tattach) Fid Uses

func (m Tattach) Fid() uint32

Fid establishes a fid to be used as the root of the file tree, should the client's Tattach request be accepted.

func (Tattach) Len Uses

func (m Tattach) Len() int64

func (Tattach) String Uses

func (m Tattach) String() string

func (Tattach) Tag Uses

func (m Tattach) Tag() uint16

func (Tattach) Uname Uses

func (m Tattach) Uname() []byte

Uname is the user name of the attaching user.

type Tauth Uses

type Tauth []byte

The Tauth message is used to authenticate users on a connection.

func (Tauth) Afid Uses

func (m Tauth) Afid() uint32

The afid of a Tversion message establishes an 'authentication file'; after a Tauth message is accepted by the server, a client must carry out the authentication protocol by performing I/O operations on afid. Any protocol may be used and authentication is outside the scope of the 9P protocol.

func (Tauth) Aname Uses

func (m Tauth) Aname() []byte

The aname field contains the name of the file tree to access. It may be empty.

func (Tauth) Len Uses

func (m Tauth) Len() int64

func (Tauth) String Uses

func (m Tauth) String() string

func (Tauth) Tag Uses

func (m Tauth) Tag() uint16

func (Tauth) Uname Uses

func (m Tauth) Uname() []byte

The uname field contains the name of the user to authenticate.

type Tclunk Uses

type Tclunk []byte

The clunk request informs the file server that the current file represented by fid is no longer needed by the client. The actual file is not removed on the server unless the fid had been opened with ORCLOSE.

func (Tclunk) Fid Uses

func (m Tclunk) Fid() uint32

func (Tclunk) Len Uses

func (m Tclunk) Len() int64

func (Tclunk) String Uses

func (m Tclunk) String() string

func (Tclunk) Tag Uses

func (m Tclunk) Tag() uint16

type Tcreate Uses

type Tcreate []byte

func (Tcreate) Fid Uses

func (m Tcreate) Fid() uint32

func (Tcreate) Len Uses

func (m Tcreate) Len() int64

func (Tcreate) Mode Uses

func (m Tcreate) Mode() uint8

func (Tcreate) Name Uses

func (m Tcreate) Name() []byte

func (Tcreate) Perm Uses

func (m Tcreate) Perm() uint32

func (Tcreate) String Uses

func (m Tcreate) String() string

func (Tcreate) Tag Uses

func (m Tcreate) Tag() uint16

type Tflush Uses

type Tflush []byte

When the response to a request is no longer needed, such as when a user interrupts a process doing a read(2), a Tflush request is sent to the server to purge the pending response.

func (Tflush) Len Uses

func (m Tflush) Len() int64

func (Tflush) Oldtag Uses

func (m Tflush) Oldtag() uint16

The message being flushed is identified by oldtag.

func (Tflush) String Uses

func (m Tflush) String() string

func (Tflush) Tag Uses

func (m Tflush) Tag() uint16

type Topen Uses

type Topen []byte

The open request asks the file server to check permissions and prepare a fid for I/O with subsequent read and write messages.

func (Topen) Fid Uses

func (m Topen) Fid() uint32

Fid is the fid of the file to open, as established by a previous transaction (such as a succesful Twalk).

func (Topen) Len Uses

func (m Topen) Len() int64

func (Topen) Mode Uses

func (m Topen) Mode() uint8

The mode field determines the type of I/O, and is checked against the permissions for the file:

0 (OREAD)    read access
1 (OWRITE)   write access
2 (ORDWR)    read and write access
3 (OEXEC)    execute access

If mode has the OTRUNC (0x10) bit set, the file is to be truncated, which requires write permission (if the file is append-only, and permission is granted, the open succeeds but the file will not be truncated)

If the mode has the ORCLOSE (0x40) bit set, the file is to be removed when the fid is clunked, which requires permission to remove the file from its directory. All other bits in mode should be zero.

It is illegal to write a directory, truncate it, or attempt to remove it on close.

func (Topen) String Uses

func (m Topen) String() string

func (Topen) Tag Uses

func (m Topen) Tag() uint16

type Tread Uses

type Tread []byte

func (Tread) Count Uses

func (m Tread) Count() int64

Count is the number of bytes to read from the file. Count cannot be more than the maximum value of a 32-bit unsigned integer.

func (Tread) Fid Uses

func (m Tread) Fid() uint32

Fid is the handle of the file to read from.

func (Tread) Len Uses

func (m Tread) Len() int64

func (Tread) Offset Uses

func (m Tread) Offset() int64

Offset is the starting point in the file from which to begin returning data.

func (Tread) String Uses

func (m Tread) String() string

func (Tread) Tag Uses

func (m Tread) Tag() uint16

type Tremove Uses

type Tremove []byte

func (Tremove) Fid Uses

func (m Tremove) Fid() uint32

func (Tremove) Len Uses

func (m Tremove) Len() int64

func (Tremove) String Uses

func (m Tremove) String() string

func (Tremove) Tag Uses

func (m Tremove) Tag() uint16

type Tstat Uses

type Tstat []byte

func (Tstat) Fid Uses

func (m Tstat) Fid() uint32

func (Tstat) Len Uses

func (m Tstat) Len() int64

func (Tstat) String Uses

func (m Tstat) String() string

func (Tstat) Tag Uses

func (m Tstat) Tag() uint16

type Tversion Uses

type Tversion []byte

The version request negotiates the protocol version and message size to be used on the connection and initializes the connection for I/O. Tversion must be the first message sent on the 9P connection, and the client cannot issue any further requests until it has received the Rversion reply.

func (Tversion) Len Uses

func (m Tversion) Len() int64

Len returns the length of a Tversion request in bytes.

func (Tversion) Msize Uses

func (m Tversion) Msize() int64

Msize returns the maximum length, in bytes, that the client will ever generate or expect to receive in a single 9P message. This count includes all 9P protocol data, starting from the size field and extending through the message, but excludes enveloping transport protocols.

func (Tversion) String Uses

func (m Tversion) String() string

func (Tversion) Tag Uses

func (m Tversion) Tag() uint16

For version messages, Tag should be NoTag

func (Tversion) Version Uses

func (m Tversion) Version() []byte

Version identifies the level of the protocol that the client supports. The string must always begin with the two characters "9P".

type Twalk Uses

type Twalk []byte

A Twalk message is used to descend a directory hierarchy.

func (Twalk) Fid Uses

func (m Twalk) Fid() uint32

The Twalk message contains the fid of the directory it intends to descend into. The Fid must have been established by a previous transaction, such as an attach.

func (Twalk) Len Uses

func (m Twalk) Len() int64

func (Twalk) Newfid Uses

func (m Twalk) Newfid() uint32

Newfid contains the proposed fid that the client wishes to associate with the result of traversing the directory hierarchy.

func (Twalk) Nwname Uses

func (m Twalk) Nwname() int

To simplify the implementation of servers, a maximum of sixteen name elements may be packed in a single message, as captured by the constant MaxWElem.

It is legal for Nwname to be zero, in which case Newfid will represent the same file as Fid.

func (Twalk) String Uses

func (m Twalk) String() string

func (Twalk) Tag Uses

func (m Twalk) Tag() uint16

func (Twalk) Wname Uses

func (m Twalk) Wname(n int) []byte

The Twalk message contains an ordered list of path name elements that the client wishes to descend into in succession.

type Twrite Uses

type Twrite struct {
    // contains filtered or unexported fields
}

The Twrite message is sent by a client to write data to a file. The data portion of a Twrite request can be accessed via the io.Reader interface.

func (Twrite) Count Uses

func (m Twrite) Count() int64

func (Twrite) Fid Uses

func (m Twrite) Fid() uint32

func (Twrite) Len Uses

func (m Twrite) Len() int64

func (Twrite) Offset Uses

func (m Twrite) Offset() int64

func (Twrite) Read Uses

func (m Twrite) Read(p []byte) (int, error)

Read copies len(p) bytes from a Twrite message's data field into p. It returns the number of bytes copied and an error, if any.

func (Twrite) String Uses

func (m Twrite) String() string

func (Twrite) Tag Uses

func (m Twrite) Tag() uint16

type Twstat Uses

type Twstat []byte

func (Twstat) Fid Uses

func (m Twstat) Fid() uint32

func (Twstat) Len Uses

func (m Twstat) Len() int64

func (Twstat) Stat Uses

func (m Twstat) Stat() Stat

func (Twstat) String Uses

func (m Twstat) String() string

func (Twstat) Tag Uses

func (m Twstat) Tag() uint16

Package styxproto imports 11 packages (graph) and is imported by 7 packages. Updated 2018-04-15. Refresh now. Tools for package owners.