Added FUSE support #55
43
fuse.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.arsenm.dev/infinitime"
|
||||||
"go.arsenm.dev/logger/log"
|
"go.arsenm.dev/logger/log"
|
||||||
"os"
|
"os"
|
||||||
"context"
|
"context"
|
||||||
@ -10,28 +11,32 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
yannickulrich marked this conversation as resolved
Outdated
|
|||||||
|
|
||||||
func (i *Device) HeartRateBytes() ([]byte, error) {
|
type Device struct {
|
||||||
yannickulrich marked this conversation as resolved
Outdated
Elara6331
commented
Use Use `os.MkdirAll` here instead so that it creates parent directories, and handle the error (just return it).
yannickulrich
commented
This is actually a bit more complicated than that. If the mountpoint already exists, fuse will crash. We also can't delete the mountpoint beforehand ( This is actually a bit more complicated than that. If the mountpoint already exists, fuse will crash. We also can't delete the mountpoint beforehand (`rm: cannot remove '/tmp/itd/mnt': Transport endpoint is not connected`). The best way to solve this should be calling the [unmount function](https://pkg.go.dev/github.com/hanwen/go-fuse/v2@v2.2.0/fuse#Server.Unmount). How would you suggest going about doing this?
Elara6331
commented
Yeah, this one is going to be a bit more complicated. The FUSE library does have a different unmount function that you could call before trying to mount the fs, but it's not exported, so we'll need to do a small hack to get access to it anyway. In the
|
|||||||
v, err := i.HeartRate()
|
dev *infinitime.Device
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Device) HeartRateBytes() ([]byte, error) {
|
||||||
|
v, err := i.dev.HeartRate()
|
||||||
return []byte(strconv.Itoa(int(v)) + "\n"), err
|
return []byte(strconv.Itoa(int(v)) + "\n"), err
|
||||||
}
|
}
|
||||||
yannickulrich marked this conversation as resolved
Outdated
Elara6331
commented
`err` is returned twice here
yannickulrich
commented
Oh, sorry, fixed now Oh, sorry, fixed now
|
|||||||
func (i *Device) BatteryLevelBytes() ([]byte, error) {
|
func (i Device) BatteryLevelBytes() ([]byte, error) {
|
||||||
v, err := i.BatteryLevel()
|
v, err := i.dev.BatteryLevel()
|
||||||
return []byte(strconv.Itoa(int(v)) + "\n"), err
|
return []byte(strconv.Itoa(int(v)) + "\n"), err
|
||||||
}
|
}
|
||||||
func (i *Device) StepCountBytes() ([]byte, error) {
|
func (i Device) StepCountBytes() ([]byte, error) {
|
||||||
v, err := i.StepCount()
|
v, err := i.dev.StepCount()
|
||||||
return []byte(strconv.Itoa(int(v)) + "\n"), err
|
return []byte(strconv.Itoa(int(v)) + "\n"), err
|
||||||
}
|
}
|
||||||
func (i *Device) MotionBytes() ([]byte, error) {
|
func (i Device) MotionBytes() ([]byte, error) {
|
||||||
v, err := i.Motion()
|
v, err := i.dev.Motion()
|
||||||
return []byte(strconv.Itoa(int(v.X)) + " " + strconv.Itoa(int(v.Y)) + " " + strconv.Itoa(int(v.Z)) + "\n"), err
|
return []byte(strconv.Itoa(int(v.X)) + " " + strconv.Itoa(int(v.Y)) + " " + strconv.Itoa(int(v.Z)) + "\n"), err
|
||||||
}
|
}
|
||||||
func (i *Device) AddressBytes() ([]byte, error) {
|
func (i Device) AddressBytes() ([]byte, error) {
|
||||||
v := i.Address()
|
v := i.dev.Address()
|
||||||
return []byte(v + "\n"), nil
|
return []byte(v + "\n"), nil
|
||||||
}
|
}
|
||||||
func (i *Device) VersionBytes() ([]byte, error) {
|
func (i Device) VersionBytes() ([]byte, error) {
|
||||||
v, err := i.Version()
|
v, err := i.dev.Version()
|
||||||
return []byte(v + "\n"), err
|
return []byte(v + "\n"), err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,12 +512,14 @@ func startFuse(ctx context.Context, dev *infinitime.Device) error {
|
|||||||
Str("target", mntDir).
|
Str("target", mntDir).
|
||||||
Send()
|
Send()
|
||||||
|
|
||||||
properties[0].f = dev.HeartRateBytes;
|
mydev := Device{dev : dev};
|
||||||
properties[1].f = dev.BatteryLevelBytes;
|
|
||||||
properties[2].f = dev.MotionBytes;
|
properties[0].f = mydev.HeartRateBytes;
|
||||||
properties[3].f = dev.StepCountBytes;
|
properties[1].f = mydev.BatteryLevelBytes;
|
||||||
properties[4].f = dev.VersionBytes;
|
properties[2].f = mydev.MotionBytes;
|
||||||
properties[5].f = dev.AddressBytes;
|
properties[3].f = mydev.StepCountBytes;
|
||||||
|
properties[4].f = mydev.VersionBytes;
|
||||||
|
properties[5].f = mydev.AddressBytes;
|
||||||
|
|
||||||
myfs = &FS{};
|
myfs = &FS{};
|
||||||
inodemap = make(map[string]uint64)
|
inodemap = make(map[string]uint64)
|
||||||
|
This function should be called
startFUSE
instead to adhere to Go naming conventionsThanks, I'm relatively new to Go, sorry for these issues
Done in
673383f