itd/fuse.go
2023-03-01 15:14:06 +00:00

46 lines
1022 B
Go

package main
import (
"go.arsenm.dev/itd/internal/fusefs"
"os"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
"go.arsenm.dev/logger/log"
"context"
"go.arsenm.dev/infinitime"
)
func startFuse(ctx context.Context, dev *infinitime.Device) error {
// This is where we'll mount the FS
os.Mkdir(k.String("fuse.mountpoint"), 0755)
root := fusefs.BuildRootNode(dev)
server, err := fs.Mount(k.String("fuse.mountpoint"), root, &fs.Options{
MountOptions: fuse.MountOptions{
// Set to true to see how the file system works.
Debug: false,
SingleThreaded: true,
},
})
if err != nil {
log.Error("Mounting failed").
Str("target", k.String("fuse.mountpoint")).
Err(err).
Send()
return err
}
log.Info("Mounted on target").
Str("target", k.String("fuse.mountpoint")).
Send()
fusefs.BuildProperties(dev)
if err != nil {
log.Warn("Error getting BLE filesystem").Err(err).Send()
return err
}
// Wait until unmount before exiting
go server.Serve()
return nil
}