當前位置: 首頁>>代碼示例>>Golang>>正文


Golang nodefs.NewDefaultNode函數代碼示例

本文整理匯總了Golang中github.com/hanwen/go-fuse/fuse/nodefs.NewDefaultNode函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewDefaultNode函數的具體用法?Golang NewDefaultNode怎麽用?Golang NewDefaultNode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewDefaultNode函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestDefaultNodeMount

func TestDefaultNodeMount(t *testing.T) {
	dir, err := ioutil.TempDir("", "go-fuse")
	if err != nil {
		t.Fatalf("TempDir: %v", err)
	}
	defer os.RemoveAll(dir)
	root := nodefs.NewDefaultNode()
	s, conn, err := nodefs.MountRoot(dir, root, nil)
	if err != nil {
		t.Fatalf("MountRoot: %v", err)
	}
	go s.Serve()
	defer s.Unmount()

	if err := conn.Mount(root.Inode(), "sub", nodefs.NewDefaultNode(), nil); !err.Ok() {
		t.Fatalf("Mount: %v", err)
	}

	if entries, err := ioutil.ReadDir(dir); err != nil {
		t.Fatalf("ReadDir: %v", err)
	} else if len(entries) != 1 {
		t.Fatalf("got %d entries", len(entries))
	} else if entries[0].Name() != "sub" {
		t.Fatalf("got %q, want %q", entries[0].Name(), "sub")
	}
}
開發者ID:yeonsh,項目名稱:go-fuse,代碼行數:26,代碼來源:mount_test.go

示例2: TestDefaultNodeGetAttr

func TestDefaultNodeGetAttr(t *testing.T) {
	dir := testutil.TempDir()
	defer os.RemoveAll(dir)

	opts := &nodefs.Options{
		// Note: defaultNode.GetAttr() calling file.GetAttr() is only useful if
		// AttrTimeout is zero.
		// See https://github.com/JonathonReinhart/gitlab-fuse/issues/2
		Owner: fuse.CurrentOwner(),
	}

	root := nodefs.NewDefaultNode()
	s, _, err := nodefs.MountRoot(dir, root, opts)
	if err != nil {
		t.Fatalf("MountRoot: %v", err)
	}
	go s.Serve()
	if err := s.WaitMount(); err != nil {
		t.Fatal("WaitMount", err)
	}
	defer s.Unmount()

	// Attach another custom node type
	root.Inode().NewChild("foo", false, &myNode{
		Node:    nodefs.NewDefaultNode(),
		content: []byte("success"),
	})

	filepath := path.Join(dir, "foo")

	// NewDefaultNode() should provide for stat that indicates 0-byte regular file
	fi, err := os.Stat(filepath)
	if err != nil {
		t.Fatalf("Stat: %v", err)
	}
	if mode := (fi.Mode() & os.ModeType); mode != 0 {
		// Mode() & ModeType should be zero for regular files
		t.Fatalf("Unexpected mode: %#o", mode)
	}
	if size := fi.Size(); size != 0 {
		t.Fatalf("Unexpected size: %d", size)
	}

	// But when we open the file, we should get the content
	content, err := ioutil.ReadFile(filepath)
	if err != nil {
		t.Fatalf("ReadFile: %v", err)
	}
	if string(content) != "success" {
		t.Fatalf("Unexpected content: %v", content)
	}
}
開發者ID:rfjakob,項目名稱:go-fuse,代碼行數:52,代碼來源:defaultnode_test.go

示例3: Mkdir

func (b *DirNode) Mkdir(name string, mode uint32, context *fuse.Context) (newNode *nodefs.Inode, code fuse.Status) {
	d, f, e := b.Dir.Create(name, true)
	if e != nil {
		return nil, fuse.ToStatus(e)
	}
	if d != nil {
		dn := &DirNode{nodefs.NewDefaultNode(), d}
		return b.Inode().NewChild(name, true, dn), fuse.OK
	} else if f != nil {
		fn := &FileNode{nodefs.NewDefaultNode(), f}
		return b.Inode().NewChild(name, false, fn), fuse.OK
	}
	return nil, fuse.ToStatus(syscall.EIO)
}
開發者ID:maxymania,項目名稱:metaclusterfs,代碼行數:14,代碼來源:fusebits2.go

示例4: newConfigNode

func (fs *multiGitFS) newConfigNode(corresponding nodefs.Node) *configNode {
	return &configNode{
		fs:            fs,
		Node:          nodefs.NewDefaultNode(),
		corresponding: corresponding,
	}
}
開發者ID:hanwen,項目名稱:gitfs,代碼行數:7,代碼來源:multifs.go

