Пример #1
0
// Creates a fid for the specified user that points to the root
// of the file server's file tree. Returns a Fid pointing to the root,
// if successful, or an Error.
func (clnt *Client) Attach(afid *Fid, user g9p.User, aname string) (*Fid, error) {
	var afno uint32

	if afid != nil {
		afno = afid.Fid
	} else {
		afno = g9p.NOFID
	}

	fid := clnt.fidAlloc()
	tc := clnt.newFcall()
	err := g9p.PackTattach(tc, fid.Fid, afno, user.Name(), aname, uint32(user.Id()), clnt.dotu)
	if err != nil {
		return nil, err
	}

	rc, err := clnt.rpc(tc)
	if err != nil {
		return nil, err
	}
	if rc.Type == g9p.Rerror {
		return nil, &g9p.Error{rc.Error, int(rc.Errornum)}
	}

	fid.Qid = rc.Qid
	fid.User = user
	return fid, nil
}
Пример #2
0
// Creates an authentication fid for the specified user. Returns the fid, if
// successful, or an Error.
func (clnt *Client) Auth(user g9p.User, aname string) (*Fid, error) {
	fid := clnt.fidAlloc()
	tc := clnt.newFcall()
	err := g9p.PackTauth(tc, fid.Fid, user.Name(), aname, uint32(user.Id()), clnt.dotu)
	if err != nil {
		return nil, err
	}

	_, err = clnt.rpc(tc)
	if err != nil {
		return nil, err
	}

	fid.User = user
	return fid, nil
}