示例#1
0
文件: p9.go 项目: 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()
}
示例#2
0
文件: dispatch.go 项目: wwaites/nopfs
func (a *AnyDir) Read(req *go9p.SrvReq) ([]byte, error) {
	a.lock.RLock()
	defer a.lock.RUnlock()
	if a.listing == nil {
		a.listing = make([]byte, 0)
		for name, subDisp := range a.static {
			path := append(a.GetPath(), name)
			newDisp := subDisp.Clone()
			newDisp.SetPath(path)
			b := go9p.PackDir(Fstat(newDisp), req.Conn.Dotu)
			a.listing = append(a.listing, b...)
		}
		for name, _ := range a.history {
			subDir := NewDir()
			path := append(a.path, name)
			subDir.SetPath(path)
			subDir.entries = a.entries
			b := go9p.PackDir(Fstat(subDir), true)
			a.listing = append(a.listing, b...)
		}
	}
	return a.listing, nil
}
示例#3
0
文件: dispatch.go 项目: wwaites/nopfs
func (d *Dir) Read(req *go9p.SrvReq) ([]byte, error) {
	d.RLock()
	defer d.RUnlock()
	if d.listing == nil {
		d.listing = make([]byte, 0)
		for name, subDisp := range d.entries {
			path := append(d.GetPath(), name)
			newDisp := subDisp.Clone()
			newDisp.SetPath(path)
			b := go9p.PackDir(Fstat(newDisp), req.Conn.Dotu)
			d.listing = append(d.listing, b...)
		}
	}
	return d.listing, nil
}