示例5: TestDefaultXAttr

func TestDefaultXAttr(t *testing.T) {
	dir := testutil.TempDir()
	defer os.RemoveAll(dir)

	root := &xattrNode{
		Node: nodefs.NewDefaultNode(),
	}

	opts := nodefs.NewOptions()
	opts.Debug = testutil.VerboseTest()
	s, _, err := nodefs.MountRoot(dir, root, opts)
	if err != nil {
		t.Fatalf("MountRoot: %v", err)
	}
	go s.Serve()
	if err := s.WaitMount(); err != nil {
		t.Fatal("WaitMount", err)
	}

	defer s.Unmount()

	var data [1024]byte
	sz, err := syscall.Getxattr(filepath.Join(dir, "child"), "attr", data[:])
	if err != nil {
		t.Fatalf("Getxattr: %v", err)
	} else if val := string(data[:sz]); val != "value" {
		t.Fatalf("got %v, want 'value'", val)
	}
}
開發者ID:jszwedko,項目名稱:ec2-metadatafs,代碼行數:29,代碼來源:xattr_test.go

示例6: TestMountOnExisting

func TestMountOnExisting(t *testing.T) {
	ts := NewTestCase(t)
	defer ts.Cleanup()

	err := os.Mkdir(ts.mnt+"/mnt", 0777)
	if err != nil {
		t.Fatalf("Mkdir failed: %v", err)
	}
	nfs := nodefs.NewDefaultNode()
	code := ts.connector.Mount(ts.rootNode(), "mnt", nfs, nil)
	if code != fuse.EBUSY {
		t.Fatal("expect EBUSY:", code)
	}

	err = os.Remove(ts.mnt + "/mnt")
	if err != nil {
		t.Fatalf("Remove failed: %v", err)
	}
	code = ts.connector.Mount(ts.rootNode(), "mnt", nfs, nil)
	if !code.Ok() {
		t.Fatal("expect OK:", code)
	}

	code = ts.pathFs.Unmount("mnt")
	if !code.Ok() {
		t.Errorf("Unmount failed: %v", code)
	}
}
開發者ID:yeonsh,項目名稱:go-fuse,代碼行數:28,代碼來源:mount_test.go

示例7: TestLiveness

func TestLiveness(t *testing.T) {
	dir := testutil.TempDir()
	defer os.RemoveAll(dir)
	root := nodefs.NewDefaultNode()
	s, _, err := nodefs.MountRoot(dir, root, nil)
	if err != nil {
		t.Fatalf("MountRoot: %v", err)
	}
	go s.Serve()
	if err := s.WaitMount(); err != nil {
		t.Fatal("WaitMount", err)
	}
	defer s.Unmount()

	if _, err := ioutil.ReadDir(dir); err != nil {
		t.Fatalf("ReadDir: %v", err)
	}

	// We previously encountered a sitation where a finalizer would close our fd out from under us. Try to force both finalizers to run and object destruction to complete.
	runtime.GC()
	runtime.GC()

	if _, err := ioutil.ReadDir(dir); err != nil {
		t.Fatalf("ReadDir: %v", err)
	}
}
開發者ID:jszwedko,項目名稱:ec2-metadatafs,代碼行數:26,代碼來源:mount_test.go

示例8: NewDeviceFSRoot

// DeviceFs is a simple filesystem interface to an MTP device. It
// should be wrapped in a Locking(Raw)FileSystem to make sure it is
// threadsafe.  The file system assumes the device does not touch the
// storage.  Arguments are the opened mtp device and a directory for the
// backing store.
func NewDeviceFSRoot(d *mtp.Device, storages []uint32, options DeviceFsOptions) (nodefs.Node, error) {
	root := rootNode{Node: nodefs.NewDefaultNode()}
	fs := &deviceFS{
		root:    &root,
		dev:     d,
		options: &options,
	}
	root.fs = fs
	fs.storages = storages
	if err := d.GetDeviceInfo(&fs.devInfo); err != nil {
		return nil, err
	}

	if !strings.Contains(fs.devInfo.MTPExtension, "android.com") {
		fs.options.Android = false
	}

	if !options.Android {
		if err := fs.setupClassic(); err != nil {
			return nil, err
		}
	}

	fs.mungeVfat = make(map[uint32]bool)
	for _, sid := range fs.storages {
		var info mtp.StorageInfo
		if err := fs.dev.GetStorageInfo(sid, &info); err != nil {
			return nil, err
		}
		fs.mungeVfat[sid] = info.IsRemovable() && fs.options.RemovableVFat
	}

	return fs.Root(), nil
}
開發者ID:riwsakihelp,項目名稱:go-mtpfs,代碼行數:39,代碼來源:fs.go

