Beispiel #1
0
// NewClient creates opens a connection with the p9p server
func NewClient(ctx context.Context, conn net.Conn) (*Client, error) {
	session, err := p9p.NewSession(ctx, conn)
	if err != nil {
		log.Println("Failed to establish 9P session to", err)
		return nil, err
	}
	root := p9p.Fid(1)
	if _, err := session.Attach(ctx, root, p9p.NOFID, "anyone", "/"); err != nil {
		log.Println("Failed to Attach to filesystem", err)
		return nil, err
	}
	usedFids := make(map[p9p.Fid]bool, 0)
	freeFids := make([]p9p.Fid, 0)
	for i := 0; i < 128; i++ {
		fid := p9p.Fid(i)
		if fid == root {
			usedFids[fid] = true
		} else {
			freeFids = append(freeFids, fid)
			usedFids[fid] = false
		}
	}
	var m sync.Mutex
	c := sync.NewCond(&m)
	return &Client{conn, session, &m, c, usedFids, freeFids, root}, nil
}
Beispiel #2
0
	p9p "github.com/docker/go-p9p"
	"golang.org/x/net/context"
)

type Client struct {
	conn     net.Conn
	session  p9p.Session
	m        *sync.Mutex
	c        *sync.Cond
	usedFids map[p9p.Fid]bool
	freeFids []p9p.Fid
	root     p9p.Fid
}

var badFid = p9p.Fid(0)

var rwx = p9p.DMREAD | p9p.DMWRITE | p9p.DMEXEC
var rx = p9p.DMREAD | p9p.DMEXEC
var rw = p9p.DMREAD | p9p.DMWRITE
var r = p9p.DMREAD
var dirperm = uint32(rwx<<6 | rx<<3 | rx | p9p.DMDIR)
var fileperm = uint32(rw<<6 | r<<3 | r)

// Dial opens a connection to a 9P server
func Dial(ctx context.Context, network, address string) (*Client, error) {
	log.Println("Dialling", network, address)
	conn, err := net.Dial(network, address)
	if err != nil {
		return nil, err
	}