Beispiel #1
0
func main() {
	var user g9p.User
	var file *g9pc.File

	flag.Parse()

	if *ouser == "" {
		user = g9p.OsUsers.Uid2User(os.Geteuid())
	} else {
		user = g9p.OsUsers.Uname2User(*ouser)
	}

	naddr := *addr
	if strings.LastIndex(naddr, ":") == -1 {
		naddr = naddr + ":5640"
	}

	var plog g9p.Logger
	if *serveHTTP != "" {
		plog = g9plog.NewClient(naddr, -1, 0)
		go func() {
			if err := http.ListenAndServe(*serveHTTP, nil); err != nil {
				log.Exitln("http listen: ", err)
			}
		}()
	}

	c, err := g9pc.Mount("tcp", naddr, "", user, plog)
	if err != nil {
		log.Exitln("error mounting %s: %s", naddr, err)
	}

	//	if *debug {
	//		c.Debuglevel = 1
	//	}
	//	if *debugall {
	//		c.Debuglevel = 2
	//	}

	walkone(c, "/")

	if file != nil {
		//process(c)
		fmt.Sprint(os.Stderr, "file reading unimplemented\n")
	} else if flag.NArg() > 0 {
		flags := flag.Args()
		for _, uc := range flags {
			cmd(c, uc)
		}
	} else {
		interactive(c)
	}

	return
}
Beispiel #2
0
func main() {
	var m int
	var user g9p.User
	var file *g9pc.File

	flag.Parse()
	user = g9p.OsUsers.Uid2User(os.Geteuid())
	c, err := g9pc.Mount("tcp", *addr, "", user, nil)
	if err != nil {
		goto error
	}

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

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

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

		if n == 0 {
			break
		}

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

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

	file.Close()
	return

error:
	log.Stderr(fmt.Sprintf("Error: %v", err))
}
Beispiel #3
0
func main() {
	var user g9p.User
	var err error
	var c *g9pc.Client
	var file *g9pc.File
	var d []*g9p.Dir

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

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

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

	for {
		d, err = file.Readdir(0)
		if err != nil {
			goto error
		}

		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: %v", err))
}
Beispiel #4
0
func main() {
	var n int
	var user g9p.User
	var file *g9pc.File

	flag.Parse()
	user = g9p.OsUsers.Uid2User(os.Geteuid())
	c, err := g9pc.Mount("tcp", *addr, "", user, nil)
	if err != nil {
		goto error
	}

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

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

	buf := make([]byte, 8192)
	for {
		n, err = file.Read(buf)
		if err != nil {
			goto error
		}

		if n == 0 {
			break
		}

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

	file.Close()
	return

error:
	log.Stderr(fmt.Sprintf("Error: %v", err))
}