p

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2017 License: Apache-2.0, BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

The p9 package provides the definitions and functions used to implement the 9P2000 protocol.

Index

Constants

View Source
const (
	Tversion = 100 + iota
	Rversion
	Tauth
	Rauth
	Tattach
	Rattach
	Terror
	Rerror
	Tflush
	Rflush
	Twalk
	Rwalk
	Topen
	Ropen
	Tcreate
	Rcreate
	Tread
	Rread
	Twrite
	Rwrite
	Tclunk
	Rclunk
	Tremove
	Rremove
	Tstat
	Rstat
	Twstat
	Rwstat
	Tlast
)

9P2000 message types

View Source
const (
	MSIZE   = 8192 + IOHDRSZ // default message size (8192+IOHdrSz)
	IOHDRSZ = 24             // the non-data size of the Twrite messages
	PORT    = 564            // default port for 9P file servers
)
View Source
const (
	QTDIR     = 0x80 // directories
	QTAPPEND  = 0x40 // append only files
	QTEXCL    = 0x20 // exclusive use files
	QTMOUNT   = 0x10 // mounted channel
	QTAUTH    = 0x08 // authentication file
	QTTMP     = 0x04 // non-backed-up file
	QTSYMLINK = 0x02 // symbolic link (Unix, 9P2000.u)
	QTLINK    = 0x01 // hard link (Unix, 9P2000.u)
	QTFILE    = 0x00
)

Qid types

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
	DMSYMLINK   = 0x02000000 // mode bit for symbolic link (Unix, 9P2000.u)
	DMLINK      = 0x01000000 // mode bit for hard link (Unix, 9P2000.u)
	DMDEVICE    = 0x00800000 // mode bit for device file (Unix, 9P2000.u)
	DMNAMEDPIPE = 0x00200000 // mode bit for named pipe (Unix, 9P2000.u)
	DMSOCKET    = 0x00100000 // mode bit for socket (Unix, 9P2000.u)
	DMSETUID    = 0x00080000 // mode bit for setuid (Unix, 9P2000.u)
	DMSETGID    = 0x00040000 // mode bit for setgid (Unix, 9P2000.u)
	DMREAD      = 0x4        // mode bit for read permission
	DMWRITE     = 0x2        // mode bit for write permission
	DMEXEC      = 0x1        // mode bit for execute permission
)

File modes

View Source
const (
	NOTAG uint16 = 0xFFFF     // no tag specified
	NOFID uint32 = 0xFFFFFFFF // no fid specified
	NOUID uint32 = 0xFFFFFFFF // no uid specified
)
View Source
const (
	EPERM   = 1
	ENOENT  = 2
	EIO     = 5
	EEXIST  = 17
	ENOTDIR = 20
	EINVAL  = 22
)

Error values

Variables

View Source
var OsUsers *osUsers

Simple Users implementation that defers to os/user and fakes looking up groups by gid only.

Functions

func Gint32

func Gint32(buf []byte) (uint32, []byte)

func InitRread

func InitRread(fc *Fcall, count uint32) error

Initializes the specified Fcall value to contain Rread message. The user should copy the returned data to the slice pointed by fc.Data and call SetRreadCount to update the data size to the actual value.

func PackDir

func PackDir(d *Dir, buf []byte, dotu bool) int

Converts a Dir value to its on-the-wire representation and writes it to the buf. Returns the number of bytes written, 0 if there is not enough space.

func PackRattach

func PackRattach(fc *Fcall, aqid *Qid) error

Create a Rattach message in the specified Fcall.

func PackRauth

func PackRauth(fc *Fcall, aqid *Qid) error

Create a Rauth message in the specified Fcall.

func PackRclunk

func PackRclunk(fc *Fcall) error

Create a Rclunk message in the specified Fcall.

func PackRcreate

func PackRcreate(fc *Fcall, qid *Qid, iounit uint32) error

Create a Rcreate message in the specified Fcall.

func PackRerror

func PackRerror(fc *Fcall, error string, errornum uint32, dotu bool) error

Create a Rerror message in the specified Fcall. If dotu is true, the function will create a 9P2000.u message. If false, nerror is ignored.

func PackRflush

func PackRflush(fc *Fcall) error

Create a Rflush message in the specified Fcall.

func PackRopen

func PackRopen(fc *Fcall, qid *Qid, iounit uint32) error

Create a Ropen message in the specified Fcall.

func PackRread

func PackRread(fc *Fcall, data []byte) error

Create a Rread message in the specified Fcall.

func PackRremove

