styxproto

package
v0.0.0-...-bf55d75 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2022 License: MIT Imports: 11 Imported by: 2

README

The styxproto package is parses and produces 9P2000 protocol messages. See the package documentation for more details.

Fuzz testing the styxproto package

This directory contains fuzz tests for the 'styxproto' package, along with test inputs.

To start fuzz testing, run

go get github.com/dvyukov/go-fuzz/go-fuzz
go get github.com/dvyukov/go-fuzz/go-fuzz-build

go-fuzz-build aqwari.net/net/styx/styxproto
go-fuzz -bin=./styxproto-fuzz.zip

Documentation

Overview

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

Constants

View Source
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

View Source
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

View Source
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.

View Source
const DefaultBufSize = 8192

DefaultBufSize is the default buffer size used in a Decoder

View Source
const DefaultMaxSize = 8 * megabyte

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

View Source
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]
View Source
const MaxAttachLen = 255

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

View Source
const MaxErrorLen = 512

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

View Source
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.

View Source
const MaxFilenameLen = 255

MaxFilenameLen is the maximum length of a file name in bytes

View Source
const MaxOffset = 1<<63 - 1

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

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

MaxStatLen is the maximum size of a Stat structure.

View Source
const MaxUidLen = 45

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

View Source
const MaxVersionLen = 20

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

View Source
const MaxWElem = 16

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

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

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

View Source
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.

View Source
const NoTag = ^uint16(0)

NoTag is the tag for Tversion and Rversion requests.

View Source
const QidLen = 13

QidLen is the length of a Qid in bytes.

Variables

View Source
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.

Functions

func Write

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.

Types

type BadMessage

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

BadMessage represents an invalid message.

func (BadMessage) Len

func (m BadMessage) Len() int64

func (BadMessage) String

func (m BadMessage) String() string

func (BadMessage) Tag

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

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.

Example
package main

import (
	"io"
	"io/ioutil"
	"log"
	"net"

	"aqwari.net/net/styx/styxproto"
)

func main() {
	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)
		}
	}
}
Output:

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

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

func NewDecoderSize

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

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

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

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

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

Reset resets a Decoder with a new io.Reader.

type Encoder

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

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

func NewEncoder

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

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

func (enc *Encoder) Flush() error

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

func (*Encoder) Rattach

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

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

func (*Encoder) Rauth

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

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

func (*Encoder) Rclunk

func (enc *Encoder) Rclunk(tag uint16)

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

func (*Encoder) Rcreate

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

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

func (*Encoder) Rerror

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

func (enc *Encoder) Rflush(tag uint16)

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

func (*Encoder) Ropen

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

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

func (*Encoder) Rread

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

func (enc *Encoder) Rremove(tag uint16)

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

func (*Encoder) Rstat

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

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

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

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

func (enc *Encoder) Rwstat(tag uint16)

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

func (*Encoder) Tattach

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

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

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

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

func (*Encoder) Tcreate

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

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

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

func (*Encoder) Topen

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

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

func (*Encoder) Tread

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

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

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

func (*Encoder) Tstat

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

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

func (*Encoder) Tversion

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

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

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

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

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

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

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.

Example
package main

import (
	"fmt"
	"log"

	"aqwari.net/net/styx/styxproto"
)

