Run formatter

This commit is contained in:
Elara 2023-03-25 15:24:46 -07:00
parent 77680704e1
commit 510f183db2
5 changed files with 103 additions and 72 deletions

View File

@ -107,7 +107,7 @@ func setCfgDefaults() {
"music.vol.interval": 5, "music.vol.interval": 5,
"fuse.enabled": false, "fuse.enabled": false,
"fuse.mountpoint": "/tmp/itd/mnt", "fuse.mountpoint": "/tmp/itd/mnt",
}, "."), nil) }, "."), nil)
} }

15
fuse.go
View File

@ -1,17 +1,19 @@
package main package main
import ( import (
"go.arsenm.dev/itd/internal/fusefs" "context"
"os" "os"
"github.com/hanwen/go-fuse/v2/fs" "github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse" "github.com/hanwen/go-fuse/v2/fuse"
"go.arsenm.dev/logger/log"
"context"
"go.arsenm.dev/infinitime" "go.arsenm.dev/infinitime"
"go.arsenm.dev/itd/internal/fusefs"
"go.arsenm.dev/logger/log"
) )
func startFUSE(ctx context.Context, dev *infinitime.Device) error { func startFUSE(ctx context.Context, dev *infinitime.Device) error {
// This is where we'll mount the FS // This is where we'll mount the FS
err := os.MkdirAll(k.String("fuse.mountpoint"), 0755) err := os.MkdirAll(k.String("fuse.mountpoint"), 0o755)
if err != nil && !os.IsExist(err) { if err != nil && !os.IsExist(err) {
return err return err
} }
@ -19,7 +21,6 @@ func startFUSE(ctx context.Context, dev *infinitime.Device) error {
// Ignore the error because nothing might be mounted on the mountpoint // Ignore the error because nothing might be mounted on the mountpoint
_ = fusefs.Unmount(k.String("fuse.mountpoint")) _ = fusefs.Unmount(k.String("fuse.mountpoint"))
root, err := fusefs.BuildRootNode(dev) root, err := fusefs.BuildRootNode(dev)
if err != nil { if err != nil {
log.Error("Building root node failed"). log.Error("Building root node failed").
@ -31,7 +32,7 @@ func startFUSE(ctx context.Context, dev *infinitime.Device) error {
server, err := fs.Mount(k.String("fuse.mountpoint"), root, &fs.Options{ server, err := fs.Mount(k.String("fuse.mountpoint"), root, &fs.Options{
MountOptions: fuse.MountOptions{ MountOptions: fuse.MountOptions{
// Set to true to see how the file system works. // Set to true to see how the file system works.
Debug: false, Debug: false,
SingleThreaded: true, SingleThreaded: true,
}, },
}) })
@ -40,7 +41,7 @@ func startFUSE(ctx context.Context, dev *infinitime.Device) error {
Str("target", k.String("fuse.mountpoint")). Str("target", k.String("fuse.mountpoint")).
Err(err). Err(err).
Send() Send()
return err return err
} }
log.Info("Mounted on target"). log.Info("Mounted on target").

View File

@ -1,44 +1,46 @@
package fusefs package fusefs
import ( import (
"bytes"
"context"
"io"
"strconv"
"syscall"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
"go.arsenm.dev/infinitime" "go.arsenm.dev/infinitime"
"go.arsenm.dev/infinitime/blefs" "go.arsenm.dev/infinitime/blefs"
"go.arsenm.dev/logger/log" "go.arsenm.dev/logger/log"
"context"
"syscall"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
"io"
"bytes"
"strconv"
) )
type ITProperty struct { type ITProperty struct {
name string name string
Ino uint64 Ino uint64
gen func() ([]byte, error) gen func() ([]byte, error)
} }
type DirEntry struct { type DirEntry struct {
isDir bool isDir bool
modtime uint64 modtime uint64
size uint32 size uint32
path string path string
} }
type ITNode struct { type ITNode struct {
fs.Inode fs.Inode
kind int kind int
Ino uint64 Ino uint64
lst []DirEntry lst []DirEntry
self DirEntry self DirEntry
path string path string
} }
var myfs *blefs.FS = nil var (
var inodemap map[string]uint64 = nil myfs *blefs.FS = nil
inodemap map[string]uint64 = nil
)
func BuildRootNode(dev *infinitime.Device) (*ITNode, error) { func BuildRootNode(dev *infinitime.Device) (*ITNode, error) {
var err error var err error
@ -55,40 +57,50 @@ func BuildRootNode(dev *infinitime.Device) (*ITNode, error) {
var properties = make([]ITProperty, 6) var properties = make([]ITProperty, 6)
func BuildProperties(dev *infinitime.Device) { func BuildProperties(dev *infinitime.Device) {
properties[0] = ITProperty{"heartrate", 2, properties[0] = ITProperty{
"heartrate", 2,
func() ([]byte, error) { func() ([]byte, error) {
ans, err := dev.HeartRate() ans, err := dev.HeartRate()
return []byte(strconv.Itoa(int(ans)) + "\n"), err return []byte(strconv.Itoa(int(ans)) + "\n"), err
}} },
properties[1] = ITProperty{"battery", 3, }
properties[1] = ITProperty{
"battery", 3,
func() ([]byte, error) { func() ([]byte, error) {
ans, err := dev.BatteryLevel() ans, err := dev.BatteryLevel()
return []byte(strconv.Itoa(int(ans)) + "\n"), err return []byte(strconv.Itoa(int(ans)) + "\n"), err
}} },
properties[2] = ITProperty{"motion", 4, }
properties[2] = ITProperty{
"motion", 4,
func() ([]byte, error) { func() ([]byte, error) {
ans, err := dev.Motion() ans, err := dev.Motion()
return []byte(strconv.Itoa(int(ans.X)) + " " + strconv.Itoa(int(ans.Y)) + " " + strconv.Itoa(int(ans.Z)) + "\n"), err return []byte(strconv.Itoa(int(ans.X)) + " " + strconv.Itoa(int(ans.Y)) + " " + strconv.Itoa(int(ans.Z)) + "\n"), err
}} },
properties[3] = ITProperty{"stepcount", 6, }
properties[3] = ITProperty{
"stepcount", 6,
func() ([]byte, error) { func() ([]byte, error) {
ans, err := dev.StepCount() ans, err := dev.StepCount()
return []byte(strconv.Itoa(int(ans)) + "\n"), err return []byte(strconv.Itoa(int(ans)) + "\n"), err
}} },
properties[4] = ITProperty{"version", 7, }
properties[4] = ITProperty{
"version", 7,
func() ([]byte, error) { func() ([]byte, error) {
ans, err := dev.Version() ans, err := dev.Version()
return []byte(ans + "\n"), err return []byte(ans + "\n"), err
}} },
properties[5] = ITProperty{"address", 8, }
properties[5] = ITProperty{
"address", 8,
func() ([]byte, error) { func() ([]byte, error) {
ans := dev.Address() ans := dev.Address()
return []byte(ans + "\n"), nil return []byte(ans + "\n"), nil
}} },
}
} }
var _ fs.NodeReaddirer = (*ITNode)(nil) var _ fs.NodeReaddirer = (*ITNode)(nil)
// Readdir is part of the NodeReaddirer interface // Readdir is part of the NodeReaddirer interface
@ -142,10 +154,10 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
name := info.Name() name := info.Name()
file := DirEntry{ file := DirEntry{
path: n.path + "/" + name, path: n.path + "/" + name,
size: uint32(info.Size()), size: uint32(info.Size()),
modtime: uint64(info.ModTime().Unix()), modtime: uint64(info.ModTime().Unix()),
isDir: info.IsDir(), isDir: info.IsDir(),
} }
n.lst[ind] = file n.lst[ind] = file
@ -159,13 +171,13 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
r[ind] = fuse.DirEntry{ r[ind] = fuse.DirEntry{
Name: name, Name: name,
Mode: fuse.S_IFDIR, Mode: fuse.S_IFDIR,
Ino : ino + 10, Ino: ino + 10,
} }
} else { } else {
r[ind] = fuse.DirEntry{ r[ind] = fuse.DirEntry{
Name: name, Name: name,
Mode: fuse.S_IFREG, Mode: fuse.S_IFREG,
Ino : ino + 10, Ino: ino + 10,
} }
} }
} }
@ -176,6 +188,7 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
} }
var _ fs.NodeLookuper = (*ITNode)(nil) var _ fs.NodeLookuper = (*ITNode)(nil)
func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) { func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
switch n.kind { switch n.kind {
case 0: case 0:
@ -183,7 +196,7 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
if name == "info" { if name == "info" {
stable := fs.StableAttr{ stable := fs.StableAttr{
Mode: fuse.S_IFDIR, Mode: fuse.S_IFDIR,
Ino: uint64(0), Ino: uint64(0),
} }
operations := &ITNode{kind: 1, Ino: 0} operations := &ITNode{kind: 1, Ino: 0}
child := n.NewInode(ctx, operations, stable) child := n.NewInode(ctx, operations, stable)
@ -191,9 +204,9 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
} else if name == "fs" { } else if name == "fs" {
stable := fs.StableAttr{ stable := fs.StableAttr{
Mode: fuse.S_IFDIR, Mode: fuse.S_IFDIR,
Ino: uint64(1), Ino: uint64(1),
} }
operations := &ITNode{kind: 2, Ino: 1, path : ""} operations := &ITNode{kind: 2, Ino: 1, path: ""}
child := n.NewInode(ctx, operations, stable) child := n.NewInode(ctx, operations, stable)
return child, 0 return child, 0
} }
@ -203,7 +216,7 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
if value.name == name { if value.name == name {
stable := fs.StableAttr{ stable := fs.StableAttr{
Mode: fuse.S_IFREG, Mode: fuse.S_IFREG,
Ino: uint64(value.Ino), Ino: uint64(value.Ino),
} }
operations := &ITNode{kind: 3, Ino: value.Ino} operations := &ITNode{kind: 3, Ino: value.Ino}
child := n.NewInode(ctx, operations, stable) child := n.NewInode(ctx, operations, stable)
@ -218,7 +231,7 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
} }
for _, file := range n.lst { for _, file := range n.lst {
if file.path != n.path + "/" + name { if file.path != n.path+"/"+name {
continue continue
} }
log.Debug("FUSE Lookup successful").Str("path", file.path).Send() log.Debug("FUSE Lookup successful").Str("path", file.path).Send()
@ -226,7 +239,7 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
if file.isDir { if file.isDir {
stable := fs.StableAttr{ stable := fs.StableAttr{
Mode: fuse.S_IFDIR, Mode: fuse.S_IFDIR,
Ino: inodemap[file.path], Ino: inodemap[file.path],
} }
operations := &ITNode{kind: 2, path: file.path} operations := &ITNode{kind: 2, path: file.path}
child := n.NewInode(ctx, operations, stable) child := n.NewInode(ctx, operations, stable)
@ -234,7 +247,7 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
} else { } else {
stable := fs.StableAttr{ stable := fs.StableAttr{
Mode: fuse.S_IFREG, Mode: fuse.S_IFREG,
Ino: inodemap[file.path], Ino: inodemap[file.path],
} }
operations := &ITNode{ operations := &ITNode{
kind: 2, path: file.path, kind: 2, path: file.path,
@ -245,7 +258,7 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
} }
break break
} }
log.Warn("FUSE Lookup failed").Str("path", n.path + "/" + name).Send() log.Warn("FUSE Lookup failed").Str("path", n.path+"/"+name).Send()
} }
return nil, syscall.ENOENT return nil, syscall.ENOENT
} }
@ -255,6 +268,7 @@ type bytesFileReadHandle struct {
} }
var _ fs.FileReader = (*bytesFileReadHandle)(nil) var _ fs.FileReader = (*bytesFileReadHandle)(nil)
func (fh *bytesFileReadHandle) Read(ctx context.Context, dest []byte, off int64) (fuse.ReadResult, syscall.Errno) { func (fh *bytesFileReadHandle) Read(ctx context.Context, dest []byte, off int64) (fuse.ReadResult, syscall.Errno) {
log.Debug("FUSE Executing Read").Int("size", len(fh.content)).Send() log.Debug("FUSE Executing Read").Int("size", len(fh.content)).Send()
end := off + int64(len(dest)) end := off + int64(len(dest))
@ -267,7 +281,9 @@ func (fh *bytesFileReadHandle) Read(ctx context.Context, dest []byte, off int64)
type sensorFileReadHandle struct { type sensorFileReadHandle struct {
content []byte content []byte
} }
var _ fs.FileReader = (*sensorFileReadHandle)(nil) var _ fs.FileReader = (*sensorFileReadHandle)(nil)
func (fh *sensorFileReadHandle) Read(ctx context.Context, dest []byte, off int64) (fuse.ReadResult, syscall.Errno) { func (fh *sensorFileReadHandle) Read(ctx context.Context, dest []byte, off int64) (fuse.ReadResult, syscall.Errno) {
log.Info("Executing Read").Int("size", len(fh.content)).Send() log.Info("Executing Read").Int("size", len(fh.content)).Send()
end := off + int64(len(dest)) end := off + int64(len(dest))
@ -278,17 +294,18 @@ func (fh *sensorFileReadHandle) Read(ctx context.Context, dest []byte, off int64
} }
var _ fs.FileFlusher = (*sensorFileReadHandle)(nil) var _ fs.FileFlusher = (*sensorFileReadHandle)(nil)
func (fh *sensorFileReadHandle) Flush(ctx context.Context) (errno syscall.Errno) { func (fh *sensorFileReadHandle) Flush(ctx context.Context) (errno syscall.Errno) {
return 0 return 0
} }
type bytesFileWriteHandle struct { type bytesFileWriteHandle struct {
content []byte content []byte
path string path string
} }
var _ fs.FileWriter = (*bytesFileWriteHandle)(nil) var _ fs.FileWriter = (*bytesFileWriteHandle)(nil)
func (fh *bytesFileWriteHandle) Write(ctx context.Context, data []byte, off int64) (written uint32, errno syscall.Errno) { func (fh *bytesFileWriteHandle) Write(ctx context.Context, data []byte, off int64) (written uint32, errno syscall.Errno) {
log.Info("Executing Write").Str("path", fh.path).Int("prev_size", len(fh.content)).Int("next_size", len(data)).Send() log.Info("Executing Write").Str("path", fh.path).Int("prev_size", len(fh.content)).Int("next_size", len(data)).Send()
if off != int64(len(fh.content)) { if off != int64(len(fh.content)) {
@ -300,8 +317,8 @@ func (fh *bytesFileWriteHandle) Write(ctx context.Context, data []byte, off int6
} }
var _ fs.FileFlusher = (*bytesFileWriteHandle)(nil) var _ fs.FileFlusher = (*bytesFileWriteHandle)(nil)
func (fh *bytesFileWriteHandle) Flush(ctx context.Context) (errno syscall.Errno) {
func (fh *bytesFileWriteHandle) Flush(ctx context.Context) (errno syscall.Errno) {
log.Debug("FUSE Attempting flush").Str("path", fh.path).Send() log.Debug("FUSE Attempting flush").Str("path", fh.path).Send()
fp, err := myfs.Create(fh.path, uint32(len(fh.content))) fp, err := myfs.Create(fh.path, uint32(len(fh.content)))
if err != nil { if err != nil {
@ -347,12 +364,15 @@ func (fh *bytesFileWriteHandle) Flush(ctx context.Context) (errno syscall.Errno)
return 0 return 0
} }
var _ fs.FileFsyncer = (*bytesFileWriteHandle)(nil) var _ fs.FileFsyncer = (*bytesFileWriteHandle)(nil)
func (fh *bytesFileWriteHandle) Fsync(ctx context.Context, flags uint32) (errno syscall.Errno) { func (fh *bytesFileWriteHandle) Fsync(ctx context.Context, flags uint32) (errno syscall.Errno) {
return fh.Flush(ctx) return fh.Flush(ctx)
} }
var _ fs.NodeGetattrer = (*ITNode)(nil) var _ fs.NodeGetattrer = (*ITNode)(nil)
func (bn *ITNode) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) syscall.Errno { func (bn *ITNode) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
log.Debug("FUSE getattr").Str("path", bn.path).Send() log.Debug("FUSE getattr").Str("path", bn.path).Send()
out.Ino = bn.Ino out.Ino = bn.Ino
@ -364,6 +384,7 @@ func (bn *ITNode) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOu
} }
var _ fs.NodeSetattrer = (*ITNode)(nil) var _ fs.NodeSetattrer = (*ITNode)(nil)
func (bn *ITNode) Setattr(ctx context.Context, fh fs.FileHandle, in *fuse.SetAttrIn, out *fuse.AttrOut) syscall.Errno { func (bn *ITNode) Setattr(ctx context.Context, fh fs.FileHandle, in *fuse.SetAttrIn, out *fuse.AttrOut) syscall.Errno {
log.Debug("FUSE setattr").Str("path", bn.path).Send() log.Debug("FUSE setattr").Str("path", bn.path).Send()
out.Size = 0 out.Size = 0
@ -372,6 +393,7 @@ func (bn *ITNode) Setattr(ctx context.Context, fh fs.FileHandle, in *fuse.SetAtt
} }
var _ fs.NodeOpener = (*ITNode)(nil) var _ fs.NodeOpener = (*ITNode)(nil)
func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle, fuseFlags uint32, errno syscall.Errno) { func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle, fuseFlags uint32, errno syscall.Errno) {
switch f.kind { switch f.kind {
case 2: case 2:
@ -381,11 +403,11 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
return nil, 0, syscall.EROFS return nil, 0, syscall.EROFS
} }
if openFlags & syscall.O_WRONLY != 0 { if openFlags&syscall.O_WRONLY != 0 {
log.Debug("FUSE Opening for write").Str("path", f.path).Send() log.Debug("FUSE Opening for write").Str("path", f.path).Send()
fh = &bytesFileWriteHandle{ fh = &bytesFileWriteHandle{
path : f.path, path: f.path,
content : make([]byte, 0), content: make([]byte, 0),
} }
return fh, fuse.FOPEN_DIRECT_IO, 0 return fh, fuse.FOPEN_DIRECT_IO, 0
} else { } else {
@ -436,7 +458,7 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
} }
fh = &sensorFileReadHandle{ fh = &sensorFileReadHandle{
content : ans, content: ans,
} }
return fh, fuse.FOPEN_DIRECT_IO, 0 return fh, fuse.FOPEN_DIRECT_IO, 0
} }
@ -446,6 +468,7 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
} }
var _ fs.NodeCreater = (*ITNode)(nil) var _ fs.NodeCreater = (*ITNode)(nil)
func (f *ITNode) Create(ctx context.Context, name string, flags uint32, mode uint32, out *fuse.EntryOut) (node *fs.Inode, fh fs.FileHandle, fuseFlags uint32, errno syscall.Errno) { func (f *ITNode) Create(ctx context.Context, name string, flags uint32, mode uint32, out *fuse.EntryOut) (node *fs.Inode, fh fs.FileHandle, fuseFlags uint32, errno syscall.Errno) {
if f.kind != 2 { if f.kind != 2 {
return nil, nil, 0, syscall.EROFS return nil, nil, 0, syscall.EROFS
@ -457,17 +480,17 @@ func (f *ITNode) Create(ctx context.Context, name string, flags uint32, mode uin
stable := fs.StableAttr{ stable := fs.StableAttr{
Mode: fuse.S_IFREG, Mode: fuse.S_IFREG,
Ino: ino, Ino: ino,
} }
operations := &ITNode{ operations := &ITNode{
kind: 2, Ino: ino, kind: 2, Ino: ino,
path : path, path: path,
} }
node = f.NewInode(ctx, operations, stable) node = f.NewInode(ctx, operations, stable)
fh = &bytesFileWriteHandle{ fh = &bytesFileWriteHandle{
path : path, path: path,
content : make([]byte, 0), content: make([]byte, 0),
} }
log.Debug("FUSE Creating file").Str("path", path).Send() log.Debug("FUSE Creating file").Str("path", path).Send()
@ -477,6 +500,7 @@ func (f *ITNode) Create(ctx context.Context, name string, flags uint32, mode uin
} }
var _ fs.NodeMkdirer = (*ITNode)(nil) var _ fs.NodeMkdirer = (*ITNode)(nil)
func (f *ITNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) { func (f *ITNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (*fs.Inode, syscall.Errno) {
if f.kind != 2 { if f.kind != 2 {
return nil, syscall.EROFS return nil, syscall.EROFS
@ -497,11 +521,11 @@ func (f *ITNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.
stable := fs.StableAttr{ stable := fs.StableAttr{
Mode: fuse.S_IFDIR, Mode: fuse.S_IFDIR,
Ino: ino, Ino: ino,
} }
operations := &ITNode{ operations := &ITNode{
kind: 2, Ino: ino, kind: 2, Ino: ino,
path : path, path: path,
} }
node := f.NewInode(ctx, operations, stable) node := f.NewInode(ctx, operations, stable)
@ -513,6 +537,7 @@ func (f *ITNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.
} }
var _ fs.NodeRenamer = (*ITNode)(nil) var _ fs.NodeRenamer = (*ITNode)(nil)
func (f *ITNode) Rename(ctx context.Context, name string, newParent fs.InodeEmbedder, newName string, flags uint32) syscall.Errno { func (f *ITNode) Rename(ctx context.Context, name string, newParent fs.InodeEmbedder, newName string, flags uint32) syscall.Errno {
if f.kind != 2 { if f.kind != 2 {
return syscall.EROFS return syscall.EROFS
@ -544,16 +569,17 @@ func (f *ITNode) Rename(ctx context.Context, name string, newParent fs.InodeEmbe
} }
var _ fs.NodeUnlinker = (*ITNode)(nil) var _ fs.NodeUnlinker = (*ITNode)(nil)
func (f *ITNode) Unlink(ctx context.Context, name string) syscall.Errno { func (f *ITNode) Unlink(ctx context.Context, name string) syscall.Errno {
if f.kind != 2 { if f.kind != 2 {
return syscall.EROFS return syscall.EROFS
} }
delete(inodemap, f.path + "/" + name) delete(inodemap, f.path+"/"+name)
err := myfs.Remove(f.path + "/" + name) err := myfs.Remove(f.path + "/" + name)
if err != nil { if err != nil {
log.Error("FUSE Unlink failed"). log.Error("FUSE Unlink failed").
Str("file", f.path + "/" + name). Str("file", f.path+"/"+name).
Err(err). Err(err).
Send() Send()
@ -561,12 +587,13 @@ func (f *ITNode) Unlink(ctx context.Context, name string) syscall.Errno {
} }
log.Debug("FUSE Unlink success"). log.Debug("FUSE Unlink success").
Str("file", f.path + "/" + name). Str("file", f.path+"/"+name).
Send() Send()
return 0 return 0
} }
var _ fs.NodeRmdirer = (*ITNode)(nil) var _ fs.NodeRmdirer = (*ITNode)(nil)
func (f *ITNode) Rmdir(ctx context.Context, name string) syscall.Errno { func (f *ITNode) Rmdir(ctx context.Context, name string) syscall.Errno {
return f.Unlink(ctx, name) return f.Unlink(ctx, name)
} }

View File

@ -1,7 +1,9 @@
package fusefs package fusefs
import ( import (
"go.arsenm.dev/infinitime/blefs"
"syscall" "syscall"
"go.arsenm.dev/infinitime/blefs"
) )
func syscallErr(err error) syscall.Errno { func syscallErr(err error) syscall.Errno {
@ -51,7 +53,7 @@ func syscallErr(err error) syscall.Errno {
case blefs.ErrFileWriteOnly: // file is write only case blefs.ErrFileWriteOnly: // file is write only
return syscall.EACCES return syscall.EACCES
case blefs.ErrInvalidOffset: // invalid file offset case blefs.ErrInvalidOffset: // invalid file offset
return syscall.EFAULT // TODO return syscall.EFAULT // TODO
case blefs.ErrOffsetChanged: // offset has already been changed case blefs.ErrOffsetChanged: // offset has already been changed
return syscall.ESPIPE return syscall.ESPIPE
case blefs.ErrReadOpen: // only one file can be opened for reading at a time case blefs.ErrReadOpen: // only one file can be opened for reading at a time
@ -63,5 +65,4 @@ func syscallErr(err error) syscall.Errno {
} }
return syscall.EIO // TODO return syscall.EIO // TODO
} }

View File

@ -2,6 +2,7 @@ package fusefs
import ( import (
_ "unsafe" _ "unsafe"
"github.com/hanwen/go-fuse/v2/fuse" "github.com/hanwen/go-fuse/v2/fuse"
) )
@ -11,5 +12,6 @@ func Unmount(mountPoint string) error {
// Unfortunately, the FUSE library does not export its unmount function, // Unfortunately, the FUSE library does not export its unmount function,
// so this is required until that changes // so this is required until that changes
//
//go:linkname unmount github.com/hanwen/go-fuse/v2/fuse.unmount //go:linkname unmount github.com/hanwen/go-fuse/v2/fuse.unmount
func unmount(mountPoint string, opts *fuse.MountOptions) error func unmount(mountPoint string, opts *fuse.MountOptions) error