Giter VIP home page Giter VIP logo

tmds.fuse's Introduction

Tmds.Fuse

Write a Linux file system in .NET.

Supported platforms

Tmds.Fuse supports Linux x64 platforms with libfuse 3.1+.

Getting Started

To use a daily build, add the myget NuGet feed to NuGet.Config.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="tmds" value="https://www.myget.org/F/tmds/api/v3/index.json" />
  </packageSources>
</configuration>

Add a package reference to your project.

dotnet add package Tmds.Fuse --version '0.1.0-*'

Implement a simple file system:

using System;
using System.Text;
using Tmds.Fuse;
using static Tmds.Linux.LibC;

class HelloFileSystem : FuseFileSystemBase
{
    private static readonly byte[] _helloFilePath = Encoding.UTF8.GetBytes("/hello");
    private static readonly byte[] _helloFileContent = Encoding.UTF8.GetBytes("hello world!");

    public override int GetAttr(ReadOnlySpan<byte> path, ref stat stat, FuseFileInfoRef fiRef)
    {
        if (path.SequenceEqual(FuseConstants.RootPath))
        {
            stat.st_mode = S_IFDIR | 0b111_101_101; // rwxr-xr-x
            stat.st_nlink = 2; // 2 + nr of subdirectories
            return 0;
        }
        else if (path.SequenceEqual(_helloFilePath))
        {
            stat.st_mode = S_IFREG | 0b100_100_100; // r--r--r--
            stat.st_nlink = 1;
            stat.st_size = _helloFileContent.Length;
            return 0;
        }
        else
        {
            return -ENOENT;
        }
    }

    public override int Open(ReadOnlySpan<byte> path, ref FuseFileInfo fi)
    {
        if (!path.SequenceEqual(_helloFilePath))
        {
            return -ENOENT;
        }

        if ((fi.flags & O_ACCMODE) != O_RDONLY)
        {
            return -EACCES;
        }

        return 0;
    }

    public override int Read(ReadOnlySpan<byte> path, ulong offset, Span<byte> buffer, ref FuseFileInfo fi)
    {
        if (offset > (ulong)_helloFileContent.Length)
        {
            return 0;
        }
        int intOffset = (int)offset;
        int length = (int)Math.Min(_helloFileContent.Length - intOffset, buffer.Length);
        _helloFileContent.AsSpan().Slice(intOffset, length).CopyTo(buffer);
        return length;
    }

    public override int ReadDir(ReadOnlySpan<byte> path, ulong offset, ReadDirFlags flags, DirectoryContent content, ref FuseFileInfo fi)
    {
        if (!path.SequenceEqual(FuseConstants.RootPath))
        {
            return -ENOENT;
        }
        content.AddEntry(".");
        content.AddEntry("..");
        content.AddEntry("hello");
        return 0;
    }
}

Implement the Main method:

static async Task Main(string[] args)
{
    if (!Fuse.CheckDependencies())
    {
        Console.WriteLine(Fuse.InstallationInstructions);
        return;
    }
    using (var mount = Fuse.Mount("/tmp/mountpoint", new HelloFileSystem()))
    {
        await mount.WaitForUnmountAsync();
    }
}

Create the mountpoint directory:

$ mkdir /tmp/mountpoint

Run the program:

$ dotnet run

tmds.fuse's People

Contributors

seertenedos avatar tmds avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

tmds.fuse's Issues

performance issues

@tmds any hints on how to improve performance? Or perhaps where to look where the bottleneck is? Can only create about 25 files/second.

Running:

dotnet 7
Debian Linux 5.10.0-26-arm64

I have Tmds.fuse calling a custom service that does all the heavy lifting with creating/maintain the inodes. Using my custom service and calling all the same methods in a test program (without using FUSE), I can create 1,000 files/sec. So, it seems that something in Tmds.Fuse is the bottle neck.

Thanks
Jason

nuget.org and status

I have been looking at your library and it looks interesting and i believe it should give some real performance boosts over the other existing libraries out there. Is there a reason it is not on nuget.org and only on your myget? Is it not complete? Any chance you could add a little info to the main readme on its status etc.

Unable to run sample on Ubuntu 20.04

Trying to run sample on Ubuntu 20.04, it fails with "libfuse3 installation required" message. libfuse3 is installed.
In debug i see that dlopen("libfuse3.so.3") returns null pointer, dlerror() returns "/snap/core18/current/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /lib/x86_64-linux-gnu/libfuse3.so.3)".
Do you have any thoughts how to fix this issue?

Issue with FSync

For the FSync call i am doing some basic logging and am just trying to test MMap on the drive from dotnet core.

protected override int FSync(string path, ref FuseFileInfo fi)
{
      Log.Trace($"Entered FSync path:{path}, fi) FileHandle:{fi.fh}");
this 

the above code fails with null reference exception on the fi.fh but it is a struct and can't be null. Exception details below
Exception thrown: 'System.NullReferenceException' in Tmds.Fuse.dll
An exception of type 'System.NullReferenceException' occurred in Tmds.Fuse.dll but was not handled in user code: 'Object reference not set to an instance of an object.'
Stack trace:

at Tmds.Fuse.FuseFileInfo.get_fh()
at MultiDrive.DriveFactories.Fuse3Drive.FuseWrapping.FuseFileSystemStringLogging.FSync(String path, FuseFileInfo& fi) in O:\git\StorjDrive\StorjDrive\Fuse3Drive\FuseWrapping\FuseFileSystemStringLogging.cs:line 387
at Tmds.Fuse.FuseFileSystemStringBase.FSync(ReadOnlySpan`1 path, FuseFileInfo& fi)
at Tmds.Fuse.FuseMount.Fsync(path* path, fuse_file_info* fi)

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.