示例9: newFolder

func (fs *P4Fs) newFolder(path string, change int) *p4Folder {
	return &p4Folder{
		Node:   nodefs.NewDefaultNode(),
		fs:     fs,
		path:   path,
		change: change,
	}
}
開發者ID:hanwen,項目名稱:p4fuse,代碼行數:8,代碼來源:fs.go

示例10: NewMemTreeFs

func NewMemTreeFs(files map[string]MemFile) *MemTreeFs {
	fs := &MemTreeFs{
		root:  &memNode{Node: nodefs.NewDefaultNode()},
		files: files,
	}
	fs.root.fs = fs
	return fs
}
開發者ID:rfjakob,項目名稱:go-fuse,代碼行數:8,代碼來源:memtree.go

示例11: newDirNode

func (t *treeFS) newDirNode(id *git.Oid) nodefs.Node {
	n := &dirNode{
		gitNode: gitNode{
			fs:   t,
			id:   id.Copy(),
			Node: nodefs.NewDefaultNode(),
		},
	}
	return n
}
開發者ID:hanwen,項目名稱:gitfs,代碼行數:10,代碼來源:fs.go

示例12: newNode

func (me *MemUnionFs) newNode(isdir bool) *memNode {
	n := &memNode{
		Node:  nodefs.NewDefaultNode(),
		fs:    me,
		mutex: &me.mutex,
	}
	now := time.Now()
	n.info.SetTimes(&now, &now, &now)
	return n
}
開發者ID:hanwen,項目名稱:termite,代碼行數:10,代碼來源:memunionfs.go

示例13: NodeFromName

func (bn *BoardNode) NodeFromName(name string) (nodefs.Node, error) {
	t := bn.LookupByTitle(name)
	if t == nil {
		log.Println("could not open thrnode", name)
		return nil, errors.New("could not open threads")
	}
	return &ThreadNode{
		Node:   nodefs.NewDefaultNode(),
		thread: t}, nil
}
開發者ID:philips,項目名稱:goboardfs,代碼行數:10,代碼來源:board.go

示例14: Create

func (n *folderNode) Create(name string, flags uint32, mode uint32, context *fuse.Context) (nodefs.File, *nodefs.Inode, fuse.Status) {
	if !n.fetch() {
		return nil, nil, fuse.EIO
	}

	obj := mtp.ObjectInfo{
		StorageID:        n.StorageID(),
		Filename:         name,
		ObjectFormat:     mtp.OFC_Undefined,
		ModificationDate: time.Now(),
		ParentObject:     n.Handle(),
		CompressedSize:   0,
	}

	var file nodefs.File
	var fsNode nodefs.Node
	if n.fs.options.Android {
		_, _, handle, err := n.fs.dev.SendObjectInfo(n.StorageID(), n.Handle(), &obj)
		if err != nil {
			log.Println("SendObjectInfo failed", err)
			return nil, nil, fuse.EIO
		}

		err = n.fs.dev.SendObject(&bytes.Buffer{}, 0)
		if err != nil {
			log.Println("SendObject failed:", err)
			return nil, nil, fuse.EIO
		}

		aNode := &androidNode{
			mtpNodeImpl: mtpNodeImpl{
				Node:   nodefs.NewDefaultNode(),
				obj:    &obj,
				fs:     n.fs,
				handle: handle,
			},
		}

		if !aNode.startEdit() {
			return nil, nil, fuse.EIO
		}
		file = &androidFile{
			File: nodefs.NewDefaultFile(),
			node: aNode,
		}
		fsNode = aNode
	} else {
		var err error
		file, fsNode, err = n.fs.createClassicFile(obj)
		if err != nil {
			return nil, nil, fuse.ToStatus(err)
		}
	}
	return file, n.Inode().NewChild(name, false, fsNode), fuse.OK
}
開發者ID:sithmakak,項目名稱:go-mtpfs,代碼行數:55,代碼來源:fs.go

示例15: newFolder

func (fs *DeviceFs) newFolder(obj mtp.ObjectInfo, h uint32) *folderNode {
	obj.AssociationType = mtp.OFC_Association
	return &folderNode{
		mtpNodeImpl: mtpNodeImpl{
			Node:   nodefs.NewDefaultNode(),
			handle: h,
			obj:    &obj,
			fs:     fs,
		},
	}
}
開發者ID:pvsousalima,項目名稱:go-mtpfs,代碼行數:11,代碼來源:fs.go


注:本文中的github.com/hanwen/go-fuse/fuse/nodefs.NewDefaultNode函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。