Documentation
¶
Overview ¶
Package p9 implements the wire encoding for the Plan 9 filesystem protocol, 9P2000, as specified in the Plan 9 manual pages intro(5) and fcall(3). It provides only the message types and their marshaling/unmarshaling to and from the wire format; connection handling and RPC dispatch live in the client and server packages.
The 9P2000.u extension (VersionU) is also supported, for its symlink support (DMSYMLINK/QTSYMLINK and Stat's Extension field) and numeric Uid/Gid/Muid (Stat's Nuid/Ngid/Nmuid) — not the rest of .u (special/device files, remapped errno numbers) or .L.
Index ¶
- Constants
- Variables
- func Marshal(tag Tag, m Message) []byte
- func MarshalVersion(tag Tag, m Message, unix bool) []byte
- func ReadMessage(r io.Reader, msize uint32) ([]byte, error)
- func Unmarshal(raw []byte) (Tag, Message, error)
- func UnmarshalVersion(raw []byte, unix bool) (Tag, Message, error)
- func WriteMessage(w io.Writer, raw []byte) error
- type FcallType
- type Fid
- type Message
- type Mode
- type Qid
- type QidType
- type RattachFcall
- type RauthFcall
- type RclunkFcall
- type RcreateFcall
- type RerrorFcall
- type RflushFcall
- type RopenFcall
- type RreadFcall
- type RremoveFcall
- type RstatFcall
- type RversionFcall
- type RwalkFcall
- type RwriteFcall
- type RwstatFcall
- type Stat
- type Tag
- type TattachFcall
- type TauthFcall
- type TclunkFcall
- type TcreateFcall
- type TflushFcall
- type TopenFcall
- type TreadFcall
- type TremoveFcall
- type TstatFcall
- type TversionFcall
- type TwalkFcall
- type TwriteFcall
- type TwstatFcall
Constants ¶
const ( // Version is the protocol version string sent in Tversion. Version = "9P2000" // VersionU is the 9P2000.u extension's version string: adds // symlinks (DMSYMLINK/QTSYMLINK), an Extension field on Stat, and // an Extension field on Tcreate, among other Unix-specific // extensions this package does not implement. VersionU = "9P2000.u" // VersionUnknown is the version string a server returns when it // does not support the version requested in Tversion. VersionUnknown = "unknown" // DefaultMsize is a reasonable default maximum message size for // a client or server that has no other preference. DefaultMsize = 8192 // MaxWElem is the maximum number of path elements permitted in a // single Twalk message. MaxWElem = 16 )
Variables ¶
var ( ErrTruncated = errors.New("p9: message truncated") ErrTrailingBytes = errors.New("p9: trailing bytes after message") ErrMsgTooLarge = errors.New("p9: message exceeds msize") ErrUnknownType = errors.New("p9: unknown message type") ErrTooManyWElem = errors.New("p9: too many walk elements") )
Errors returned while framing or decoding a 9P2000 message. These indicate a malformed message on the wire — protocol-level failures (a file not found, permission denied, and so on) are reported by the peer as an RerrorFcall instead.
Functions ¶
func Marshal ¶
Marshal encodes tag and m into a complete wire message, including the leading 4-byte size prefix, using plain 9P2000. Use MarshalVersion on a connection that negotiated VersionU.
func MarshalVersion ¶ added in v0.9.0
MarshalVersion is Marshal, but includes the 9P2000.u-only fields on Stat and Tcreate when unix is true.
func ReadMessage ¶
ReadMessage reads one complete 9P2000 message from r: a 4-byte little-endian size prefix followed by size-4 bytes of body. The returned slice includes the size prefix, as Unmarshal expects. If msize is non-zero, messages larger than msize are rejected without being read into memory, which bounds how much a misbehaving peer can force a reader to allocate.
func Unmarshal ¶
Unmarshal parses a complete wire message, as produced by ReadMessage, into its tag and typed Message, assuming plain 9P2000. Use UnmarshalVersion on a connection that negotiated VersionU.
func UnmarshalVersion ¶ added in v0.9.0
UnmarshalVersion is Unmarshal, but expects the 9P2000.u-only fields on Stat and Tcreate to be present when unix is true.
Types ¶
type FcallType ¶
type FcallType uint8
FcallType is the one-byte message type that begins every 9P2000 message on the wire, immediately after the 4-byte size.
const ( Tversion FcallType = 100 Rversion FcallType = 101 Tauth FcallType = 102 Rauth FcallType = 103 Tattach FcallType = 104 Rattach FcallType = 105 // 106 (Terror) is illegal and never sent on the wire. Rerror FcallType = 107 Tflush FcallType = 108 Rflush FcallType = 109 Twalk FcallType = 110 Rwalk FcallType = 111 Topen FcallType = 112 Ropen FcallType = 113 Tcreate FcallType = 114 Rcreate FcallType = 115 Tread FcallType = 116 Rread FcallType = 117 Twrite FcallType = 118 Rwrite FcallType = 119 Tclunk FcallType = 120 Rclunk FcallType = 121 Tremove FcallType = 122 Rremove FcallType = 123 Tstat FcallType = 124 Rstat FcallType = 125 Twstat FcallType = 126 Rwstat FcallType = 127 )
type Fid ¶
type Fid uint32
Fid is a client-chosen handle identifying a file on the server, analogous to a file descriptor.
const NoFid Fid = 0xFFFFFFFF
NoFid marks the absence of an authentication fid in Tattach.
type Message ¶
type Message interface {
MsgType() FcallType
// contains filtered or unexported methods
}
Message is implemented by every 9P2000 message body (everything after the tag). Marshal and Unmarshal combine a Message with a Tag to produce or parse a complete wire message.
type Mode ¶
type Mode uint32
Mode holds either an open mode (Topen.Mode, Tcreate.Mode — one byte on the wire) or a permission mode (Stat.Mode, Tcreate.Perm — four bytes on the wire). The two share no bits in practice, so one type serves both roles; callers marshal it as one or four bytes depending on which field it appears in.
const ( OREAD Mode = 0 OWRITE Mode = 1 ORDWR Mode = 2 OEXEC Mode = 3 OTRUNC Mode = 0x10 ORCLOSE Mode = 0x40 )
Open-mode bits: the low two bits select the access mode, the rest are flags.
const ( DMDIR Mode = 0x80000000 DMAPPEND Mode = 0x40000000 DMEXCL Mode = 0x20000000 DMTMP Mode = 0x04000000 DMSYMLINK Mode = 0x02000000 // 9P2000.u only DMPerm Mode = 0777 )
Permission-mode bits: the top bits mark directories and other special files, the low 9 bits are rwxrwxrwx permissions.
type Qid ¶
Qid is the server's identification for a file: its type, a version number that changes whenever the file's contents change, and a path that is unique among all files served on a connection.
type QidType ¶
type QidType uint8
QidType identifies the type of a file. It occupies the type byte of a Qid and mirrors the high bits of the file's permission Mode.
type RattachFcall ¶
type RattachFcall struct {
Qid Qid
}
func (*RattachFcall) MsgType ¶
func (m *RattachFcall) MsgType() FcallType
type RauthFcall ¶
type RauthFcall struct {
Aqid Qid
}
func (*RauthFcall) MsgType ¶
func (m *RauthFcall) MsgType() FcallType
type RclunkFcall ¶
type RclunkFcall struct{}
func (*RclunkFcall) MsgType ¶
func (m *RclunkFcall) MsgType() FcallType
type RcreateFcall ¶
func (*RcreateFcall) MsgType ¶
func (m *RcreateFcall) MsgType() FcallType
type RerrorFcall ¶
type RerrorFcall struct {
Ename string
}
RerrorFcall is the error reply to any T-message. It implements the error interface so it can be returned directly from client RPC calls.
func (*RerrorFcall) Error ¶
func (m *RerrorFcall) Error() string
func (*RerrorFcall) MsgType ¶
func (m *RerrorFcall) MsgType() FcallType
type RflushFcall ¶
type RflushFcall struct{}
func (*RflushFcall) MsgType ¶
func (m *RflushFcall) MsgType() FcallType
type RopenFcall ¶
func (*RopenFcall) MsgType ¶
func (m *RopenFcall) MsgType() FcallType
type RreadFcall ¶
type RreadFcall struct {
Data []byte
}
func (*RreadFcall) MsgType ¶
func (m *RreadFcall) MsgType() FcallType
type RremoveFcall ¶
type RremoveFcall struct{}
func (*RremoveFcall) MsgType ¶
func (m *RremoveFcall) MsgType() FcallType
type RstatFcall ¶
type RstatFcall struct {
Stat Stat
}
func (*RstatFcall) MsgType ¶
func (m *RstatFcall) MsgType() FcallType
type RversionFcall ¶
func (*RversionFcall) MsgType ¶
func (m *RversionFcall) MsgType() FcallType
type RwalkFcall ¶
type RwalkFcall struct {
Wqid []Qid
}
func (*RwalkFcall) MsgType ¶
func (m *RwalkFcall) MsgType() FcallType
type RwriteFcall ¶
type RwriteFcall struct {
Count uint32
}
func (*RwriteFcall) MsgType ¶
func (m *RwriteFcall) MsgType() FcallType
type RwstatFcall ¶
type RwstatFcall struct{}
func (*RwstatFcall) MsgType ¶
func (m *RwstatFcall) MsgType() FcallType
type Stat ¶
type Stat struct {
Type uint16 // kernel use; servers should leave this zero
Dev uint32 // kernel use; servers should leave this zero
Qid Qid
Mode Mode
Atime uint32
Mtime uint32
Length uint64
Name string
Uid string
Gid string
Muid string
// The following are 9P2000.u only: present on the wire, in this
// order, only when the connection negotiated VersionU. Extension
// holds a symlink's target when Mode has DMSYMLINK set. Nuid,
// Ngid, and Nmuid are the numeric counterparts of Uid/Gid/Muid.
Extension string
Nuid uint32
Ngid uint32
Nmuid uint32
}
Stat describes a file's metadata, as used in Tstat/Rstat, Twstat, and directory contents (a directory Read returns a concatenation of Stat blobs, one per entry).
func UnmarshalStat ¶
UnmarshalStat decodes a single plain-9P2000 Stat blob, including its leading size prefix. It returns ErrTrailingBytes if b holds more than one Stat's worth of data. Use UnmarshalStatVersion(b, true) to decode a 9P2000.u-flavored blob.
func UnmarshalStatVersion ¶ added in v0.9.0
UnmarshalStatVersion is UnmarshalStat, but expects the 9P2000.u fields to be present when unix is true.
func (Stat) Marshal ¶
Marshal encodes s as it appears on plain 9P2000: a 2-byte size prefix (the length of everything that follows) followed by the fixed and string fields. The 9P2000.u fields are never included; use MarshalVersion(true) on a connection that negotiated VersionU.
func (Stat) MarshalVersion ¶ added in v0.9.0
MarshalVersion is Marshal, but includes the 9P2000.u fields when unix is true.
type Tag ¶
type Tag uint16
Tag identifies an in-flight request so a reply can be matched to it. NoTag marks a message with no associated tag.
const NoTag Tag = 0xFFFF
NoTag marks a message with no associated tag. It is only ever used on the first Tversion of a connection.
type TattachFcall ¶
func (*TattachFcall) MsgType ¶
func (m *TattachFcall) MsgType() FcallType
type TauthFcall ¶
func (*TauthFcall) MsgType ¶
func (m *TauthFcall) MsgType() FcallType
type TclunkFcall ¶
type TclunkFcall struct {
Fid Fid
}
func (*TclunkFcall) MsgType ¶
func (m *TclunkFcall) MsgType() FcallType
type TcreateFcall ¶
type TcreateFcall struct {
Fid Fid
Name string
Perm Mode
Mode Mode
// Extension is 9P2000.u only: present on the wire only when the
// connection negotiated VersionU. It holds the symlink target
// when Perm has DMSYMLINK set.
Extension string
}
func (*TcreateFcall) MsgType ¶
func (m *TcreateFcall) MsgType() FcallType
type TflushFcall ¶
type TflushFcall struct {
Oldtag Tag
}
func (*TflushFcall) MsgType ¶
func (m *TflushFcall) MsgType() FcallType
type TopenFcall ¶
func (*TopenFcall) MsgType ¶
func (m *TopenFcall) MsgType() FcallType
type TreadFcall ¶
func (*TreadFcall) MsgType ¶
func (m *TreadFcall) MsgType() FcallType
type TremoveFcall ¶
type TremoveFcall struct {
Fid Fid
}
func (*TremoveFcall) MsgType ¶
func (m *TremoveFcall) MsgType() FcallType
type TstatFcall ¶
type TstatFcall struct {
Fid Fid
}
func (*TstatFcall) MsgType ¶
func (m *TstatFcall) MsgType() FcallType
type TversionFcall ¶
func (*TversionFcall) MsgType ¶
func (m *TversionFcall) MsgType() FcallType
type TwalkFcall ¶
func (*TwalkFcall) MsgType ¶
func (m *TwalkFcall) MsgType() FcallType
type TwriteFcall ¶
func (*TwriteFcall) MsgType ¶
func (m *TwriteFcall) MsgType() FcallType
type TwstatFcall ¶
func (*TwstatFcall) MsgType ¶
func (m *TwstatFcall) MsgType() FcallType
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client implements a 9P2000 client: dial or wrap a connection, attach to a server's exported tree, and walk, open, read, write, and stat files on it.
|
Package client implements a 9P2000 client: dial or wrap a connection, attach to a server's exported tree, and walk, open, read, write, and stat files on it. |
|
cmd
|
|
|
9pc
command
Command 9pc is a bare 9P2000 client: ls, cat, get, and put against a running 9P server, for manual testing and quick scripting.
|
Command 9pc is a bare 9P2000 client: ls, cat, get, and put against a running 9P server, for manual testing and quick scripting. |
|
9ps
command
Command 9ps serves a filesystem over 9P2000 on a TCP address: either a real directory (the default) or an in-memory scratch filesystem (-mem).
|
Command 9ps serves a filesystem over 9P2000 on a TCP address: either a real directory (the default) or an in-memory scratch filesystem (-mem). |
|
examples
|
|
|
dirfs
Package dirfs is a server.FileSystem backend that exports a real directory tree from the local filesystem, using only the standard library.
|
Package dirfs is a server.FileSystem backend that exports a real directory tree from the local filesystem, using only the standard library. |
|
memfs
Package memfs is an in-memory server.FileSystem backend: a tree of files and directories held entirely in memory, useful both as a demo server and as a test fixture for the server package.
|
Package memfs is an in-memory server.FileSystem backend: a tree of files and directories held entirely in memory, useful both as a demo server and as a test fixture for the server package. |
|
Package ns implements a Plan 9 style per-process namespace: a tree built purely by bind (no FUSE, no OS mount table), where a path may graft one or more underlying server.File trees on top of each other (a union directory) with Plan 9's before/after/replace disposition.
|
Package ns implements a Plan 9 style per-process namespace: a tree built purely by bind (no FUSE, no OS mount table), where a path may graft one or more underlying server.File trees on top of each other (a union directory) with Plan 9's before/after/replace disposition. |
|
Package server implements a 9P2000 server: given a FileSystem backend, it handles wire encoding, fid bookkeeping, multi-element walk batching, and Tflush cancellation, and exposes the backend to any 9P2000 client over a net.Listener or a single connection.
|
Package server implements a 9P2000 server: given a FileSystem backend, it handles wire encoding, fid bookkeeping, multi-element walk batching, and Tflush cancellation, and exposes the backend to any 9P2000 client over a net.Listener or a single connection. |