Documentation ¶
Overview ¶
The p9 package provides the definitions and functions used to implement the 9P2000 protocol.
Index ¶
- Constants
- Variables
- func Gint32(buf []byte) (uint32, []byte)
- func InitRread(fc *Fcall, count uint32) error
- func PackDir(d *Dir, buf []byte, dotu bool) int
- func PackRattach(fc *Fcall, aqid *Qid) error
- func PackRauth(fc *Fcall, aqid *Qid) error
- func PackRclunk(fc *Fcall) error
- func PackRcreate(fc *Fcall, qid *Qid, iounit uint32) error
- func PackRerror(fc *Fcall, error string, errornum uint32, dotu bool) error
- func PackRflush(fc *Fcall) error
- func PackRopen(fc *Fcall, qid *Qid, iounit uint32) error
- func PackRread(fc *Fcall, data []byte) error
- func PackRremove(fc *Fcall) error
- func PackRstat(fc *Fcall, d *Dir, dotu bool) error
- func PackRversion(fc *Fcall, msize uint32, version string) error
- func PackRwalk(fc *Fcall, wqids []Qid) error
- func PackRwrite(fc *Fcall, count uint32) error
- func PackRwstat(fc *Fcall) error
- func PackTattach(fc *Fcall, fid uint32, afid uint32, uname string, aname string, ...) error
- func PackTauth(fc *Fcall, fid uint32, uname string, aname string, unamenum uint32, dotu bool) error
- func PackTclunk(fc *Fcall, fid uint32) error
- func PackTcreate(fc *Fcall, fid uint32, name string, perm uint32, mode uint8, ext string, ...) error
- func PackTflush(fc *Fcall, oldtag uint16) error
- func PackTopen(fc *Fcall, fid uint32, mode uint8) error
- func PackTread(fc *Fcall, fid uint32, offset uint64, count uint32) error
- func PackTremove(fc *Fcall, fid uint32) error
- func PackTstat(fc *Fcall, fid uint32) error
- func PackTversion(fc *Fcall, msize uint32, version string) error
- func PackTwalk(fc *Fcall, fid uint32, newfid uint32, wnames []string) error
- func PackTwrite(fc *Fcall, fid uint32, offset uint64, count uint32, data []byte) error
- func PackTwstat(fc *Fcall, fid uint32, d *Dir, dotu bool) error
- func SetRreadCount(fc *Fcall, count uint32)
- func SetTag(fc *Fcall, tag uint16)
- type Dir
- type Error
- type Fcall
- type Group
- type Log
- type Logger
- type Qid
- type User
- type Users
Constants ¶
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
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 )
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
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 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
const ( NOTAG uint16 = 0xFFFF // no tag specified NOFID uint32 = 0xFFFFFFFF // no fid specified NOUID uint32 = 0xFFFFFFFF // no uid specified )
const ( EPERM = 1 ENOENT = 2 EIO = 5 EEXIST = 17 ENOTDIR = 20 EINVAL = 22 )
Error values
Variables ¶
var OsUsers *osUsers
Simple Users implementation that defers to os/user and fakes looking up groups by gid only.
Functions ¶
func InitRread ¶
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 ¶
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 ¶
Create a Rattach message in the specified Fcall.
func PackRcreate ¶
Create a Rcreate message in the specified Fcall.
func PackRerror ¶
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 PackRremove ¶
Create a Rremove message in the specified Fcall.
func PackRstat ¶
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 ¶
Create a Rversion message in the specified Fcall.
func PackRwrite ¶
Create a Rwrite 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 PackTclunk ¶
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 ¶
Create a Tflush message in the specified Fcall.
func PackTremove ¶
Create a Tremove message in the specified Fcall.
func PackTversion ¶
Create a Tversion message in the specified Fcall.
func PackTwrite ¶
Create a Twrite message in the specified Fcall.
func PackTwstat ¶
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 ¶
Updates the size of the data returned by Rread. Expects that the Fcall value is already initialized by InitRread.
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
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
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) Pkt []uint8 // raw packet data Buf []uint8 // buffer to put the raw data in }
Fcall represents a 9P2000 message
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 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
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 |
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 |