func PackRremove(fc *Fcall) error

Create a Rremove message in the specified Fcall.

func PackRstat

func PackRstat(fc *Fcall, d *Dir, dotu bool) error

Create a Rstat message in the specified Fcall. If dotu is true, the function will create a 9P2000.u stat representation that includes st.Nuid, st.Ngid, st.Nmuid and st.Ext. Otherwise these values will be ignored.

func PackRversion

func PackRversion(fc *Fcall, msize uint32, version string) error

Create a Rversion message in the specified Fcall.

func PackRwalk

func PackRwalk(fc *Fcall, wqids []Qid) error

Create a Rwalk message in the specified Fcall.

func PackRwrite

func PackRwrite(fc *Fcall, count uint32) error

Create a Rwrite message in the specified Fcall.

func PackRwstat

func PackRwstat(fc *Fcall) error

Create a Rwstat message in the specified Fcall.

func PackTattach

func PackTattach(fc *Fcall, fid uint32, afid uint32, uname string, aname string, unamenum uint32, dotu bool) error

Create a Tattach message in the specified Fcall. If dotu is true, the function will create 9P2000.u including the nuname value, otherwise nuname is ignored.

func PackTauth

func PackTauth(fc *Fcall, fid uint32, uname string, aname string, unamenum uint32, dotu bool) error

Create a Tauth message in the specified Fcall.

func PackTclunk

func PackTclunk(fc *Fcall, fid uint32) error

Create a Tclunk message in the specified Fcall.

func PackTcreate

func PackTcreate(fc *Fcall, fid uint32, name string, perm uint32, mode uint8, ext string, dotu bool) error

Create a Tcreate message in the specified Fcall. If dotu is true, the function will create a 9P2000.u message that includes ext. Otherwise the ext value is ignored.

func PackTflush

func PackTflush(fc *Fcall, oldtag uint16) error

Create a Tflush message in the specified Fcall.

func PackTopen

func PackTopen(fc *Fcall, fid uint32, mode uint8) error

Create a Topen message in the specified Fcall.

func PackTread

func PackTread(fc *Fcall, fid uint32, offset uint64, count uint32) error

Create a Tread message in the specified Fcall.

func PackTremove

func PackTremove(fc *Fcall, fid uint32) error

Create a Tremove message in the specified Fcall.

func PackTstat

func PackTstat(fc *Fcall, fid uint32) error

Create a Tstat message in the specified Fcall.

func PackTversion

func PackTversion(fc *Fcall, msize uint32, version string) error

Create a Tversion message in the specified Fcall.

func PackTwalk

func PackTwalk(fc *Fcall, fid uint32, newfid uint32, wnames []string) error

Create a Twalk message in the specified Fcall.

func PackTwrite

func PackTwrite(fc *Fcall, fid uint32, offset uint64, count uint32, data []byte) error

Create a Twrite message in the specified Fcall.

func PackTwstat

func PackTwstat(fc *Fcall, fid uint32, d *Dir, dotu bool) error

Create a Twstat message in the specified Fcall. If dotu is true the function will create 9P2000.u message, otherwise the 9P2000.u specific fields from the Stat value will be ignored.

func SetRreadCount

func SetRreadCount(fc *Fcall, count uint32)

Updates the size of the data returned by Rread. Expects that the Fcall value is already initialized by InitRread.

func SetTag

func SetTag(fc *Fcall, tag uint16)

Sets the tag of a Fcall.

Types

type Dir

type Dir struct {
	Size   uint16 // size-2 of the Dir on the wire
	Type   uint16
	Dev    uint32
	Qid           // file's Qid
	Mode   uint32 // permissions and flags
	Atime  uint32 // last access time in seconds
	Mtime  uint32 // last modified time in seconds
	Length uint64 // file length in bytes
	Name   string // file name
	Uid    string // owner name
	Gid    string // group name
	Muid   string // name of the last user that modified the file

	/* 9P2000.u extension */
	Ext     string // special file's descriptor
	Uidnum  uint32 // owner ID
	Gidnum  uint32 // group ID
	Muidnum uint32 // ID of the last user that modified the file
}

Dir describes a file

func UnpackDir

func UnpackDir(buf []byte, dotu bool) (d *Dir, err error)

Converts the on-the-wire representation of a stat to Stat value. Returns an error if the conversion is impossible, otherwise a pointer to a Stat value.

func (*Dir) String

func (d *Dir) String() string

type Error

type Error struct {
	Err      string // textual representation of the error
	Errornum uint32 // numeric representation of the error (9P2000.u)
}

