当前位置: 首页>>代码示例>>Golang>>正文


Golang srv.Req类代码示例

本文整理汇总了Golang中github.com/lionkov/ninep/srv.Req的典型用法代码示例。如果您正苦于以下问题:Golang Req类的具体用法?Golang Req怎么用?Golang Req使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Req类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Attach

func (*NullFS) Attach(req *srv.Req) {

	if req.Afid != nil {
		req.RespondError(srv.Enoauth)
		return
	}

	req.Fid.Aux = &Fid{NullFile: NullFile{Name: "."}}

	req.RespondRattach(dirQids["."])
}
开发者ID:hugelgupf,项目名称:ninep,代码行数:11,代码来源:nullfs.go

示例2: Stat

func (f *NullFS) Stat(req *srv.Req) {
	fid := req.Fid.Aux.(*Fid)
	d := &ninep.Dir{
		Qid:  *fid.Qid,
		Type: uint16(fid.Type),
		Mode: uint32(fid.Type) | fid.Version,
		Name: fid.Name,
		Uid:  "root",
		Gid:  "root",
	}
	req.RespondRstat(d)
}
开发者ID:hugelgupf,项目名称:ninep,代码行数:12,代码来源:nullfs.go

示例3: Walk

func (f *NullFS) Walk(req *srv.Req) {
	tc := req.Tc

	if len(tc.Wname) > 1 && tc.Qid.Type != ninep.QTDIR {
		req.RespondError(ninep.ENOENT)
		return
	}

	// The most common case is walking from '.', so we initialize to '.' and fix it up
	// later if needed.
	if req.Newfid.Aux == nil {
		req.Newfid.Aux = &Fid{NullFile: NullFile{Name: ".", Qid: dirQids["."]}}
	}

	if len(tc.Wname) == 0 {
		req.RespondRwalk([]ninep.Qid{})
		return
	}

	if q, ok := dirQids[tc.Wname[0]]; !ok {
		req.RespondError(ninep.ENOENT)
	} else {
		req.Newfid.Aux.(*Fid).Name = tc.Wname[0]
		req.Newfid.Aux.(*Fid).Qid = q
		req.RespondRwalk([]ninep.Qid{*q})
	}
}
开发者ID:hugelgupf,项目名称:ninep,代码行数:27,代码来源:nullfs.go

示例4: Read

func (f *NullFS) Read(r *srv.Req) {
	var count int

	ninep.InitRread(r.Rc, r.Tc.Count)
	fid := r.Fid.Aux.(*Fid)

	if fid.Qid.Path == Qroot {
		var dirents []byte
		for path, v := range dirQids {
			d := &ninep.Dir{
				Qid:  *v,
				Type: uint16(v.Type),
				Mode: uint32(v.Type) | v.Version,
				Name: path,
				Uid:  "root",
				Gid:  "root",
			}
			b := ninep.PackDir(d, true)
			dirents = append(dirents, b...)
			count += len(b)
		}

		// TODO: put this boilerplate into a helper function.
		switch {
		case r.Tc.Offset > uint64(len(dirents)):
			count = 0
		case len(dirents[r.Tc.Offset:]) > int(r.Tc.Count):
			count = int(r.Tc.Count)
		default:
			count = len(dirents[r.Tc.Offset:])
		}

		if count == 0 && int(r.Tc.Offset) < len(dirents) && len(dirents) > 0 {
			r.RespondError(&ninep.Error{Err: "too small read size for dir entry", Errornum: ninep.EINVAL})
			return
		}
		copy(r.Rc.Data, dirents[r.Tc.Offset:int(r.Tc.Offset)+count])
	} else {
		if fid.Qid.Path == Qzero {
			count = int(r.Tc.Count)
		}
	}
	ninep.SetRreadCount(r.Rc, uint32(count))
	r.Respond()
}
开发者ID:hugelgupf,项目名称:ninep,代码行数:45,代码来源:nullfs.go

示例5: Stat

func (*Ufs) Stat(req *srv.Req) {
	fid := req.Fid.Aux.(*Fid)
	if err := fid.stat(); err != nil {
		req.RespondError(err)
		return
	}

	st, err := dir2Dir(fid.path, fid.st, req.Conn.Dotu, req.Conn.Srv.Upool)
	if err != nil {
		req.RespondError(err)
		return
	}
	req.RespondRstat(st)
}
开发者ID:hugelgupf,项目名称:ninep,代码行数:14,代码来源:ufs.go

示例6: Remove

func (*Ufs) Remove(req *srv.Req) {
	fid := req.Fid.Aux.(*Fid)
	err := fid.stat()
	if err != nil {
		req.RespondError(err)
		return
	}

	e := os.Remove(fid.path)
	if e != nil {
		req.RespondError(toError(e))
		return
	}

	req.RespondRremove()
}
开发者ID:hugelgupf,项目名称:ninep,代码行数:16,代码来源:ufs.go

示例7: Write

func (*Ufs) Write(req *srv.Req) {
	fid := req.Fid.Aux.(*Fid)
	tc := req.Tc
	err := fid.stat()
	if err != nil {
		req.RespondError(err)
		return
	}

	n, e := fid.file.WriteAt(tc.Data, int64(tc.Offset))
	if e != nil {
		req.RespondError(toError(e))
		return
	}

	req.RespondRwrite(uint32(n))
}
开发者ID:hugelgupf,项目名称:ninep,代码行数:17,代码来源:ufs.go

示例8: Open

func (*Ufs) Open(req *srv.Req) {
	fid := req.Fid.Aux.(*Fid)
	tc := req.Tc
	err := fid.stat()
	if err != nil {
		req.RespondError(err)
		return
	}

	var e error
	fid.file, e = os.OpenFile(fid.path, omode2uflags(tc.Mode), 0)
	if e != nil {
		req.RespondError(toError(e))
		return
	}

	req.RespondRopen(dir2Qid(fid.st), 0)
}
开发者ID:hugelgupf,项目名称:ninep,代码行数:18,代码来源:ufs.go

示例9: Walk

func (*Ufs) Walk(req *srv.Req) {
	fid := req.Fid.Aux.(*Fid)
	tc := req.Tc

	err := fid.stat()
	if err != nil {
		req.RespondError(err)
		return
	}

	if req.Newfid.Aux == nil {
		req.Newfid.Aux = new(Fid)
	}

	nfid := req.Newfid.Aux.(*Fid)
	wqids := make([]ninep.Qid, len(tc.Wname))
	path := fid.path
	i := 0
	for ; i < len(tc.Wname); i++ {
		p := path + "/" + tc.Wname[i]
		st, err := os.Lstat(p)
		if err != nil {
			if i == 0 {
				req.RespondError(Enoent)
				return
			}

			break
		}

		wqids[i] = *dir2Qid(st)
		path = p
	}

	nfid.path = path
	req.RespondRwalk(wqids[0:i])
}
开发者ID:hugelgupf,项目名称:ninep,代码行数:37,代码来源:ufs.go

示例10: Attach

func (u *Ufs) Attach(req *srv.Req) {
	if req.Afid != nil {
		req.RespondError(srv.Enoauth)
		return
	}

	tc := req.Tc
	fid := new(Fid)

	// You can think of the ufs.Root as a 'chroot' of a sort.
	// client attaches are not allowed to go outside the
	// directory represented by ufs.Root
	fid.path = path.Join(u.Root, tc.Aname)

	req.Fid.Aux = fid
	err := fid.stat()
	if err != nil {
		req.RespondError(err)
		return
	}

	qid := dir2Qid(fid.st)
	req.RespondRattach(qid)
}
开发者ID:hugelgupf,项目名称:ninep,代码行数:24,代码来源:ufs.go

示例11: Create

func (f *NullFS) Create(r *srv.Req) {
	r.RespondError(srv.Eperm)
}
开发者ID:hugelgupf,项目名称:ninep,代码行数:3,代码来源:nullfs.go

示例12: Clunk

func (*NullFS) Clunk(req *srv.Req) { req.RespondRclunk() }
开发者ID:hugelgupf,项目名称:ninep,代码行数:1,代码来源:nullfs.go

示例13: Write

// Write handles writes for writeable files and always succeeds.
// Only the null files has w so we don't bother checking Path.
func (f *NullFS) Write(r *srv.Req) {
	var count uint32
	ninep.SetRreadCount(r.Rc, uint32(count))
	r.Respond()
}
开发者ID:hugelgupf,项目名称:ninep,代码行数:7,代码来源:nullfs.go

示例14: Read

func (u *Ufs) Read(req *srv.Req) {
	dbg := u.Debuglevel&srv.DbgLogFcalls != 0
	fid := req.Fid.Aux.(*Fid)
	tc := req.Tc
	rc := req.Rc
	err := fid.stat()
	if err != nil {
		req.RespondError(err)
		return
	}

	ninep.InitRread(rc, tc.Count)
	var count int
	var e error
	if fid.st.IsDir() {
		if tc.Offset == 0 {
			var e error
			// If we got here, it was open. Can't really seek
			// in most cases, just close and reopen it.
			fid.file.Close()
			if fid.file, e = os.OpenFile(fid.path, omode2uflags(req.Fid.Omode), 0); e != nil {
				req.RespondError(toError(e))
				return
			}

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

			if dbg {
				log.Printf("Read: read %d entries", len(fid.dirs))
			}
			fid.dirents = nil
			fid.direntends = nil
			for i := 0; i < len(fid.dirs); i++ {
				path := fid.path + "/" + fid.dirs[i].Name()
				st, err := dir2Dir(path, fid.dirs[i], req.Conn.Dotu, req.Conn.Srv.Upool)
				if err != nil {
					if dbg {
						log.Printf("dbg: stat of %v: %v", path, err)
					}
					continue
				}
				if dbg {
					log.Printf("Stat: %v is %v", path, st)
				}
				b := ninep.PackDir(st, req.Conn.Dotu)
				fid.dirents = append(fid.dirents, b...)
				count += len(b)
				fid.direntends = append(fid.direntends, count)
				if dbg {
					log.Printf("fid.direntends is %v\n", fid.direntends)
				}
			}
		}

		switch {
		case tc.Offset > uint64(len(fid.dirents)):
			count = 0
		case len(fid.dirents[tc.Offset:]) > int(tc.Count):
			count = int(tc.Count)
		default:
			count = len(fid.dirents[tc.Offset:])
		}

		if dbg {
			log.Printf("readdir: count %v @ offset %v", count, tc.Offset)
		}
		nextend := sort.SearchInts(fid.direntends, int(tc.Offset)+count)
		if nextend < len(fid.direntends) {
			if fid.direntends[nextend] > int(tc.Offset)+count {
				if nextend > 0 {
					count = fid.direntends[nextend-1] - int(tc.Offset)
				} else {
					count = 0
				}
			}
		}
		if dbg {
			log.Printf("readdir: count adjusted %v @ offset %v", count, tc.Offset)
		}
		if count == 0 && int(tc.Offset) < len(fid.dirents) && len(fid.dirents) > 0 {
			req.RespondError(&ninep.Error{"too small read size for dir entry", ninep.EINVAL})
			return
		}
		copy(rc.Data, fid.dirents[tc.Offset:int(tc.Offset)+count])
	} else {
		count, e = fid.file.ReadAt(rc.Data, int64(tc.Offset))
		if e != nil && e != io.EOF {
			req.RespondError(toError(e))
			return
		}
	}

	ninep.SetRreadCount(rc, uint32(count))
	req.Respond()
}
开发者ID:hugelgupf,项目名称:ninep,代码行数:98,代码来源:ufs.go

示例15: Create

func (*Ufs) Create(req *srv.Req) {
	fid := req.Fid.Aux.(*Fid)
	tc := req.Tc
	err := fid.stat()
	if err != nil {
		req.RespondError(err)
		return
	}

	path := fid.path + "/" + tc.Name
	var e error = nil
	var file *os.File = nil
	switch {
	case tc.Perm&ninep.DMDIR != 0:
		e = os.Mkdir(path, os.FileMode(tc.Perm&0777))

	case tc.Perm&ninep.DMSYMLINK != 0:
		e = os.Symlink(tc.Ext, path)

	case tc.Perm&ninep.DMLINK != 0:
		n, e := strconv.ParseUint(tc.Ext, 10, 0)
		if e != nil {
			break
		}

		ofid := req.Conn.FidGet(uint32(n))
		if ofid == nil {
			req.RespondError(srv.Eunknownfid)
			return
		}

		e = os.Link(ofid.Aux.(*Fid).path, path)
		ofid.DecRef()

	case tc.Perm&ninep.DMNAMEDPIPE != 0:
	case tc.Perm&ninep.DMDEVICE != 0:
		req.RespondError(&ninep.Error{"not implemented", ninep.EIO})
		return

	default:
		var mode uint32 = tc.Perm & 0777
		if req.Conn.Dotu {
			if tc.Perm&ninep.DMSETUID > 0 {
				mode |= syscall.S_ISUID
			}
			if tc.Perm&ninep.DMSETGID > 0 {
				mode |= syscall.S_ISGID
			}
		}
		file, e = os.OpenFile(path, omode2uflags(tc.Mode)|os.O_CREATE, os.FileMode(mode))
	}

	if file == nil && e == nil {
		file, e = os.OpenFile(path, omode2uflags(tc.Mode), 0)
	}

	if e != nil {
		req.RespondError(toError(e))
		return
	}

	fid.path = path
	fid.file = file
	err = fid.stat()
	if err != nil {
		req.RespondError(err)
		return
	}

	req.RespondRcreate(dir2Qid(fid.st), 0)
}
开发者ID:hugelgupf,项目名称:ninep,代码行数:71,代码来源:ufs.go


注:本文中的github.com/lionkov/ninep/srv.Req类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。