itd/fuse.go

46 lines
1022 B
Go
Raw Normal View History

2023-03-01 15:12:48 +00:00
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"
)
2023-03-01 18:01:25 +00:00
func startFUSE(ctx context.Context, dev *infinitime.Device) error {
2023-03-01 15:12:48 +00:00
// This is where we'll mount the FS
os.Mkdir(k.String("fuse.mountpoint"), 0755)
2023-03-01 15:14:06 +00:00
root := fusefs.BuildRootNode(dev)
2023-03-01 15:12:48 +00:00
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()
2023-03-01 15:14:06 +00:00
fusefs.BuildProperties(dev)
2023-03-01 15:12:48 +00:00
if err != nil {
log.Warn("Error getting BLE filesystem").Err(err).Send()
return err
}
// Wait until unmount before exiting
go server.Serve()
return nil
}