• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang nodefs.NewDefaultNode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/hanwen/go-fuse/fuse/nodefs.NewDefaultNode函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDefaultNode函数的具体用法?Golang NewDefaultNode怎么用?Golang NewDefaultNode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewDefaultNode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: NewP4FSRoot

// Creates a new P4FS
func NewP4FSRoot(conn *p4.Conn, backingDir string) nodefs.Node {
	fs := &P4Fs{
		p4: conn,
	}

	fs.backingDir = backingDir
	fs.root = &p4Root{
		Node: nodefs.NewDefaultNode(),
		fs:   fs,
	}
	return fs.root
}
开发者ID:hanwen,项目名称:p4fuse,代码行数:13,代码来源:fs.go


示例17: Lookup

func (b *DirNode) Lookup(out *fuse.Attr, name string, context *fuse.Context) (*nodefs.Inode, fuse.Status) {
	{
		c := b.Inode().GetChild(name)
		if c != nil {
			return c, fuse.OK
		}
	}
	d, f, e := b.Dir.Lookup(name)
	if e != nil {
		return nil, fuse.ToStatus(e)
	}
	if d != nil {
		dn := &DirNode{nodefs.NewDefaultNode(), d}
		dn.GetAttr(out, nil, context)
		return b.Inode().NewChild(name, true, dn), fuse.OK
	} else if f != nil {
		fn := &FileNode{nodefs.NewDefaultNode(), f}
		fn.GetAttr(out, nil, context)
		return b.Inode().NewChild(name, false, fn), fuse.OK
	}
	return nil, fuse.ToStatus(syscall.EIO)
}
开发者ID:maxymania,项目名称:metaclusterfs,代码行数:22,代码来源:fusebits2.go


示例18: newDirNode

func newDirNode(o *fuse.Owner, t *time.Time, nm NodeMaker) (dn *DirNode) {
	if nm == nil {
		return nil
	}
	if o == nil {
		o = getDefaultOwner()
	}
	if t == nil {
		now := time.Now()
		t = &now
	}
	return &DirNode{
		Node:      nodefs.NewDefaultNode(),
		NodeMaker: nm,
		time:      *t,
		owner:     *o}
}
开发者ID:philips,项目名称:goboardfs,代码行数:17,代码来源:dirnode.go


示例19: newLinkNode

func (t *treeFS) newLinkNode(id *git.Oid) (nodefs.Node, error) {
	n := &linkNode{
		gitNode: gitNode{
			fs:   t,
			id:   id.Copy(),
			Node: nodefs.NewDefaultNode(),
		},
	}

	blob, err := t.repo.LookupBlob(id)
	if err != nil {
		return nil, err
	}
	defer blob.Free()
	n.target = append([]byte{}, blob.Contents()...)
	return n, nil
}
开发者ID:hanwen,项目名称:gitfs,代码行数:17,代码来源:fs.go


示例20: Create

func (b *DirNode) Create(name string, flags uint32, mode uint32, context *fuse.Context) (file nodefs.File, child *nodefs.Inode, code fuse.Status) {
	d, f, e := b.Dir.Lookup(name)
	if e != nil {
		d, f, e = b.Dir.Create(name, false)
	}
	if e != nil {
		return nil, nil, fuse.ToStatus(e)
	}
	if d != nil {
		d.Dispose()
	} else if f != nil {
		fn := &FileNode{nodefs.NewDefaultNode(), f}
		fobj, _ := fn.Open(flags, context)
		return fobj, b.Inode().NewChild(name, false, fn), fuse.OK
	}
	return nil, nil, fuse.ToStatus(syscall.EIO)
	panic("")
}
开发者ID:maxymania,项目名称:metaclusterfs,代码行数:18,代码来源:fusebits2.go



注:本文中的github.com/hanwen/go-fuse/fuse/nodefs.NewDefaultNode函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang nodefs.NewFileSystemConnector函数代码示例发布时间:2022-05-23
下一篇:
Golang nodefs.NewDefaultFile函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap