message

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2021 License: BSD-2-Clause Imports: 8 Imported by: 2

Documentation

Overview

Package message contains types for 9p messages.

The types defined here can encode/decode themselves to the 9p wire representation.

Index

Constants

View Source
const (
	BadAttachErrorString    = "unknown specifier in attach"
	BadOffsetErrorString    = "bad offset"
	BadCountErrorString     = "bad count"
	BotchErrorString        = "9P protocol botch"
	CreateNonDirErrorString = "create in non-directory"
	DupFidErrorString       = "duplicate fid"
	DupTagErrorString       = "duplicate tag"
	IsDirErrorString        = "is a directory"
	NoCreateErrorString     = "create prohibited"
	NoMemErrorString        = "out of memory"
	NoRemoveErrorString     = "remove prohibited"
	NoStatErrorString       = "stat prohibited"
	NotFoundErrorString     = "file not found"
	NoWriteErrorString      = "write prohibited"
	NoWstatErrorString      = "wstat prohibited"
	PermErrorString         = "permission denied"
	UnknownFidErrorString   = "unknown fid"
	BadDirErrorString       = "bad directory in wstat"
	WalkNoDirErrorString    = "walk in non-directory"
)

9p defined error strings. See: https://github.com/0intro/plan9/blob/7524062cfa4689019a4ed6fc22500ec209522ef0/sys/src/lib9p/srv.c#L10

View Source
const HeaderSize uint64 = 4 + 1 + 2

HeaderSize is the length of the size, type and tag headers in bytes.

Variables

This section is empty.

Functions

func OsMode

func OsMode(mode OpenMode) int

OsMode convertes a OpenMode to os.Open mode.

Converted modes: Read, Write, ReadWrite, Trunc

Types

type Content

type Content interface {
	// contains filtered or unexported methods
}

Content is implemented by the message types containing the real information.

type Message

type Message struct {
	Tag     uint16
	Content Content
	// contains filtered or unexported fields
}

Message is the general message type.

It wraps implementations of interface Content.

func New

func New(tag uint16, content Content) (Message, error)

New creates a new Message with a given tag and Content.

func (*Message) Decode

func (m *Message) Decode(r io.Reader) (int64, error)

Decode reads a message from a io.Reader.

It returns the count of read bytes and an error.

func (*Message) Encode

func (m *Message) Encode(w io.Writer) (int64, error)

Encode writes a Message to an io.Writer.

It returns the count of bytes written and an error.

func (Message) Response

func (m Message) Response() Message

Response returns a new Message prepared for using as reply.

type OpenMode

type OpenMode uint8

OpenMode is used to signalize the mode a file should be opened with in a TOpenMessage.

const (
	// Read opens a file for reading.
	Read OpenMode = 0

	// Write opens a file for writing
	Write OpenMode = 1

	// ReadWrite opens a file for random access.
	ReadWrite OpenMode = 2

	// Exec opens a file for reading but also checks execute permission.
	Exec OpenMode = 3

	// Trunc is to be OR'ed in (except for OpenExec), truncates file before opening.
	Trunc OpenMode = 16

	// CloseExec is to be OR'ed in, closes on execution.
	CloseExec OpenMode = 32

	// Close is to be OR'ed in, remove on closing.
	Close OpenMode = 64
)

func NeinMode

func NeinMode(osMode int) OpenMode

NeinMode convertes a os.Open mode to OpenMode.

Converted modes: os.O_RDONLY, os.O_WRONLY, os.O_RDWR, os.O_TRUNC

type RAttach

type RAttach struct {
	Qid qid.Qid
}

RAttach is the answer to an attach request.

Qid is the servers representation of the file trees root.

See also: http://man.cat-v.org/plan_9/5/attach

type RAuth

type RAuth struct {
	Aqid qid.Qid
}

RAuth is the response to a TAuth

Aqid is a file of type QidTypeAuth that can be read and written using read and write messages to perform authentication. The authentication protocol is not part of 9p.

See also: http://man.cat-v.org/plan_9/5/attach

type RClunk

type RClunk struct{}

RClunk signals a successful clunk.

After the fid is successfully clunked it can be reused.

See also: http://man.cat-v.org/plan_9/5/clunk

type RCreate

type RCreate struct {
	Qid    qid.Qid
	Iounit uint32
}

RCreate is the answer for a successful create.

Qid is the new file as seen by the server.

Iounit may be zero. If not, it is the number of bytes guaranteed to succeed to be read or written in one message.

See also: http://man.cat-v.org/plan_9/5/open

type RError

type RError struct {
	Ename string
}

RError is the response to failed requests.

It usually contains one of the standard *ErrorString constants.

See also: http://man.cat-v.org/plan_9/5/error

type RFlush

type RFlush struct {
}

RFlush is the answer to a TFlush and signals that the flush has finished.

See also: http://man.cat-v.org/plan_9/5/flush

type ROpen

type ROpen struct {
	Qid    qid.Qid
	Iounit uint32
}

ROpen is the reply to a open request.

Qid is the servers idea of the opened file accessed.

Iounit may be zero. If not, it's the number of bytes which can be read or written in a single call.

See also: http://man.cat-v.org/plan_9/5/open

type RRead

type RRead struct {
	Count uint32
	Data  []byte
}

RRead is the reply to a TRead.

The data read is stored in Data, Count being the length of Data in bytes.

For directories, read returns an integral number of directory entries exactly as in RStat, one for each member of the directory. To help with this StatReader can be used.

See also: http://man.cat-v.org/inferno/5/read

type RRemove

type RRemove struct{}

RRemove is the answer for a successful TRemove request.

See also: http://man.cat-v.org/inferno/5/remove

type RStat

type RStat struct {
	Stat stat.Stat
}

RStat contains a machine-independent directory entry, Stat.

See also: http://man.cat-v.org/inferno/5/stat

type RVersion

type RVersion struct {
	Msize   uint32
	Version string
}

RVersion is the servers reply to a TVersionMessage.

Msize must be lower or equal of what the client requested.

Version may be set to the clients version string or a string of an earlier protocol version. If the server doesn't understand the requested version, it replies with the version string "unknown".

A version request starts a new session, so any remaining I/O operations are aborted and allocated fids are clunked.

See also: http://man.cat-v.org/inferno/5/version

type RWalk

type RWalk struct {
	Wqid []qid.Qid
}

RWalk is the response to a TWalk.

