Esempio n. 1
0
// It's recommended not to have a helper. But this is so much boiler plate.
func setup(msize uint32, failf func(...interface{})) (*clnt.Clnt, *clnt.Fid) {
	f := new(NullFS)
	f.Dotu = false
	f.Id = "ufs"
	f.Debuglevel = 0
	if !f.Start(f) {
		failf("Can't happen: Starting the server failed")
	}

	l, err := net.Listen("unix", "")
	if err != nil {
		failf("net.Listen: want nil, got %v", err)
	}

	go func() {
		if err = f.StartListener(l); err != nil {
			failf("Can not start listener: %v", err)
		}
	}()

	user := ninep.OsUsers.Uid2User(os.Geteuid())

	clnt, err := clnt.Mount("unix", l.Addr().String(), "/", 8192, user)

	if err != nil {
		failf("Attach: %v", err)
	}

	rootfid := clnt.Root
	return clnt, rootfid
}
Esempio n. 2
0
func main() {
	var n, m int
	var user ninep.User
	var err error
	var c *clnt.Clnt
	var file *clnt.File
	var buf []byte

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

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

	file, err = c.FOpen(flag.Arg(0), ninep.OWRITE|ninep.OTRUNC)
	if err != nil {
		file, err = c.FCreate(flag.Arg(0), 0666, ninep.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 = &ninep.Error{"short write", 0}
			goto error
		}
	}

	file.Close()
	return

error:
	log.Println("Error", err)
}
Esempio n. 3
0
func main() {
	var n int
	var user ninep.User
	var err error
	var c *clnt.Clnt
	var file *clnt.File
	var buf []byte

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

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

	file, err = c.FOpen(flag.Arg(0), ninep.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)
}
Esempio n. 4
0
func main() {
	var user ninep.User
	var err error
	var c *clnt.Clnt
	var file *clnt.File

	flag.Parse()

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

	naddr := *addr
	if strings.LastIndex(naddr, ":") == -1 {
		naddr = naddr + ":5640"
	}
	c, err = clnt.Mount("tcp", naddr, "", uint32(*msize), user)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error mounting %s: %s\n", naddr, err)
		os.Exit(1)
	}

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

	walkone(c, "/", false)

	if file != nil {
		//process(c)
		fmt.Fprint(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
}
Esempio n. 5
0
func main() {
	var user ninep.User
	var err error
	var c *clnt.Clnt
	var file *clnt.File
	var d []*ninep.Dir

	flag.Parse()
	user = ninep.OsUsers.Uid2User(os.Geteuid())
	clnt.DefaultDebuglevel = *debuglevel
	c, err = clnt.Mount("tcp", *addr, "", uint32(*msize), 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, ninep.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
}
Esempio n. 6
0
func main() {
	var user ninep.User
	var ba [][]byte
	var nreqs int
	var rchan chan *clnt.Req
	var tag *clnt.Tag
	var fid *clnt.Fid
	var wnames []string

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

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

	ba = make([][]byte, 100)
	for i := 0; i < len(ba); i++ {
		ba[i] = make([]byte, 8192)
	}

	nreqs = 0
	rchan = make(chan *clnt.Req)
	tag = c.TagAlloc(rchan)

	// walk the file
	wnames = strings.Split(flag.Arg(0), "/")
	for wnames[0] == "" {
		wnames = wnames[1:]
	}

	fid = c.FidAlloc()
	for root := c.Root; len(wnames) > 0; root = fid {
		n := len(wnames)
		if n > 8 {
			n = 8
		}

		err = tag.Walk(root, fid, wnames[0:n])
		if err != nil {
			goto error
		}

		nreqs++
		wnames = wnames[n:]
	}
	err = tag.Open(fid, ninep.OREAD)
	if err != nil {
		goto error
	}

	for i := 0; i < len(ba); i++ {
		err = tag.Read(fid, uint64(i*8192), 8192)
		if err != nil {
			goto error
		}
		nreqs++
	}

	err = tag.Clunk(fid)

	// now start reading...
	for nreqs > 0 {
		r := <-rchan
		if r.Tc.Type == ninep.Tread {
			i := r.Tc.Offset / 8192
			copy(ba[i], r.Rc.Data)
			ba[i] = ba[i][0:r.Rc.Count]
		}
		nreqs--
	}

	for i := 0; i < len(ba); i++ {
		os.Stdout.Write(ba[i])
	}

	return

error:
	log.Println("error: ", err)
}