neinp: Index | Examples | Files | Directories

package neinp

import ""

Package neinp is a toolkit to implement 9p servers.

A 9p filesystem is created by implementing the P2000 interface, which is then used as argument for NewServer. Server can then use an io.ReadWriter supplied to the Serve method handle requests using the aforementioned P2000 implementer.

See for an example.

NB: This isn't really polished yet, things may break.



Package Files

doc.go nopfs.go server.go

type NopP2000 Uses

type NopP2000 struct{}

NopP2000 is a dummy impementation of interface P2000, returning error for every call. It can be embedded into own implementations if some functions aren't required. For a working mount (with p9p 9pfuse or linux kernel module), at least Version, Attach, Stat, Walk, Open, Read, and Clunk need to be implemented.

func (*NopP2000) Attach Uses

func (f *NopP2000) Attach(context.Context, message.TAttach) (message.RAttach, error)

func (*NopP2000) Auth Uses

func (f *NopP2000) Auth(context.Context, message.TAuth) (message.RAuth, error)

func (*NopP2000) Close Uses

func (f *NopP2000) Close() error

func (*NopP2000) Clunk Uses

func (f *NopP2000) Clunk(context.Context, message.TClunk) (message.RClunk, error)

func (*NopP2000) Create Uses

func (f *NopP2000) Create(context.Context, message.TCreate) (message.RCreate, error)

func (*NopP2000) Open Uses

func (f *NopP2000) Open(context.Context, message.TOpen) (message.ROpen, error)

func (*NopP2000) Read Uses

func (f *NopP2000) Read(context.Context, message.TRead) (message.RRead, error)

func (*NopP2000) Remove Uses

func (f *NopP2000) Remove(context.Context, message.TRemove) (message.RRemove, error)

func (*NopP2000) Stat Uses

func (f *NopP2000) Stat(context.Context, message.TStat) (message.RStat, error)

func (*NopP2000) Version Uses

func (f *NopP2000) Version(context.Context, message.TVersion) (message.RVersion, error)

func (*NopP2000) Walk Uses

func (f *NopP2000) Walk(context.Context, message.TWalk) (message.RWalk, error)

func (*NopP2000) Write Uses

func (f *NopP2000) Write(context.Context, message.TWrite) (message.RWrite, error)

func (*NopP2000) Wstat Uses

func (f *NopP2000) Wstat(context.Context, message.TWstat) (message.RWstat, error)

type P2000 Uses

type P2000 interface {
    Version(context.Context, message.TVersion) (message.RVersion, error)
    Auth(context.Context, message.TAuth) (message.RAuth, error)
    Attach(context.Context, message.TAttach) (message.RAttach, error)
    Walk(context.Context, message.TWalk) (message.RWalk, error)
    Open(context.Context, message.TOpen) (message.ROpen, error)
    Create(context.Context, message.TCreate) (message.RCreate, error)
    Read(context.Context, message.TRead) (message.RRead, error)
    Write(context.Context, message.TWrite) (message.RWrite, error)
    Clunk(context.Context, message.TClunk) (message.RClunk, error)
    Remove(context.Context, message.TRemove) (message.RRemove, error)
    Stat(context.Context, message.TStat) (message.RStat, error)
    Wstat(context.Context, message.TWstat) (message.RWstat, error)
    Close() error

P2000 is the interface which file systems must implement to be used with Server. To ease implementation of new filesystems, NopP2000 can be embedded. See the types defined in message for documentation of what they do.

type Server Uses

type Server struct {
    Debug bool
    // contains filtered or unexported fields

Server muxes and demuxes 9p messages from a connection, calling the corresponding handlers of a P2000 interface.


fs := &neinp.NopP2000{}

l, err := net.Listen("tcp", "localhost:9999")
if err != nil {
    fmt.Println("listen:", err)

for {
    c, err := l.Accept()
    if err != nil {
        fmt.Println("accept:", err)

    s := neinp.NewServer(fs)
    if err := s.Serve(c); err != nil {
        fmt.Println("serve:", err)

func NewServer Uses

func NewServer(fs P2000) *Server

NewServer returns a Server initialized to use fs for message handling.

func (*Server) Serve Uses

func (s *Server) Serve(rw io.ReadWriter) error

Serve the filesystem on the connection given by rw.

func (*Server) Shutdown Uses

func (s *Server) Shutdown() error

Shutdown serving the filesystem.


basicPackage basic handles en-/decoding of basic types to 9p wire format.
fidPackage fid supplies a fid type and the usual mutexed map for storing them.
fsPackage fs provides helpers to implement 9p objects: directories and files.
idPackage id provides utility functions to convert unix uid/gid to strings.
messagePackage message contains types for 9p messages.
qidPackage qid provides the qid type and supporting functionality.
statPackage stat provides functionality to handle 9p stat values.

Package neinp imports 8 packages (graph) and is imported by 1 packages. Updated 2020-11-24. Refresh now. Tools for package owners.