Пример #1
0
func TestNonseekable(t *testing.T) {
	fs := &nonseekFs{FileSystem: pathfs.NewDefaultFileSystem()}
	fs.Length = 200 * 1024

	dir, err := ioutil.TempDir("", "go-fuse-cache_test")
	if err != nil {
		t.Fatalf("failed: %v", err)
	}
	defer os.RemoveAll(dir)
	nfs := pathfs.NewPathNodeFs(fs, nil)
	state, _, err := nodefs.MountRoot(dir, nfs.Root(), nil)
	if err != nil {
		t.Fatalf("failed: %v", err)
	}
	state.SetDebug(VerboseTest())
	defer state.Unmount()

	go state.Serve()

	f, err := os.Open(dir + "/file")
	if err != nil {
		t.Fatalf("failed: %v", err)
	}
	defer f.Close()

	b := make([]byte, 200)
	n, err := f.ReadAt(b, 20)
	if err == nil || n > 0 {
		t.Errorf("file was opened nonseekable, but seek successful")
	}
}
Пример #2
0
func NewStatFS() *StatFS {
	return &StatFS{
		FileSystem: pathfs.NewDefaultFileSystem(),
		entries:    make(map[string]*fuse.Attr),
		dirs:       make(map[string][]fuse.DirEntry),
	}
}
Пример #3
0
// New initializes a new TagsFs that uses the given AWS client
func New(client *ec2.EC2, instanceID string) *TagsFs {
	return &TagsFs{
		FileSystem: pathfs.NewReadonlyFileSystem(pathfs.NewDefaultFileSystem()),
		Client:     client,
		InstanceID: instanceID,
	}
}
Пример #4
0
func main() {
	if len(os.Args) != 2 {
		fmt.Println("Usage: %s <mountpath>")
		os.Exit(1)
	}
	root := os.Args[1]

	hfs := &HelloFs{FileSystem: pathfs.NewDefaultFileSystem()}

	nfs := pathfs.NewPathNodeFs(hfs, nil)
	fuseSrv, _, err := nodefs.MountRoot(root, nfs.Root(), nil)
	if err != nil {
		log.Fatal(err)
	}
	go fuseSrv.Serve()
	l, err := net.Listen("tcp", "127.0.0.1:50000")
	if err != nil {
		log.Fatal(err)
	}
	s := grpc.NewServer()
	pb.RegisterPathFSServer(s, server.New(hfs))
	go s.Serve(l)
	log.Printf("Listen on %s for dir %s", l.Addr(), root)
	sigCh := make(chan os.Signal)
	signal.Notify(sigCh, os.Interrupt)
	for range sigCh {
		fuseSrv.Unmount()
		s.Stop()
		os.Exit(0)
	}
}
Пример #5
0
func defaultReadTest(t *testing.T) (root string, cleanup func()) {
	fs := &DefaultReadFS{
		FileSystem: pathfs.NewDefaultFileSystem(),
		size:       22,
	}

	var err error
	dir, err := ioutil.TempDir("", "go-fuse")
	if err != nil {
		t.Fatalf("TempDir failed: %v", err)
	}
	pathfs := pathfs.NewPathNodeFs(fs, nil)
	opts := nodefs.NewOptions()
	opts.Debug = VerboseTest()

	state, _, err := nodefs.MountRoot(dir, pathfs.Root(), opts)
	if err != nil {
		t.Fatalf("MountNodeFileSystem failed: %v", err)
	}
	go state.Serve()
	if err := state.WaitMount(); err != nil {
		t.Fatal("WaitMount", err)
	}
	return dir, func() {
		state.Unmount()
		os.Remove(dir)
	}
}
Пример #6
0
func newNotifyFs() *NotifyFs {
	return &NotifyFs{
		FileSystem: pathfs.NewDefaultFileSystem(),
		sizeChan:   make(chan uint64, 1),
		existChan:  make(chan bool, 1),
	}
}
Пример #7
0
func NewUnionFs(fileSystems []pathfs.FileSystem, options UnionFsOptions) (pathfs.FileSystem, error) {
	g := &unionFS{
		options:     &options,
		fileSystems: fileSystems,
		FileSystem:  pathfs.NewDefaultFileSystem(),
	}

	writable := g.fileSystems[0]
	code := g.createDeletionStore()
	if !code.Ok() {
		return nil, fmt.Errorf("could not create deletion path %v: %v", options.DeletionDirName, code)
	}

	g.deletionCache = newDirCache(writable, options.DeletionDirName, options.DeletionCacheTTL)
	g.branchCache = NewTimedCache(
		func(n string) (interface{}, bool) { return g.getBranchAttrNoCache(n), true },
		options.BranchCacheTTL)

	g.hiddenFiles = make(map[string]bool)
	for _, name := range options.HiddenFiles {
		g.hiddenFiles[name] = true
	}

	return g, nil
}
Пример #8
0
func New(config *conf.Fuse, logger log_driver.Logger) (*GitFs, error) {
	gitfsDir, err := gitfsDir(logger)
	if err != nil {
		return nil, err
	}

	defaultfs := pathfs.NewDefaultFileSystem()
	gitfs := &GitFs{FileSystem: pathfs.NewReadonlyFileSystem(defaultfs), GitRepoDir: config.GitRepoDir, GitFsDir: gitfsDir, logger: logger}
	fs := pathfs.NewPathNodeFs(gitfs, nil)
	server, _, err := nodefs.MountRoot(gitfsDir, fs.Root(), nil)
	if err != nil {
		logger.Errorf("Failed to mount GitFS on %s due to %s", gitfsDir, err)
		return nil, err
	}
	logger.Debugf("Mount GitFs on %s", gitfsDir)
	gitfs.server = server
	server.SetDebug(config.Debug)

	gitfs.cache, err = cache.New(1024)
	if err != nil {
		logger.Errorf("Failed to initialize object cache due to %s\n", err)
		return nil, err
	}

	return gitfs, nil
}
Пример #9
0
// New initializes a new MetadataFs that uses the given endpoint as the
// target of metadata requests
func New(endpoint string) *MetadataFs {
	return &MetadataFs{
		FileSystem: pathfs.NewReadonlyFileSystem(pathfs.NewDefaultFileSystem()),
		Client:     &http.Client{},
		Endpoint:   endpoint,
	}
}
Пример #10
0
func start(dataset string, mount mount) {
	ds, err := spec.GetDataset(dataset)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not create dataset: %s\n", err)
		return
	}

	hv, ok := ds.MaybeHeadValue()
	if ok {
		if !types.IsSubtype(fsType, hv.Type()) {
			fmt.Fprintf(os.Stderr, "Invalid dataset head: expected type '%s' but found type '%s'\n", fsType.Desc.(types.StructDesc).Name, hv.Type().Desc.(types.StructDesc).Name)
			return
		}
	} else {
		rootAttr := makeAttr(0777) // create the root directory with maximally permissive permissions
		rootDir := types.NewStructWithType(directoryType, types.ValueSlice{types.NewMap()})
		rootInode := types.NewStructWithType(inodeType, types.ValueSlice{rootAttr, rootDir})
		hv = types.NewStructWithType(fsType, types.ValueSlice{rootInode})
	}

	mount(&nomsFS{
		FileSystem: pathfs.NewDefaultFileSystem(),
		ds:         ds,
		head:       hv.(types.Struct),
		mdLock:     &sync.Mutex{},
		nodes:      make(map[hash.Hash]*nNode),
	})
}
Пример #11
0
func TestNonseekable(t *testing.T) {
	fs := &nonseekFs{FileSystem: pathfs.NewDefaultFileSystem()}
	fs.Length = 200 * 1024

	dir := testutil.TempDir()
	defer os.RemoveAll(dir)
	nfs := pathfs.NewPathNodeFs(fs, nil)
	opts := nodefs.NewOptions()
	opts.Debug = testutil.VerboseTest()
	state, _, err := nodefs.MountRoot(dir, nfs.Root(), opts)
	if err != nil {
		t.Fatalf("failed: %v", err)
	}
	defer state.Unmount()

	go state.Serve()
	if err := state.WaitMount(); err != nil {
		t.Fatal("WaitMount", err)
	}

	f, err := os.Open(dir + "/file")
	if err != nil {
		t.Fatalf("failed: %v", err)
	}
	defer f.Close()

	b := make([]byte, 200)
	n, err := f.ReadAt(b, 20)
	if err == nil || n > 0 {
		t.Errorf("file was opened nonseekable, but seek successful")
	}
}
Пример #12
0
func NewMultiZipFs() *MultiZipFs {
	m := &MultiZipFs{
		zips:          make(map[string]nodefs.Node),
		dirZipFileMap: make(map[string]string),
		FileSystem:    pathfs.NewDefaultFileSystem(),
	}
	return m
}
Пример #13
0
func NewDriver(basepath, etcdendpoint string) dkvolume.Driver {
	e := etcDriver{
		etcdbackend: etcdfs.EtcdFs{FileSystem: pathfs.NewDefaultFileSystem(), EtcdEndpoint: etcdendpoint},
		mountpoints: make(map[string]*etcdFuseServer),
		basePath:    basepath,
	}
	return &e
}
Пример #14
0
// NewKeywhizFs readies a KeywhizFs struct and its parent filesystem objects.
func NewFs(client *api.Client, owner keywhizfs.Ownership) (*fs, nodefs.Node) {
	defaultfs := pathfs.NewDefaultFileSystem()            // Returns ENOSYS by default
	readonlyfs := pathfs.NewReadonlyFileSystem(defaultfs) // R/W calls return EPERM

	kwfs := &fs{readonlyfs, client, owner}
	nfs := pathfs.NewPathNodeFs(kwfs, nil)
	nfs.SetDebug(true)
	return kwfs, nfs.Root()
}
Пример #15
0
func MountFs(path string) {
	LoadSession()
	CacheInit()
	nfs := pathfs.NewPathNodeFs(&DropboxFs{FileSystem: pathfs.NewDefaultFileSystem()}, nil)
	server, _, err := nodefs.MountRoot(path, nfs.Root(), nil)
	if err != nil {
		log.Fatalf("Mount fail: %v\n", err)
	}
	server.Serve()
}
Пример #16
0
//
//func (me *HelloFs) OpenDir(name string, context *fuse.Context) (c []fuse.DirEntry, code fuse.Status) {
//	if name == "" {
//		c = []fuse.DirEntry{{Name: "file.txt", Mode: fuse.S_IFREG}}
//		return c, fuse.OK
//	}
//	return nil, fuse.ENOENT
//}
//
//func (me *HelloFs) Open(name string, flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) {
//	if name != "file.txt" {
//		return nil, fuse.ENOENT
//	}
//	if flags&fuse.O_ANYWRITE != 0 {
//		return nil, fuse.EPERM
//	}
//	return nodefs.NewDataFile([]byte(name)), fuse.OK
//}
//
func main() {
	use_hammer2 := false
	flag.Parse()
	if len(flag.Args()) < 1 {
		log.Fatal("Usage:\n  hello MOUNTPOINT")
	}
	var nfs *pathfs.PathNodeFs
	if use_hammer2 {
		nfs = pathfs.NewPathNodeFs(&Hammer2Fs{FileSystem: pathfs.NewDefaultFileSystem()}, nil)
	} else {
		nfs = pathfs.NewPathNodeFs(&HammerFs{FileSystem: pathfs.NewDefaultFileSystem()}, nil)
	}
	fmt.Println("nfs ==", nfs)
	//	server, _, err := nodefs.MountFileSystem(flag.Arg(0), nfs, nil)
	//	if err != nil {
	//		log.Fatal("Mount fail: %v\n", err)
	//	}
	//	server.Serve()
}
Пример #17
0
func TestHelloWorld(t *testing.T) {
	tmpSrv, err := ioutil.TempDir("", "fuse-server-")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(tmpSrv)
	hfs := &HelloFs{FileSystem: pathfs.NewDefaultFileSystem()}
	hsrv, err := startServer(tmpSrv, hfs)
	if err != nil {
		t.Fatal(err)
	}
	defer hsrv.Close()
	tmpCli, err := ioutil.TempDir("", "fuse-client-")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(tmpCli)
	cliFs, err := startFs(tmpCli, hsrv.addr.String())
	if err != nil {
		t.Fatal(err)
	}
	defer cliFs.Close()
	fis, err := ioutil.ReadDir(tmpCli)
	if err != nil {
		t.Fatal(err)
	}
	if len(fis) != 1 {
		t.Fatalf("expected to find one file, got %d", len(fis))
	}
	fi := fis[0]
	if fi.IsDir() {
		t.Fatal("should be a file, got dir")
	}
	if fi.Name() != "file.txt" {
		t.Fatalf("file should be \"file.txt\", got %s", fi.Name())
	}
	f, err := os.Open(filepath.Join(tmpCli, fi.Name()))
	if err != nil {
		t.Fatal(err)
	}
	defer f.Close()
	data, err := ioutil.ReadAll(f)
	if err != nil {
		t.Fatal(err)
	}
	if string(data) != "file.txt" {
		t.Fatalf("file content expected to be \"file.txt\", got %s", data)
	}
	if f, err := os.Open("whatever"); !os.IsNotExist(err) {
		if err == nil {
			f.Close()
		}
		t.Fatalf("error from open should be not exist, got %v", err)
	}
}
Пример #18
0
func NewObjectFileSystem(c *config.Config, mapper *mapper.ObjectMapper) *objectFileSystem {
	fs := &objectFileSystem{
		containerName:   c.ContainerName,
		createContainer: c.CreateContainer,
		mapper:          mapper,
		lock:            sync.Mutex{},

		FileSystem: pathfs.NewDefaultFileSystem(),
	}
	return fs
}
Пример #19
0
// NewKeywhizFs readies a KeywhizFs struct and its parent filesystem objects.
func NewKeywhizFs(client *Client, ownership Ownership, timeouts Timeouts, logConfig log.Config) (kwfs *KeywhizFs, root nodefs.Node, err error) {
	logger := log.New("kwfs", logConfig)
	cache := NewCache(client, timeouts, logConfig)

	defaultfs := pathfs.NewDefaultFileSystem()            // Returns ENOSYS by default
	readonlyfs := pathfs.NewReadonlyFileSystem(defaultfs) // R/W calls return EPERM

	kwfs = &KeywhizFs{readonlyfs, logger, client, cache, time.Now(), ownership}
	nfs := pathfs.NewPathNodeFs(kwfs, nil)
	nfs.SetDebug(logConfig.Debug)
	return kwfs, nfs.Root(), nil
}
Пример #20
0
func main() {
	flag.Parse()
	if len(flag.Args()) < 1 {
		log.Fatal("Usage:\n  hello MOUNTPOINT")
	}
	nfs := pathfs.NewPathNodeFs(&HelloFs{FileSystem: pathfs.NewDefaultFileSystem()}, nil)
	server, _, err := nodefs.MountRoot(flag.Arg(0), nfs.Root(), nil)
	if err != nil {
		log.Fatalf("Mount fail: %v\n", err)
	}
	server.Serve()
}
Пример #21
0
func main() {
	flag.Parse()
	if len(flag.Args()) < 2 {
		log.Fatal("Usage:\n  etcd-fs MOUNTPOINT ETCDENDPOINT")
	}
	etcdFs := EtcdFs{FileSystem: pathfs.NewDefaultFileSystem(), EtcdEndpoint: flag.Arg(1)}
	nfs := pathfs.NewPathNodeFs(&etcdFs, nil)
	server, _, err := nodefs.MountRoot(flag.Arg(0), nfs.Root(), nil)
	if err != nil {
		log.Fatalf("Mount fail: %v\n", err)
	}
	server.Serve()
}
Пример #22
0
func main() {
	if len(os.Args) < 3 {
		log.Fatal("More Args Pls. path username")
	}

	gf := &GistFs{FileSystem: pathfs.NewDefaultFileSystem(), user: os.Args[2]}

	nfs := pathfs.NewPathNodeFs(gf, nil)
	server, _, err := nodefs.MountRoot(os.Args[1], nfs.Root(), nil)
	if err != nil {
		log.Fatal(err)
	}
	server.Serve()
}
Пример #23
0
Файл: main.go Проект: c-fs/cfuse
func main() {
	flag.Parse()
	if len(flag.Args()) < 1 {
		log.Fatal("Usage:\n  ./main MOUNTPOINT")
	}
	cli, err := client.New(1, "localhost:15524")
	if err != nil {
		log.Fatalf("cannot connect to cfs server %v\n", err)
	}
	log.Println("Connected to server")
	nfs := pathfs.NewPathNodeFs(&CFuse{FileSystem: pathfs.NewDefaultFileSystem(),
		client: cli}, nil)
	server, _, err := nodefs.MountRoot(flag.Arg(0), nfs.Root(), nil)
	if err != nil {
		log.Fatalf("Mount fail: %v\n", err)
	}
	server.Serve()
}
Пример #24
0
func NewAutoUnionFs(directory string, options AutoUnionFsOptions) pathfs.FileSystem {
	if options.HideReadonly {
		options.HiddenFiles = append(options.HiddenFiles, _READONLY)
	}
	a := &autoUnionFs{
		knownFileSystems: make(map[string]knownFs),
		nameRootMap:      make(map[string]string),
		options:          &options,
		FileSystem:       pathfs.NewDefaultFileSystem(),
	}

	directory, err := filepath.Abs(directory)
	if err != nil {
		panic("filepath.Abs returned err")
	}
	a.root = directory
	return a
}
Пример #25
0
// NewFS returns an encrypted FUSE overlay filesystem.
// In this case (reverse mode) the backing directory is plain-text and
// ReverseFS provides an encrypted view.
func NewFS(args fusefrontend.Args) *ReverseFS {
	if args.CryptoBackend != cryptocore.BackendAESSIV {
		log.Panic("reverse mode must use AES-SIV, everything else is insecure")
	}
	initLongnameCache()
	cryptoCore := cryptocore.New(args.Masterkey, args.CryptoBackend, contentenc.DefaultIVBits)
	contentEnc := contentenc.New(cryptoCore, contentenc.DefaultBS)
	nameTransform := nametransform.New(cryptoCore, args.LongNames, args.Raw64)

	return &ReverseFS{
		// pathfs.defaultFileSystem returns ENOSYS for all operations
		FileSystem:    pathfs.NewDefaultFileSystem(),
		loopbackfs:    pathfs.NewLoopbackFileSystem(args.Cipherdir),
		args:          args,
		nameTransform: nameTransform,
		contentEnc:    contentEnc,
		inoGen:        newInoGen(),
		inoMap:        map[fusefrontend.DevInoStruct]uint64{},
	}
}
Пример #26
0
func main() {
	kingpin.Parse()

	// Create a client
	b, err := elastic.NewClient()
	Check(err)

	// Found the filesystem.
	nfs := pathfs.NewPathNodeFs(&ElasticFs{
		Index:      *cliIndex,
		Backend:    b,
		FileSystem: pathfs.NewDefaultFileSystem(),
	}, nil)
	s, _, err := nodefs.MountRoot(*cliDir, nfs.Root(), nil)
	if err != nil {
		log.Fatalf("Mount fail: %v\n", err)
	}

	s.Serve()
}
Пример #27
0
func TestDataReadLarge(t *testing.T) {
	fs := &FSetAttrFs{
		FileSystem: pathfs.NewDefaultFileSystem(),
	}
	dir, clean := setupFAttrTest(t, fs)
	defer clean()

	content := randomData(385 * 1023)
	fn := dir + "/file"
	err := ioutil.WriteFile(fn, []byte(content), 0644)
	if err != nil {
		t.Fatalf("WriteFile failed: %v", err)
	}

	back, err := ioutil.ReadFile(fn)
	if err != nil {
		t.Fatalf("ReadFile failed: %v", err)
	}
	CompareSlices(t, back, content)
}
Пример #28
0
func NewRpcFs(attrClient *attr.Client, cache *cba.Store, contentConn io.ReadWriteCloser) *RpcFs {
	fs := &RpcFs{
		FileSystem:    pathfs.NewDefaultFileSystem(),
		attrClient:    attrClient,
		contentClient: cache.NewClient(contentConn),
		timings:       stats.NewTimerStats(),
	}

	fs.attr = attr.NewAttributeCache(
		func(n string) *attr.FileAttr {
			a := attr.FileAttr{}
			err := attrClient.GetAttr(n, &a)
			if err != nil {
				log.Printf("GetAttr %s: %v", n, err)
				return nil
			}
			return &a
		}, nil)
	fs.cache = cache
	return fs
}
Пример #29
0
func main() {
	usage := `9pmount

Usage:
  9pmount <mount_point> (--address <address>)

Options:
  -h --help                    Show this screen.
  --version                    Show version.
  --address                    Address of 9pserver`

	args, err := docopt.Parse(usage, nil, true, "9pmount 0.1", false)
	mount_point := args["<mount_point>"].(string)
	address = args["<address>"].(string)
	nfs := pathfs.NewPathNodeFs(&P9Fs{FileSystem: pathfs.NewDefaultFileSystem()}, nil)
	server, _, err := nodefs.MountRoot(mount_point, nfs.Root(), nil)
	if err != nil {
		log.Fatalf("Mount fail: %v\n", err)
	}
	server.Serve()
}
Пример #30
0
func (p *MountFUSEFS) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	_, err := os.Stat(fusemount)
	if err == nil {
		w.WriteHeader(http.StatusOK)
		w.Write([]byte("already mounted"))
		return
	}
	err = os.Mkdir(fusemount, 0755)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte("mkdir fail: " + err.Error()))
	}

	nfs := pathfs.NewPathNodeFs(&HelloFs{FileSystem: pathfs.NewDefaultFileSystem()}, nil)
	server, _, err := nodefs.MountRoot(fusemount, nfs.Root(), nil)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte("mount fail: " + err.Error()))
	}
	go server.Serve()
}