Ejemplo n.º 1
0
func (sfs *NopSrv) Read(req *go9p.SrvReq) {
	fid := req.Fid.Aux.(Dispatcher)
	tc := req.Tc
	rc := req.Rc

	if sfs.Debuglevel > 0 {
		log.Printf("read %T %s %d:%d", fid, fid, tc.Offset, tc.Count)
	}

	buf, err := fid.Read(req)
	if err != nil {
		req.RespondError(toError(err))
		return
	}

	go9p.InitRread(rc, tc.Count)
	count := 0
	switch {
	case tc.Offset > uint64(len(buf)):
		count = 0
	case len(buf[tc.Offset:]) > int(tc.Count):
		count = int(tc.Count)
	default:
		count = len(buf[tc.Offset:])
	}

	copy(rc.Data, buf[tc.Offset:int(tc.Offset)+count])
	go9p.SetRreadCount(rc, uint32(count))
	req.Respond()
}
Ejemplo n.º 2
0
Archivo: p9.go Proyecto: flynn/bake
// Read reads data from a file handle.
func (fs *fileSystem) Read(req *go9p.SrvReq) {
	aux := req.Fid.Aux.(*Aux)
	if err := aux.stat(); err != nil {
		req.RespondError(err)
		return
	}

	// Add to readset.
	fs.addToReadset(aux.rootID, aux.path)

	go9p.InitRread(req.Rc, req.Tc.Count)
	if aux.st.IsDir() {
		fs.readDir(req)
		return
	}
	fs.readFile(req)
}