Wqid contains the qids of the Wnames in a successfull walk. If the walk fails at the first element an error is returned, if it fails at a later point, the qids of the successfully walked elements are returned (len(Wqid) < len(Wname).

See also: http://man.cat-v.org/inferno/5/walk

type RWrite

type RWrite struct {
	Count uint32
}

RWrite is the reply to a TWrite.

Count is the number of bytes written. It usually should be the same as requested.

See also: http://man.cat-v.org/inferno/5/read

type RWstat

type RWstat struct{}

RWstat is the reply for a successfull TWstat request.

See also: http://man.cat-v.org/inferno/5/stat

type TAttach

type TAttach struct {
	Fid   fid.Fid
	Afid  fid.Fid
	Uname string
	Aname string
}

TAttach establishes a new connection.

Fid will be mapped to the root of the file system. Afid specifies a fid gained from a previous TAuth. Uname identifies the user accessing the file system, Aname selecting the file tree to access.

See also: http://man.cat-v.org/plan_9/5/attach

type TAuth

type TAuth struct {
	Afid  fid.Fid
	Uname string
	Aname string
}

TAuth facilitates authentication.

Afid is a new fid to be used for authentication. Uname and Aname must be the same as for the following TAttach.

Authentication is performed by reading and writing the file referenced by Afid, after receiving RAuth. When complete Afid is used for authentication in TAttach.

The same Afid, Uname and Aname may be used for multiple TAttach messages.

If no authentication is required, RError is returned instead of RAuth.

See also: http://man.cat-v.org/plan_9/5/attach

type TClunk

type TClunk struct {
	Fid fid.Fid
}

TClunk requests to forget a fid.

The mapping on the server from fid to actual file should be removed, not touching the actual file unless it was used OpenClose.

Regardless of the result of this call, the fid will not be valid anymore and can be reused.

See also: http://man.cat-v.org/plan_9/5/clunk

type TCreate

type TCreate struct {
	Fid  uint32
	Name string
	Perm stat.Mode
	Mode OpenMode
}

TCreate asks the file server to create a new file.

The file is to be created in the directory represented by Fid, with the supplied Name. Write permission is required on the directory. The owner will be implied by the file systems used. The group is the same as the directories. Permissions for a file will be set to

Perm & 0666 | DPerm & 0666

or

Perm & 0777 | DPerm & 0777

if a directory (DPerm being the permissions of the parent directory).

The created file is opened with Mode, and Fid will represent the new file. Mode is not checked to fulfill the permissions of Perm.

Directories are created by setting the DirModeDir bit in Perm.

Names "." and ".." are forbidden.

Fid must not be in use already.

Creating a file with a name already in use, will truncate the existing file.

See also: http://man.cat-v.org/plan_9/5/open

type TFlush

type TFlush struct {
	Oldtag uint16
}

TFlush signals the server that it should abort processing a message.

Instances of Server directly handle these message type by running the cancel function of the context for the message which should be aborted. It is here for usage in client implementations.

Unlike the real world, flushing never fails.

See also: http://man.cat-v.org/inferno/5/flush

type TOpen

type TOpen struct {
	Fid  fid.Fid
	Mode OpenMode
}

TOpen is a 9P open request message.

Open requests ask the file server to prepare a fid to be used with read and write requests, checking the permissions before.

Mode determines the type of IO and can be one of the constants OpenRead, OpenWrite, OpenReadWrite, OpenExec, additionally OpenTrunc, OpenCloseExec and OpenClose or'ed into Mode.

See also: http://man.cat-v.org/plan_9/5/open

type TRead

type TRead struct {
	Fid    fid.Fid
	Offset uint64
	Count  uint32
}

TRead requests data from a file.

The file is identified by Fid, which must be opened before reading. Count bytes are read from the file, starting at Offset bytes after the beginning of the file.

The count Field in the reply indicates the number of bytes returned. This may be less than the requested amount. If the Offset field is greater than or equal to the number of bytes in the file, a Count of zero will be returned.

For directories, the read request message must have Offset equal to zero or the value of Offset in the previous read on the directory, plus the number of bytes returned in the previous read. In other words, seeking other than to the beginning is illegal in a directory.

See also: http://man.cat-v.org/inferno/5/read

type TRemove

type TRemove struct {
	Fid fid.Fid
}

TRemove signals the server to remove the file and clunk the Fid.

The Fid is clunked even if the remove fails. The request will fail if the client doesn't have the permission to write the parent directory.

See also: http://man.cat-v.org/inferno/5/remove

type TStat

type TStat struct {
	Fid fid.Fid
}

TStat requests information about file.

The file for which information is requested is identified by Fid.

See also: http://man.cat-v.org/inferno/5/stat

type TVersion

type TVersion struct {
	Msize   uint32
	Version string
}

TVersion initializes a new connection.

Msize is the maximum message size the client will ever create, and includes _all_ protocol data (also 9p type, tag and size fields). As the contents of these fields are handled by neinp.Server, the msize has to include the length of the size (4 octets) type (1 octet) and tag (2 octets) fields, even if not visible to neinp.P2000 implementers. The msize returned with RVersion will be read by neinp.Server to setup a io.LimitReader for message reception.

Version identifies the level of the protocol, it must always start with "9P" (though not enforced here).

See also: http://man.cat-v.org/inferno/5/version

type TWalk

type TWalk struct {
	Fid    fid.Fid
	Newfid fid.Fid
	Wname  []string
}

TWalk asks to walk down a directory hierarchy.

Fid is an already existing fid, Newfid is a proposed new fid that the client wants to use for the result of the walk. Wname are successive path elements to walk to, and may be of length zero. Fid must be a directory, only if Wname is of length zero. In this case Newfid will represent the same file as Fid.

Fid must be valid and not already opened by a TOpen or TCreate request.

Wname may be "..", which represents the parent directory, "." is not used and forbidden, zero length Wname is used for this.

Wname should have a maximum length of 16 elements (this limit is not enforced here).

See also: http://man.cat-v.org/inferno/5/walk

type TWrite

type TWrite struct {
	Fid    fid.Fid
	Offset uint64
	Count  uint32
	Data   []byte
}

TWrite requests data to be written to a file.

Write Count bytes of Data at Offset bytes from the beginning of the file. The file which is represented by Fid must be opened for writing before this request, when opened in append mode, the write will be to the end of the file, ignoring Offset. Writes to directories are forbidden.

See also: http://man.cat-v.org/inferno/5/read

type TWstat

type TWstat struct {
	Fid  fid.Fid
	Stat stat.Stat
}

TWstat requests to change some of the file status information.

Name can be changed by anyone with write permissions for the parent directory and if the name isn't already in use in the parent directory.

The length of the file can be changed by anyone with write permissions and will reflect in the actual length of the file. The length of directories can't be set to anything than zero.

Servers may refuse length changes.

Mode and mtime may be changed by the owner or group.

All permission and mode bits can be changed, except for the directory bit.

The gid can be changed by the owner if he is member of the new group or by the group leader of both the current and new group.

The other data can't be changed using wstat. It is illegal to change the owner of a file.

Changes are performed atomic, either all changes are applied with the call succeeding, or none.

Modification of properties can be avoided using zero values: Strings of length zero and the maximum value for integers.

If every property is set to such a zero value, it is to be handled as a request to sync the file to stable storage.

See also: http://man.cat-v.org/inferno/5/stat

Jump to

Keyboard shortcuts

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