Documentation ¶
Index ¶
- Constants
- Variables
- func Dispatch(s *Server, b *bytes.Buffer, t MType) error
- func MarshalRattachPkt(b *bytes.Buffer, t Tag, QID QID)
- func MarshalRclunkPkt(b *bytes.Buffer, t Tag)
- func MarshalRcreatePkt(b *bytes.Buffer, t Tag, OQID QID, IOUnit MaxSize)
- func MarshalRerrorPkt(b *bytes.Buffer, t Tag, Error string)
- func MarshalRflushPkt(b *bytes.Buffer, t Tag)
- func MarshalRopenPkt(b *bytes.Buffer, t Tag, OQID QID, IOUnit MaxSize)
- func MarshalRreadPkt(b *bytes.Buffer, t Tag, Data []uint8)
- func MarshalRremovePkt(b *bytes.Buffer, t Tag)
- func MarshalRstatPkt(b *bytes.Buffer, t Tag, B []byte)
- func MarshalRversionPkt(b *bytes.Buffer, t Tag, RMsize MaxSize, RVersion string)
- func MarshalRwalkPkt(b *bytes.Buffer, t Tag, QIDs []QID)
- func MarshalRwritePkt(b *bytes.Buffer, t Tag, RLen Count)
- func MarshalRwstatPkt(b *bytes.Buffer, t Tag)
- func MarshalTattachPkt(b *bytes.Buffer, t Tag, SFID FID, AFID FID, Uname string, Aname string)
- func MarshalTclunkPkt(b *bytes.Buffer, t Tag, OFID FID)
- func MarshalTcreatePkt(b *bytes.Buffer, t Tag, OFID FID, Name string, CreatePerm Perm, Omode Mode)
- func MarshalTflushPkt(b *bytes.Buffer, t Tag, OTag Tag)
- func MarshalTopenPkt(b *bytes.Buffer, t Tag, OFID FID, Omode Mode)
- func MarshalTreadPkt(b *bytes.Buffer, t Tag, OFID FID, Off Offset, Len Count)
- func MarshalTremovePkt(b *bytes.Buffer, t Tag, OFID FID)
- func MarshalTstatPkt(b *bytes.Buffer, t Tag, OFID FID)
- func MarshalTversionPkt(b *bytes.Buffer, t Tag, TMsize MaxSize, TVersion string)
- func MarshalTwalkPkt(b *bytes.Buffer, t Tag, SFID FID, NewFID FID, Paths []string)
- func MarshalTwritePkt(b *bytes.Buffer, t Tag, OFID FID, Off Offset, Data []uint8)
- func MarshalTwstatPkt(b *bytes.Buffer, t Tag, OFID FID, B []byte)
- func Marshaldir(b *bytes.Buffer, D Dir)
- func ServerError(b *bytes.Buffer, s string)
- func UnmarshalRattachPkt(b *bytes.Buffer) (QID QID, t Tag, err error)
- func UnmarshalRcreatePkt(b *bytes.Buffer) (OQID QID, IOUnit MaxSize, t Tag, err error)
- func UnmarshalRopenPkt(b *bytes.Buffer) (OQID QID, IOUnit MaxSize, t Tag, err error)
- func UnmarshalRversionPkt(b *bytes.Buffer) (RMsize MaxSize, RVersion string, t Tag, err error)
- func UnmarshalRwalkPkt(b *bytes.Buffer) (QIDs []QID, t Tag, err error)
- func UnmarshalRwritePkt(b *bytes.Buffer) (RLen Count, t Tag, err error)
- func UnmarshalTattachPkt(b *bytes.Buffer) (SFID FID, AFID FID, Uname string, Aname string, t Tag, err error)
- func UnmarshalTclunkPkt(b *bytes.Buffer) (OFID FID, t Tag, err error)
- func UnmarshalTcreatePkt(b *bytes.Buffer) (OFID FID, Name string, CreatePerm Perm, Omode Mode, t Tag, err error)
- func UnmarshalTflushPkt(b *bytes.Buffer) (OTag Tag, t Tag, err error)
- func UnmarshalTopenPkt(b *bytes.Buffer) (OFID FID, Omode Mode, t Tag, err error)
- func UnmarshalTreadPkt(b *bytes.Buffer) (OFID FID, Off Offset, Len Count, t Tag, err error)
- func UnmarshalTremovePkt(b *bytes.Buffer) (OFID FID, t Tag, err error)
- func UnmarshalTstatPkt(b *bytes.Buffer) (OFID FID, t Tag, err error)
- func UnmarshalTversionPkt(b *bytes.Buffer) (TMsize MaxSize, TVersion string, t Tag, err error)
- func UnmarshalTwalkPkt(b *bytes.Buffer) (SFID FID, NewFID FID, Paths []string, t Tag, err error)
- func UnmarshalTwritePkt(b *bytes.Buffer) (OFID FID, Off Offset, Data []uint8, t Tag, err error)
- func UnmarshalTwstatPkt(b *bytes.Buffer) (OFID FID, B []byte, t Tag, err error)
- type Client
- func (c *Client) CallTattach(SFID FID, AFID FID, Uname string, Aname string) (QID QID, err error)
- func (c *Client) CallTclunk(OFID FID) (err error)
- func (c *Client) CallTcreate(OFID FID, Name string, CreatePerm Perm, Omode Mode) (OQID QID, IOUnit MaxSize, err error)
- func (c *Client) CallTflush(OTag Tag) (err error)
- func (c *Client) CallTopen(OFID FID, Omode Mode) (OQID QID, IOUnit MaxSize, err error)
- func (c *Client) CallTread(OFID FID, Off Offset, Len Count) (Data []uint8, err error)
- func (c *Client) CallTremove(OFID FID) (err error)
- func (c *Client) CallTstat(OFID FID) (B []byte, err error)
- func (c *Client) CallTversion(TMsize MaxSize, TVersion string) (RMsize MaxSize, RVersion string, err error)
- func (c *Client) CallTwalk(SFID FID, NewFID FID, Paths []string) (QIDs []QID, err error)
- func (c *Client) CallTwrite(OFID FID, Off Offset, Data []uint8) (RLen Count, err error)
- func (c *Client) CallTwstat(OFID FID, B []byte) (err error)
- func (c *Client) GetFID() FID
- func (c *Client) GetTag() Tag
- func (c *Client) IO()
- func (c *Client) String() string
- type ClientOpt
- type Count
- type Data
- type DataCnt16
- type Dir
- type DirPkt
- type Dispatcher
- type Error
- type FID
- type File
- type FileServer
- type MType
- type MaxSize
- type Mode
- type NineServer
- type NumEntries
- type Offset
- type Perm
- type QID
- type RPCCall
- type RPCReply
- type RattachPkt
- type RclunkPkt
- type RcreatePkt
- type RerrorPkt
- type RflushPkt
- type RopenPkt
- type RreadPkt
- type RremovePkt
- type RstatPkt
- type RversionPkt
- type RwalkPkt
- type RwritePkt
- type RwstatPkt
- type Server
- func (s *Server) NineServer() NineServer
- func (s *Server) SrvRattach(b *bytes.Buffer) (err error)
- func (s *Server) SrvRclunk(b *bytes.Buffer) (err error)
- func (s *Server) SrvRcreate(b *bytes.Buffer) (err error)
- func (s *Server) SrvRflush(b *bytes.Buffer) (err error)
- func (s *Server) SrvRopen(b *bytes.Buffer) (err error)
- func (s *Server) SrvRread(b *bytes.Buffer) (err error)
- func (s *Server) SrvRremove(b *bytes.Buffer) (err error)
- func (s *Server) SrvRstat(b *bytes.Buffer) (err error)
- func (s *Server) SrvRversion(b *bytes.Buffer) (err error)
- func (s *Server) SrvRwalk(b *bytes.Buffer) (err error)
- func (s *Server) SrvRwrite(b *bytes.Buffer) (err error)
- func (s *Server) SrvRwstat(b *bytes.Buffer) (err error)
- func (s *Server) Start()
- func (s *Server) String() string
- type ServerOpt
- type Service
- type Tag
- func UnmarshalRclunkPkt(b *bytes.Buffer) (t Tag, err error)
- func UnmarshalRerrorPkt(b *bytes.Buffer) (Error string, t Tag, err error)
- func UnmarshalRflushPkt(b *bytes.Buffer) (t Tag, err error)
- func UnmarshalRreadPkt(b *bytes.Buffer) (Data []uint8, t Tag, err error)
- func UnmarshalRremovePkt(b *bytes.Buffer) (t Tag, err error)
- func UnmarshalRstatPkt(b *bytes.Buffer) (B []byte, t Tag, err error)
- func UnmarshalRwstatPkt(b *bytes.Buffer) (t Tag, err error)
- type TattachPkt
- type TclunkPkt
- type TcreatePkt
- type TflushPkt
- type TopenPkt
- type Tracer
- type TreadPkt
- type TremovePkt
- type TstatPkt
- type TversionPkt
- type TwalkPkt
- type TwritePkt
- type TwstatPkt
Constants ¶
const ( MSIZE = 2*1048576 + IOHDRSZ // default message size (1048576+IOHdrSz) IOHDRSZ = 24 // the non-data size of the Twrite messages PORT = 564 // default port for 9P file servers NumFID = 1 << 16 QIDLen = 13 )
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 = 0x0 // open read-only OWRITE = 0x1 // open write-only ORDWR = 0x2 // open read-write OEXEC = 0x3 // execute (== read but check execute permission) OTRUNC = 0x10 // or'ed in (except for exec), truncate file first OCEXEC = 0x20 // or'ed in, close on exec ORCLOSE = 0x40 // or'ed in, remove on close OAPPEND = 0x80 // or'ed in, append only OEXCL = 0x1000 // or'ed in, exclusive client use )
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 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 Tag = 0xFFFF // no tag specified NOFID FID = 0xFFFFFFFF // no fid specified // We reserve tag NOTAG and tag 0. 0 is a troublesome value to pass // around, since it is also a default value and using it can hide errors // in the code. NumTags = 1<<16 - 2 )
const ( EPERM = 1 ENOENT = 2 EIO = 5 EACCES = 13 EEXIST = 17 ENOTDIR = 20 EINVAL = 22 )
Error values
Variables ¶
var ( RPCNames = map[MType]string{ Tversion: "Tversion", Rversion: "Rversion", Tauth: "Tauth", Rauth: "Rauth", Tattach: "Tattach", Rattach: "Rattach", Terror: "Terror", Rerror: "Rerror", Tflush: "Tflush", Rflush: "Rflush", Twalk: "Twalk", Rwalk: "Rwalk", Topen: "Topen", Ropen: "Ropen", Tcreate: "Tcreate", Rcreate: "Rcreate", Tread: "Tread", Rread: "Rread", Twrite: "Twrite", Rwrite: "Rwrite", Tclunk: "Tclunk", Rclunk: "Rclunk", Tremove: "Tremove", Rremove: "Rremove", Tstat: "Tstat", Rstat: "Rstat", Twstat: "Twstat", Rwstat: "Rwstat", } )
Functions ¶
func Dispatch ¶
Dispatch dispatches request to different functions. It's also the the first place we try to establish server semantics. We could do this with interface assertions and such a la rsc/fuse but most people I talked do disliked that. So we don't. If you want to make things optional, just define the ones you want to implement in this case.
func MarshalRclunkPkt ¶
func MarshalRflushPkt ¶
func MarshalRremovePkt ¶
func MarshalRversionPkt ¶
func MarshalRwstatPkt ¶
func MarshalTattachPkt ¶
func MarshalTcreatePkt ¶
func MarshalTreadPkt ¶
func MarshalTversionPkt ¶
func MarshalTwalkPkt ¶
func MarshalTwritePkt ¶
func Marshaldir ¶
func ServerError ¶
func UnmarshalRcreatePkt ¶
func UnmarshalRopenPkt ¶
func UnmarshalRversionPkt ¶
func UnmarshalTattachPkt ¶
func UnmarshalTcreatePkt ¶
func UnmarshalTopenPkt ¶
func UnmarshalTreadPkt ¶
func UnmarshalTversionPkt ¶
func UnmarshalTwalkPkt ¶
func UnmarshalTwritePkt ¶
Types ¶
type Client ¶
type Client struct { Tags chan Tag FID uint64 RPC []*RPCCall ToNet io.WriteCloser FromNet io.ReadCloser FromClient chan *RPCCall FromServer chan *RPCReply Msize uint32 Dead bool Trace Tracer }
Client implements a 9p client. It has a chan containing all tags, a scalar FID which is incremented to provide new FIDS (all FIDS for a given client are unique), an array of MaxTag-2 RPC structs, a ReadWriteCloser for IO, and two channels for a server goroutine: one down which RPCalls are pushed and another from which RPCReplys return. Once a client is marked Dead all further requests to it will fail. The ToNet/FromNet are separate so we can use io.Pipe for testing.
func (*Client) CallTattach ¶
func (*Client) CallTclunk ¶
func (*Client) CallTcreate ¶
func (*Client) CallTflush ¶
func (*Client) CallTremove ¶
func (*Client) CallTversion ¶
func (*Client) CallTwrite ¶
func (*Client) GetFID ¶
GetFID gets a fid to be used to identify a resource for a 9p client. For a given lifetime of a 9p client, FIDS are unique (i.e. not reused as in many 9p client libraries).
type DataCnt16 ¶
type DataCnt16 byte // []byte with a 16-bit count.
Some []byte fields are encoded with a 16-bit length, e.g. stat data. We use this type to tag such fields. The parameters are still []byte, this was just the only way I could think of to make the stub generator do the right thing.
type Dir ¶
type Dir struct { Type uint16 Dev uint32 QID 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 User string // owner name Group string // group name ModUser string // name of the last user that modified the file }
Dir describes a file
type File ¶
type File struct { }
A File is defined by a QID. File Servers never see a FID. There are two channels. The first is for normal requests. The second is for Flushes. File server code always checks the flush channel first. At the same time, server code puts the flush into both channels, so the server code has some idea when the flush entered the queue. This is very similar to how MSI-X works on PCIe ...
type FileServer ¶
Server maintains file system server state. This is inclusive of RPC server state plus more. In our case when we walk to a fid we kick off a goroutine to manage it. As a result we need a map of Tag to FID so we know what to do about Tflush.
type NineServer ¶
type NineServer interface { Rversion(MaxSize, string) (MaxSize, string, error) Rattach(FID, FID, string, string) (QID, error) Rwalk(FID, FID, []string) ([]QID, error) Ropen(FID, Mode) (QID, MaxSize, error) Rcreate(FID, string, Perm, Mode) (QID, MaxSize, error) Rstat(FID) ([]byte, error) Rwstat(FID, []byte) error Rclunk(FID) error Rremove(FID) error Rread(FID, Offset, Count) ([]byte, error) Rwrite(FID, Offset, []byte) (Count, error) Rflush(Otag Tag) error }
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
type RattachPkt ¶
type RattachPkt struct {
QID QID
}
type RcreatePkt ¶
type RremovePkt ¶
type RremovePkt struct { }
type RversionPkt ¶
type Server ¶
type Server struct { NS NineServer D Dispatcher Versioned bool FromNet io.ReadCloser ToNet io.WriteCloser Replies chan RPCReply Trace Tracer Dead bool // contains filtered or unexported fields }
Server is a 9p server. For now it's extremely serial. But we will use a chan for replies to ensure that we can go to a more concurrent one later.
func (*Server) NineServer ¶
func (s *Server) NineServer() NineServer
type Service ¶
A service is a closure which returns an error or nil. It writes its result down the provided channel. It looks for flushes on the flushchan before doing its function, and will respond to all flushes while any are pending.
type TremovePkt ¶
type TremovePkt struct {
OFID FID
}