Error represents a 9P2000 (and 9P2000.u) error

func (*Error) Error

func (err *Error) Error() string

type Fcall

type Fcall struct {
	Size    uint32   // size of the message
	Type    uint8    // message type
	Fid     uint32   // file identifier
	Tag     uint16   // message tag
	Msize   uint32   // maximum message size (used by Tversion, Rversion)
	Version string   // protocol version (used by Tversion, Rversion)
	Oldtag  uint16   // tag of the message to flush (used by Tflush)
	Error   string   // error (used by Rerror)
	Qid              // file Qid (used by Rauth, Rattach, Ropen, Rcreate)
	Iounit  uint32   // maximum bytes read without breaking in multiple messages (used by Ropen, Rcreate)
	Afid    uint32   // authentication fid (used by Tauth, Tattach)
	Uname   string   // user name (used by Tauth, Tattach)
	Aname   string   // attach name (used by Tauth, Tattach)
	Perm    uint32   // file permission (mode) (used by Tcreate)
	Name    string   // file name (used by Tcreate)
	Mode    uint8    // open mode (used by Topen, Tcreate)
	Newfid  uint32   // the fid that represents the file walked to (used by Twalk)
	Wname   []string // list of names to walk (used by Twalk)
	Wqid    []Qid    // list of Qids for the walked files (used by Rwalk)
	Offset  uint64   // offset in the file to read/write from/to (used by Tread, Twrite)
	Count   uint32   // number of bytes read/written (used by Tread, Rread, Twrite, Rwrite)
	Data    []uint8  // data read/to-write (used by Rread, Twrite)
	Dir              // file description (used by Rstat, Twstat)

	/* 9P2000.u extensions */
	Errornum uint32 // error code, 9P2000.u only (used by Rerror)
	Ext      string // special file description, 9P2000.u only (used by Tcreate)
	Unamenum uint32 // user ID, 9P2000.u only (used by Tauth, Tattach)

	Pkt []uint8 // raw packet data
	Buf []uint8 // buffer to put the raw data in
}

Fcall represents a 9P2000 message

func NewFcall

func NewFcall(sz uint32) *Fcall

Allocates a new Fcall.

func Unpack

func Unpack(buf []byte, dotu bool) (fc *Fcall, err error, fcsz int)

Creates a Fcall value from the on-the-wire representation. If dotu is true, reads 9P2000.u messages. Returns the unpacked message, error and how many bytes from the buffer were used by the message.

func (*Fcall) String

func (fc *Fcall) String() string

type Group

type Group interface {
	Name() string    // group name
	Id() int         // group id
	Members() []User // list of members that belong to the group (can return nil)
}

Represents a group of users

type Log

type Log struct {
	Data  interface{}
	Owner interface{}
	Type  int
}

type Logger

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

func NewLogger

func NewLogger(sz int) *Logger

func (*Logger) Filter

func (l *Logger) Filter(owner interface{}, itype int) []*Log

func (*Logger) Log

func (l *Logger) Log(data, owner interface{}, itype int)

func (*Logger) Resize

func (l *Logger) Resize(sz int)

type Qid

type Qid struct {
	Type    uint8  // type of the file (high 8 bits of the mode)
	Version uint32 // version number for the path
	Path    uint64 // server's unique identification of the file
}

File identifier

func (*Qid) String

func (qid *Qid) String() string

type User

type User interface {
	Name() string          // user name
	Id() int               // user id
	Groups() []Group       // groups the user belongs to (can return nil)
	IsMember(g Group) bool // returns true if the user is member of the specified group
}

Represents a user

type Users

type Users interface {
	Uid2User(uid int) User
	Uname2User(uname string) User
	Gid2Group(gid int) Group
	Gname2Group(gname string) Group
}

Interface for accessing users and groups

Directories

Path Synopsis
The clnt package provides definitions and functions used to implement a 9P2000 file client.
The clnt package provides definitions and functions used to implement a 9P2000 file client.
examples/tls
Connects to a server over TLS and lists the specified directory
Connects to a server over TLS and lists the specified directory
srv
The srv package provides definitions and functions used to implement a 9P2000 file server.
The srv package provides definitions and functions used to implement a 9P2000 file server.
examples/tlsramfs
Listen on SSL connection, can be used as an example with p/clnt/examples/tls.go Sample certificate was copied from the Go source code
Listen on SSL connection, can be used as an example with p/clnt/examples/tls.go Sample certificate was copied from the Go source code

Jump to

Keyboard shortcuts

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