Exemplo n.º 1
0
func (me *P9Fs) Open(name string, flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {

	var user go9p.User
	var err error
	var c *clnt.Clnt
	var file *clnt.File
	var f []byte

	user = go9p.OsUsers.Uid2User(os.Geteuid())
	clnt.DefaultDebuglevel = 0
	c, err = clnt.Mount("tcp", address, "", user)
	if err != nil {
		goto error
	}

	file, err = c.FOpen("/tmp/anaconda-post.log", go9p.OREAD)
	if err != nil {
		goto error
	}
	defer file.Close()
	f, err = ioutil.ReadAll(file)

	if err != nil && err != io.EOF {
		goto error
	}

	return nodefs.NewDataFile(f), fuse.OK

error:
	log.Println("Error", err)
	return nil, fuse.EPERM
}
Exemplo n.º 2
0
func main() {
	var n, m int
	var user go9p.User
	var err error
	var c *clnt.Clnt
	var file *clnt.File
	var buf []byte

	flag.Parse()
	user = go9p.OsUsers.Uid2User(os.Geteuid())
	clnt.DefaultDebuglevel = *debuglevel
	c, err = clnt.Mount("tcp", *addr, "", user)
	if err != nil {
		goto error
	}

	if flag.NArg() != 1 {
		log.Println("invalid arguments")
		return
	}

	file, err = c.FOpen(flag.Arg(0), go9p.OWRITE|go9p.OTRUNC)
	if err != nil {
		file, err = c.FCreate(flag.Arg(0), 0666, go9p.OWRITE)
		if err != nil {
			goto error
		}
	}

	buf = make([]byte, 8192)
	for {
		n, err = os.Stdin.Read(buf)
		if err != nil && err != io.EOF {
			goto error
		}

		if n == 0 {
			break
		}

		m, err = file.Write(buf[0:n])
		if err != nil {
			goto error
		}

		if m != n {
			err = &go9p.Error{"short write", 0}
			goto error
		}
	}

	file.Close()
	return

error:
	log.Println("Error", err)
}
Exemplo n.º 3
0
func main() {
	var user go9p.User
	var file *clnt.File

	flag.Parse()
	user = go9p.OsUsers.Uid2User(os.Geteuid())
	clnt.DefaultDebuglevel = *debuglevel

	c, oerr := tls.Dial("tcp", *addr, &tls.Config{
		Rand:               rand.Reader,
		InsecureSkipVerify: true,
	})
	if oerr != nil {
		log.Println("can't dial", oerr)
		return
	}

	clnt, err := clnt.MountConn(c, "", user)
	if err != nil {
		goto error
	}

	if flag.NArg() != 1 {
		log.Println("invalid arguments")
		return
	}

	file, oerr = clnt.FOpen(flag.Arg(0), go9p.OREAD)
	if oerr != nil {
		goto oerror
	}

	for {
		d, oerr := file.Readdir(0)
		if oerr != nil {
			goto oerror
		}

		if d == nil || len(d) == 0 {
			break
		}

		for i := 0; i < len(d); i++ {
			os.Stdout.WriteString(d[i].Name + "\n")
		}
	}

	file.Close()
	return

error:
	log.Println(fmt.Sprintf("Error: %s", err))
	return

oerror:
	log.Println("Error", oerr)
}
Exemplo n.º 4
0
func main() {
	var n int
	var user go9p.User
	var err error
	var c *clnt.Clnt
	var file *clnt.File
	var buf []byte

	flag.Parse()
	user = go9p.OsUsers.Uid2User(os.Geteuid())
	clnt.DefaultDebuglevel = *debuglevel
	c, err = clnt.Mount("tcp", *addr, "", user)
	if err != nil {
		goto error
	}

	if flag.NArg() != 1 {
		log.Println("invalid arguments")
		return
	}

	file, err = c.FOpen(flag.Arg(0), go9p.OREAD)
	if err != nil {
		goto error
	}

	buf = make([]byte, 8192)
	for {
		n, err = file.Read(buf)
		if n == 0 {
			break
		}

		os.Stdout.Write(buf[0:n])
	}

	file.Close()

	if err != nil && err != io.EOF {
		goto error
	}

	return

error:
	log.Println("Error", err)
}
Exemplo n.º 5
0
func main() {
	var user go9p.User
	var err error
	var c *clnt.Clnt
	var file *clnt.File
	var d []*go9p.Dir

	flag.Parse()
	user = go9p.OsUsers.Uid2User(os.Geteuid())
	clnt.DefaultDebuglevel = *debuglevel
	c, err = clnt.Mount("tcp", *addr, "", user)
	if err != nil {
		log.Fatal(err)
	}

	lsarg := "/"
	if flag.NArg() == 1 {
		lsarg = flag.Arg(0)
	} else if flag.NArg() > 1 {
		log.Fatal("error: only one argument expected")
	}

	file, err = c.FOpen(lsarg, go9p.OREAD)
	if err != nil {
		log.Fatal(err)
	}

	for {
		d, err = file.Readdir(0)
		if d == nil || len(d) == 0 || err != nil {
			break
		}

		for i := 0; i < len(d); i++ {
			os.Stdout.WriteString(d[i].Name + "\n")
		}
	}

	file.Close()
	if err != nil && err != io.EOF {
		log.Fatal(err)
	}

	return
}