Code Monkey home page Code Monkey logo

fuse-go's Introduction

fuse-go

License Coverage

一个纯Golang的libfuse实现,目前相当于实现了libfuse中的low level接口。

如何使用

  • fuse.Session是启动和管理整个Fuse运行周期的结构体,所以这个类的实例是必须要有的。
  • fuse.mount中是挂载目录的函数封装,主要是mountumount,具体实现其实是使用了fusermount的。
  • fuse.FuseOpt是保存用户实现的方法的结构体,然后将其传入fuse.Session中。
  • fuse.util中目前提供了两工具类:
    • FusePathManager是一个key: inode,val: filepath的字典
    • NotExistManager是用来缓存那些文件路径不存在的,可以设置一个超时时间

要实现的文件操作接口,可以查看opt_h.go,如果有些接口不需要实现,则直接不赋值(nil)即可。

示例代码

import (
    "github.com/mingforpc/fuse-go/fuse"
    "github.com/mingforpc/fuse-go/fuse/mount"
)

......

var getattr = func(req fuse.Req, nodeid uint64) (fsStat *fuse.Stat, result int32) {

	......

	return fsStat, result
}

......

func main() {
    ......
    opts := fuse.Opt{}
    opts.Getattr = &getattr
    opts.Opendir = &opendir
    opts.Readdir = &readdir
    opts.Releasedir = &release
    opts.Release = &release
    opts.Lookup = &lookup
    opts.Open = &open
    opts.Read = &read
    opts.Mkdir = &mkdir
    opts.Create = &create
    opts.Setattr = &setattr
    opts.Write = &write
    opts.Unlink = &unlink
    opts.Rmdir = &rmdir
    opts.Rename = &rename
    opts.Setxattr = &setxattr
    opts.Getxattr = &getxattr
    opts.Listxattr = &listxattr
    opts.Removexattr = &removexattr
    ......

    se := fuse.NewFuseSession(cg.Mountpoint, &opts, 1024)

    ......

    err := mount.Mount(se)

    ......

    se.FuseLoop()

    ......
}

原理

通过对/dev/fuse读写,获得内核fuse传过来的文件操作。

详细可以看看fuse/kernel/中的代码。

/dev/fuse交互的请求响应格式,可以参考我的博文FUSE协议解析

Mount部分的代码,为了实现普通用户可以直接Mount,调用了/bin/fusermount(可能需要安装libfuse后才有),Mount的代码主要复制go-fuse,然后自己做了小修改

例子

example中有一个hello的简单例子,具体使用是go build后,hello -mp {挂载的目录}

更详细的例子可以参考我下面的hadoop-fs

https://github.com/mingforpc/hadoop-fs

TODO(按优先级排序)

  • errno中的错误代码需要完善(急)(2018/12/21,已在errno中添加基本的错误代码)
  • 修改好注释和调整结构(2018/12/24)
  • 完成example中的例子(2018/12/29)
  • 发现Close()会存在block的情况,需要解决(急)(2019/1/3)
  • test中添加测试用例(2018/1/14, 大部分函数已经有测试)
  • 测试各个系统上的兼容性(目前只在64位Ubuntu上进行)
  • 完善evloop相关的操作
  • 提供一些管理inodepath的工具类
  • 实现一个高级接口

联系我

如果有什么问题直接联系我指出,万分感谢!

邮箱: [email protected]

fuse-go's People

Contributors

mingforpc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.