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
|
2023-03-12 12:32:56 +00:00
|
|
|
err := os.MkdirAll(k.String("fuse.mountpoint"), 0755)
|
|
|
|
if err != nil && !os.IsExist(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore the error because nothing might be mounted on the mountpoint
|
|
|
|
_ = fusefs.Unmount(k.String("fuse.mountpoint"))
|
|
|
|
|
|
|
|
|
2023-03-01 18:08:58 +00:00
|
|
|
root, err := fusefs.BuildRootNode(dev)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Building root node failed").
|
|
|
|
Err(err).
|
|
|
|
Send()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|