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
func (fs *fileSystem) readFile(req *go9p.SrvReq) {
	aux := req.Fid.Aux.(*Aux)

	n, err := aux.file.ReadAt(req.Rc.Data, int64(req.Tc.Offset))
	if err != nil && err != io.EOF {
		req.RespondError(toError(err))
		return
	}

	go9p.SetRreadCount(req.Rc, uint32(n))
	req.Respond()
}
Ejemplo n.º 3
0
Archivo: p9.go Proyecto: flynn/bake
func (fs *fileSystem) readDir(req *go9p.SrvReq) {
	aux := req.Fid.Aux.(*Aux)

	var n int
	if req.Tc.Offset == 0 {
		// If we got here, it was open. Can't really seek
		// in most cases, just close and reopen it.
		aux.file.Close()

		file, err := os.OpenFile(aux.path, omode2uflags(req.Fid.Omode), 0)
		if err != nil {
			req.RespondError(toError(err))
			return
		}
		aux.file = file

		dirs, e := aux.file.Readdir(-1)
		if e != nil {
			req.RespondError(toError(e))
			return
		}
		aux.dirs = dirs

		aux.dirents = nil
		aux.direntends = nil
		for _, dir := range aux.dirs {
			path := aux.path + "/" + dir.Name()
			st, _ := new9pDir(path, dir, req.Conn.Dotu, req.Conn.Srv.Upool)
			if st == nil {
				continue
			}

			b := go9p.PackDir(st, req.Conn.Dotu)
			aux.dirents = append(aux.dirents, b...)
			n += len(b)
			aux.direntends = append(aux.direntends, n)
		}
	}

	switch {
	case req.Tc.Offset > uint64(len(aux.dirents)):
		n = 0
	case len(aux.dirents[req.Tc.Offset:]) > int(req.Tc.Count):
		n = int(req.Tc.Count)
	default:
		n = len(aux.dirents[req.Tc.Offset:])
	}

	copy(req.Rc.Data, aux.dirents[req.Tc.Offset:int(req.Tc.Offset)+n])

	go9p.SetRreadCount(req.Rc, uint32(n))
	req.Respond()
}