func main() {
	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

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

func (q Qid) String() string

func (Qid) Type

func (q Qid) Type() uint8

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

func (Qid) Version

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

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

func (m Rattach) Len() int64

func (Rattach) Qid

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

func (m Rattach) String() string

func (Rattach) Tag

func (m Rattach) Tag() uint16

type Rauth

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

func (m Rauth) Aqid() Qid

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

func (Rauth) Len

func (m Rauth) Len() int64

func (Rauth) String

func (m Rauth) String() string

func (Rauth) Tag

func (m Rauth) Tag() uint16

type Rclunk

type Rclunk []byte

func (Rclunk) Len

func (m Rclunk) Len() int64

func (Rclunk) String

func (m Rclunk) String() string

func (Rclunk) Tag

func (m Rclunk) Tag() uint16

type Rcreate

type Rcreate []byte

func (Rcreate) IOunit

func (m Rcreate) IOunit() int64

func (Rcreate) Len

func (m Rcreate) Len() int64

func (Rcreate) Qid

func (m Rcreate) Qid() Qid

func (Rcreate) String

func (m Rcreate) String() string

func (Rcreate) Tag

func (m Rcreate) Tag() uint16

type Rerror

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

func (m Rerror) Ename() []byte

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

func (Rerror) Err

func (m Rerror) Err() error

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

func (Rerror) Len

func (m Rerror) Len() int64

func (Rerror) String

func (m Rerror) String() string

func (Rerror) Tag

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

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

func (m Rflush) Len() int64

func (Rflush) String

func (m Rflush) String() string

func (Rflush) Tag

func (m Rflush) Tag() uint16

type Ropen

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

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

func (m Ropen) Len() int64

func (Ropen) Qid

func (m Ropen) Qid() Qid

Qid contains the unique identifier of the opened file.

func (Ropen) String

func (m Ropen) String() string

func (Ropen) Tag

func (m Ropen) Tag() uint16

type Rread

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

func (m Rread) Count() int64

func (Rread) Len

func (m Rread) Len() int64

func (Rread) Read

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

func (m Rread) String() string

func (Rread) Tag

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

type Rremove []byte

func (Rremove) Len

func (m Rremove) Len() int64

func (Rremove) String

func (m Rremove) String() string

func (Rremove) Tag

func (m Rremove) Tag() uint16

type Rstat

type Rstat []byte

func (Rstat) Len

func (m Rstat) Len() int64

func (Rstat) Stat

func (m Rstat) Stat() Stat

func (Rstat) String

func (m Rstat) String() string

func (Rstat) Tag

func (m Rstat) Tag() uint16

type Rversion

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

func (m Rversion) Len() int64

Len returns the length of the Rversion message in bytes.

func (Rversion) Msize

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

func (m Rversion) String() string

func (Rversion) Tag

func (m Rversion) Tag() uint16

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

func (Rversion) Version

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

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

func (m Rwalk) Len() int64

func (Rwalk) Nwqid

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

func (m Rwalk) String() string

func (Rwalk) Tag

func (m Rwalk) Tag() uint16

func (Rwalk) Wqid

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

type Rwrite []byte

func (Rwrite) Count

func (m Rwrite) Count() uint32

func (Rwrite) Len

func (m Rwrite) Len() int64

func (Rwrite) String

func (m Rwrite) String() string

func (Rwrite) Tag

func (m Rwrite) Tag() uint16

type Rwstat

type Rwstat []byte

func (Rwstat) Len

func (m Rwstat) Len() int64

func (Rwstat) String

func (m Rwstat) String() string

func (Rwstat) Tag

func (m Rwstat) Tag() uint16

type Stat

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

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.

Example
package main

import (
	"fmt"
	"log"

	"aqwari.net/net/styx/styxproto"
)

func main() {
	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

func (s Stat) Atime() uint32

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

func (Stat) Dev

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

func (s Stat) Gid() []byte

Gid returns the group of the file.

func (Stat) Length

func (s Stat) Length() int64

Length returns the length of the file in bytes.

func (Stat) Mode

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

func (s Stat) Mtime() uint32

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

func (Stat) Muid

func (s Stat) Muid() []byte

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

func (Stat) Name

func (s Stat) Name() []byte

Name returns the name of the file.

func (Stat) Qid

func (s Stat) Qid() Qid

Qid returns the unique identifier of the file.

func (Stat) SetAtime

func (s Stat) SetAtime(t uint32)

func (Stat) SetDev

func (s Stat) SetDev(d uint32)

func (Stat) SetLength

func (s Stat) SetLength(n int64)

func (Stat) SetMode

func (s Stat) SetMode(m uint32)

func (Stat) SetMtime

func (s Stat) SetMtime(t uint32)

func (Stat) SetQid

func (s Stat) SetQid(q Qid)

func (Stat) SetType

func (s Stat) SetType(t uint16)

func (Stat) String

func (s Stat) String() string

func (Stat) Type

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

func (s Stat) Uid() []byte

Uid returns the name of the owner of the file.

type Tattach

type Tattach []byte

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

func (Tattach) Afid

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

func (m Tattach) Aname() []byte

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

func (Tattach) Fid

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

func (m Tattach) Len() int64

func (Tattach) String

func (m Tattach) String() string

func (Tattach) Tag

func (m Tattach) Tag() uint16

func (Tattach) Uname

func (m Tattach) Uname() []byte

Uname is the user name of the attaching user.

type Tauth

type Tauth []byte

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

func (Tauth) Afid

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

func (m Tauth) Aname() []byte

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

func (Tauth) Len

func (m Tauth) Len() int64

func (Tauth) String

func (m Tauth) String() string

func (Tauth) Tag

func (m Tauth) Tag() uint16

func (Tauth) Uname

func (m Tauth) Uname() []byte

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

type Tclunk

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

func (m Tclunk) Fid() uint32

func (Tclunk) Len

func (m Tclunk) Len() int64

func (Tclunk) String

func (m Tclunk) String() string

func (Tclunk) Tag

func (m Tclunk) Tag() uint16

type Tcreate

type Tcreate []byte

func (Tcreate) Fid

func (m Tcreate) Fid() uint32

func (Tcreate) Len

func (m Tcreate) Len() int64

func (Tcreate) Mode

func (m Tcreate) Mode() uint8

func (Tcreate) Name

func (m Tcreate) Name() []byte

func (Tcreate) Perm

func (m Tcreate) Perm() uint32

func (Tcreate) String

func (m Tcreate) String() string

func (Tcreate) Tag

func (m Tcreate) Tag() uint16

type Tflush

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

func (m Tflush) Len() int64

func (Tflush) Oldtag

func (m Tflush) Oldtag() uint16

The message being flushed is identified by oldtag.

func (Tflush) String

func (m Tflush) String() string

func (Tflush) Tag

func (m Tflush) Tag() uint16

type Topen

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

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

func (m Topen) Len() int64

func (Topen) Mode

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

func (m Topen) String() string

func (Topen) Tag

func (m Topen) Tag() uint16

type Tread

type Tread []byte

func (Tread) Count

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

func (m Tread) Fid() uint32

Fid is the handle of the file to read from.

func (Tread) Len

func (m Tread) Len() int64

func (Tread) Offset

func (m Tread) Offset() int64

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

func (Tread) String

func (m Tread) String() string

func (Tread) Tag

func (m Tread) Tag() uint16

type Tremove

type Tremove []byte

func (Tremove) Fid

func (m Tremove) Fid() uint32

func (Tremove) Len

func (m Tremove) Len() int64

func (Tremove) String

func (m Tremove) String() string

func (Tremove) Tag

func (m Tremove) Tag() uint16

type Tstat

type Tstat []byte

func (Tstat) Fid

func (m Tstat) Fid() uint32

func (Tstat) Len

func (m Tstat) Len() int64

func (Tstat) String

func (m Tstat) String() string

func (Tstat) Tag

func (m Tstat) Tag() uint16

type Tversion

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

func (m Tversion) Len() int64

Len returns the length of a Tversion request in bytes.

func (Tversion) Msize

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

func (m Tversion) String() string

func (Tversion) Tag

func (m Tversion) Tag() uint16

For version messages, Tag should be NoTag

func (Tversion) Version

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

type Twalk []byte

A Twalk message is used to descend a directory hierarchy.

func (Twalk) Fid

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

func (m Twalk) Len() int64

func (Twalk) Newfid

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

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

func (m Twalk) String() string

func (Twalk) Tag

func (m Twalk) Tag() uint16

func (Twalk) Wname

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

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

func (m Twrite) Count() int64

func (Twrite) Fid

func (m Twrite) Fid() uint32

func (Twrite) Len

func (m Twrite) Len() int64

func (Twrite) Offset

func (m Twrite) Offset() int64

func (Twrite) Read

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

func (m Twrite) String() string

func (Twrite) Tag

func (m Twrite) Tag() uint16

type Twstat

type Twstat []byte

func (Twstat) Fid

func (m Twstat) Fid() uint32

func (Twstat) Len

func (m Twstat) Len() int64

func (Twstat) Stat

func (m Twstat) Stat() Stat

func (Twstat) String

func (m Twstat) String() string

func (Twstat) Tag

func (m Twstat) Tag() uint16

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL