本文整理汇总了Golang中code/google/com/p/go9p/p/srv.File类的典型用法代码示例。如果您正苦于以下问题:Golang File类的具体用法?Golang File怎么用?Golang File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Read
func (k *Clone) Read(fid *srv.FFid, buf []byte, offset uint64) (int, error) {
var err error
// we only allow a single read from us, change the offset and we're done
if offset > uint64(0) {
return 0, nil
}
user := p.OsUsers.Uid2User(os.Geteuid())
k.clones++
name := strconv.Itoa(k.clones)
f := new(srv.File)
err = f.Add(root, name, user, nil, p.DMDIR|0777, f)
if err != nil {
return 0, &p.Error{"can not create dir", 0}
}
ctl := new(CtlFile)
ctl.datafile = make([]byte, 0)
err = ctl.Add(f, "ctl", user, nil, 0777, ctl)
if err != nil {
return 0, &p.Error{"cannot create ctl file", 0}
}
b := []byte(name)
if len(buf) < len(b) {
f.Remove()
return 0, &p.Error{"not enough buffer space for result", 0}
}
copy(buf, b)
return len(b), nil
}
示例2: mkroot
func mkroot() (*srv.File, error) {
root := new(srv.File)
err := root.Add(nil, "/", p.OsUsers.Uid2User(os.Geteuid()), p.OsUsers.Gid2Group(os.Getegid()), p.DMDIR|0555, nil)
if err != nil {
return nil, err
}
return root, nil
}
示例3: main
func main() {
var err error
var tm *Time
var ntm *InfTime
var s *srv.Fsrv
var p9c net.Conn
var ch chan bool
var usr *user.User
flag.Parse()
root := new(srv.File)
usr, err = user.Current()
if err != nil {
goto error
}
// log.Println("running as User: ", usr)
err = root.Add(nil, "/", UserNone(usr.Uid), nil, p.DMDIR|0555, nil)
if err != nil {
goto error
}
tm = new(Time)
err = tm.Add(root, "time", UserNone(usr.Uid), nil, 0444, tm)
if err != nil {
goto error
}
ntm = new(InfTime)
err = ntm.Add(root, "inftime", UserNone(usr.Uid), nil, 0444, ntm)
if err != nil {
goto error
}
s = srv.NewFileSrv(root)
s.Dotu = false
s.Upool = NoneUsers{}
if *debug {
s.Debuglevel = 1
}
if *debugall {
s.Debuglevel = 2
}
log.Println("starting tree")
s.Start(s)
p9c, err = NewSrvConn(*addr)
if err != nil {
goto error
}
log.Println("starting")
s.NewConn(p9c)
<-ch
return
error:
log.Println(fmt.Sprintf("Error: %s", err))
}
示例4: main
func main() {
var err error
var tm *Time
var ntm *InfTime
var s *srv.Fsrv
flag.Parse()
user := p.OsUsers.Uid2User(os.Geteuid())
root := new(srv.File)
err = root.Add(nil, "/", user, nil, p.DMDIR|0555, nil)
if err != nil {
goto error
}
tm = new(Time)
err = tm.Add(root, "time", p.OsUsers.Uid2User(os.Geteuid()), nil, 0444, tm)
if err != nil {
goto error
}
ntm = new(InfTime)
err = ntm.Add(root, "inftime", p.OsUsers.Uid2User(os.Geteuid()), nil, 0444, ntm)
if err != nil {
goto error
}
s = srv.NewFileSrv(root)
s.Dotu = true
if *debug {
s.Debuglevel = 1
}
if *debugall {
s.Debuglevel = 2
}
s.Start(s)
err = s.StartNetListener("tcp", *addr)
if err != nil {
goto error
}
return
error:
log.Println(fmt.Sprintf("Error: %s", err))
}
示例5: Serve9P
// Serve a previously opened serial device via 9P.
// `addr' shoud be of form "host:port", where host
// may be missing.
func Serve9P(addr string, dev Port) (err error) {
user := user.Current()
root := new(srv.File)
err = root.Add(nil, "/", user, nil, p.DMDIR|0555, nil)
if err != nil {
return
}
c := new(ctl)
c.dev = dev
err = c.Add(root, "ctl", user, nil, 0666, c)
if err != nil {
return
}
d := new(data)
d.dev = dev
d.rch = ioutil.ChannelizeReader(dev, nil)
d.unblockch = make(chan bool)
c.dataUnblockch = d.unblockch
err = d.Add(root, "data", user, nil, 0666, d)
if err != nil {
return
}
s := srv.NewFileSrv(root)
s.Dotu = true
switch {
case Debugall:
s.Debuglevel = 2
case Debug:
s.Debuglevel = 1
}
s.Start(s)
err = s.StartNetListener("tcp", addr)
return
}
示例6: Read
func (cl *Clone) Read(fid *srv.FFid, buf []byte, offset uint64) (int, error) {
var err error
var dir *srv.File
var ctl *ClientCtl
var body *ClientBody
var parsed *srv.File
var outb []byte
// we only allow a single read from us, change the offset and we're done
if offset > uint64(0) {
return 0, nil
}
id := fmt.Sprintf("%d", cl.clones)
client := new(HttpClient)
client.id = cl.clones
client.req = &http.Request{
Method: "GET",
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
Header: make(http.Header),
}
// web/0
dir = new(srv.File)
if p9err := dir.Add(root, id, user, user, p.DMDIR|0555, nil); p9err != nil {
err = fmt.Errorf("clone: can't add client dir: %s", p9err)
goto remove
}
client.dir = dir
// web/0/ctl
ctl = new(ClientCtl)
if p9err := ctl.Add(dir, "ctl", user, user, 0666, ctl); p9err != nil {
err = fmt.Errorf("clone: can't make ctl: %s", p9err)
goto remove
}
ctl.c = client
// web/0/body
body = new(ClientBody)
if p9err := body.Add(dir, "body", user, user, 0444, body); p9err != nil {
err = fmt.Errorf("clone: can't make body: %s", p9err)
goto remove
}
body.c = client
// web/0/parsed/
parsed = new(srv.File)
if p9err := parsed.Add(dir, "parsed", user, user, p.DMDIR|0555, nil); p9err != nil {
err = fmt.Errorf("clone: can't add parsed dir: %s", p9err)
goto remove
}
for ptype, fname := range parsedtab {
pfile := &ParsedFile{ptype: ptype, c: client}
if p9err := pfile.Add(parsed, fname, user, user, 0444, pfile); p9err != nil {
err = fmt.Errorf("clone: can't add parsed file %s: %s", p9err)
goto remove
}
}
outb = []byte(id + "\n")
if len(buf) < len(outb) {
err = fmt.Errorf("not enough buffer space for result")
goto remove
}
fid.F = &ctl.File
cl.clones++
copy(buf, outb)
return len(outb), nil
remove:
if dir != nil {
dir.Remove()
}
return 0, err
}