Exemple #1
0
func dirUnpack(b []byte) ([]*plan9.Dir, error) {
	var err error
	dirs := make([]*plan9.Dir, 0, 10)
	for len(b) > 0 {
		if len(b) < 2 {
			err = io.ErrUnexpectedEOF
			break
		}
		n := int(b[0]) | int(b[1])<<8
		if len(b) < n+2 {
			err = io.ErrUnexpectedEOF
			break
		}
		var d *plan9.Dir
		d, err = plan9.UnmarshalDir(b[0 : n+2])
		if err != nil {
			break
		}
		b = b[n+2:]
		if len(dirs) >= cap(dirs) {
			ndirs := make([]*plan9.Dir, len(dirs), 2*cap(dirs))
			copy(ndirs, dirs)
			dirs = ndirs
		}
		n = len(dirs)
		dirs = dirs[0 : n+1]
		dirs[n] = d
	}
	return dirs, err
}
Exemple #2
0
func (fid *Fid) Stat() (*plan9.Dir, error) {
	tx := &plan9.Fcall{Type: plan9.Tstat, Fid: fid.fid}
	rx, err := fid.c.rpc(tx)
	if err != nil {
		return nil, err
	}
	return plan9.UnmarshalDir(rx.Stat)
}