forked from Elara6331/itd
Compare commits
10 Commits
955e1323ce
...
fuse
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
008f6b35a9 | ||
|
|
98775600af | ||
|
|
613d33ff4d | ||
|
|
1a1bc30df9 | ||
|
|
c5a6e0d298 | ||
|
|
84c7a33c40 | ||
|
|
dc53ead339 | ||
|
|
9bbdc3bd52 | ||
|
|
b28c386c4e | ||
|
|
4c59561a99 |
11
fuse.go
11
fuse.go
@@ -11,13 +11,20 @@ import (
|
|||||||
|
|
||||||
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
|
||||||
os.Mkdir(k.String("fuse.mountpoint"), 0755)
|
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"))
|
||||||
|
|
||||||
|
|
||||||
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").
|
||||||
Err(err).
|
Err(err).
|
||||||
Send()
|
Send()
|
||||||
return err
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
package fusefs
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.arsenm.dev/infinitime"
|
|
||||||
"context"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
func converterU8(ctx context.Context, in <-chan uint8) <-chan []byte {
|
|
||||||
out := make(chan []byte, 2)
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <- ctx.Done():
|
|
||||||
return
|
|
||||||
case event := <-in:
|
|
||||||
out <- []byte(strconv.Itoa(int(event)) + "\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func converterU32(ctx context.Context, in <-chan uint32) <-chan []byte {
|
|
||||||
out := make(chan []byte, 2)
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <- ctx.Done():
|
|
||||||
return
|
|
||||||
case event := <-in:
|
|
||||||
out <- []byte(strconv.Itoa(int(event)) + "\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func converterMotionValues(ctx context.Context, in <-chan infinitime.MotionValues) <-chan []byte {
|
|
||||||
out := make(chan []byte, 2)
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <- ctx.Done():
|
|
||||||
return
|
|
||||||
case event := <-in:
|
|
||||||
out <- []byte(strconv.Itoa(int(event.X)) + " " + strconv.Itoa(int(event.Y)) + " " + strconv.Itoa(int(event.Z)) + "\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func converter1String(ctx context.Context, in string) <-chan []byte {
|
|
||||||
out := make(chan []byte, 2)
|
|
||||||
out <- []byte(in + "\n")
|
|
||||||
close(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -10,12 +10,13 @@ import (
|
|||||||
"github.com/hanwen/go-fuse/v2/fuse"
|
"github.com/hanwen/go-fuse/v2/fuse"
|
||||||
"io"
|
"io"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ITProperty struct {
|
type ITProperty struct {
|
||||||
name string
|
name string
|
||||||
Ino uint64
|
Ino uint64
|
||||||
gen func(context.Context) (<-chan []byte, error)
|
gen func() ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -55,34 +56,34 @@ 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(ctx context.Context) (<-chan []byte, error) {
|
func() ([]byte, error) {
|
||||||
ans, err := dev.WatchHeartRate(ctx)
|
ans, err := dev.HeartRate()
|
||||||
return converterU8(ctx, ans), err
|
return []byte(strconv.Itoa(int(ans)) + "\n"), err
|
||||||
}}
|
}}
|
||||||
properties[1] = ITProperty{"battery", 3,
|
properties[1] = ITProperty{"battery", 3,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func() ([]byte, error) {
|
||||||
ans, err := dev.WatchBatteryLevel(ctx)
|
ans, err := dev.BatteryLevel()
|
||||||
return converterU8(ctx, ans), err
|
return []byte(strconv.Itoa(int(ans)) + "\n"), err
|
||||||
}}
|
}}
|
||||||
properties[2] = ITProperty{"motion", 4,
|
properties[2] = ITProperty{"motion", 4,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func() ([]byte, error) {
|
||||||
ans, err := dev.WatchMotion(ctx)
|
ans, err := dev.Motion()
|
||||||
return converterMotionValues(ctx, ans), err
|
return []byte(strconv.Itoa(int(ans.X)) + " " + strconv.Itoa(int(ans.Y)) + " " + strconv.Itoa(int(ans.Z)) + "\n"), err
|
||||||
}}
|
}}
|
||||||
properties[3] = ITProperty{"stepcount", 5,
|
properties[3] = ITProperty{"stepcount", 6,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func() ([]byte, error) {
|
||||||
ans, err := dev.WatchStepCount(ctx)
|
ans, err := dev.StepCount()
|
||||||
return converterU32(ctx, ans), err
|
return []byte(strconv.Itoa(int(ans)) + "\n"), err
|
||||||
}}
|
}}
|
||||||
properties[4] = ITProperty{"version", 6,
|
properties[4] = ITProperty{"version", 7,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func() ([]byte, error) {
|
||||||
ans, err := dev.Version()
|
ans, err := dev.Version()
|
||||||
return converter1String(ctx, ans), err
|
return []byte(ans + "\n"), err
|
||||||
}}
|
}}
|
||||||
properties[5] = ITProperty{"address", 7,
|
properties[5] = ITProperty{"address", 8,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func() ([]byte, error) {
|
||||||
ans := dev.Address()
|
ans := dev.Address()
|
||||||
return converter1String(ctx, ans), nil
|
return []byte(ans + "\n"), nil
|
||||||
}}
|
}}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -97,7 +98,7 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
|||||||
// root folder
|
// root folder
|
||||||
r := make([]fuse.DirEntry, 2)
|
r := make([]fuse.DirEntry, 2)
|
||||||
r[0] = fuse.DirEntry{
|
r[0] = fuse.DirEntry{
|
||||||
Name: "device",
|
Name: "info",
|
||||||
Ino: 0,
|
Ino: 0,
|
||||||
Mode: fuse.S_IFDIR,
|
Mode: fuse.S_IFDIR,
|
||||||
}
|
}
|
||||||
@@ -109,7 +110,7 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
|||||||
return fs.NewListDirStream(r), 0
|
return fs.NewListDirStream(r), 0
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// device folder
|
// info folder
|
||||||
r := make([]fuse.DirEntry, 6)
|
r := make([]fuse.DirEntry, 6)
|
||||||
for ind, value := range properties {
|
for ind, value := range properties {
|
||||||
r[ind] = fuse.DirEntry{
|
r[ind] = fuse.DirEntry{
|
||||||
@@ -122,12 +123,11 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
|||||||
return fs.NewListDirStream(r), 0
|
return fs.NewListDirStream(r), 0
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
// on device
|
// on info
|
||||||
files, err := myfs.ReadDir(n.path)
|
files, err := myfs.ReadDir(n.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE ReadDir failed").Str("path", n.path).Err(err).Send()
|
log.Error("FUSE ReadDir failed").Str("path", n.path).Err(err).Send()
|
||||||
// TODO we probably should figure out why it failed
|
return nil, syscallErr(err)
|
||||||
return nil, syscall.ENOENT
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("FUSE ReadDir succeeded").Str("path", n.path).Int("objects", len(files)).Send()
|
log.Debug("FUSE ReadDir succeeded").Str("path", n.path).Int("objects", len(files)).Send()
|
||||||
@@ -137,7 +137,7 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
|||||||
info, err := entry.Info()
|
info, err := entry.Info()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE Info failed").Str("path", n.path).Err(err).Send()
|
log.Error("FUSE Info failed").Str("path", n.path).Err(err).Send()
|
||||||
return nil, syscall.ENOENT
|
return nil, syscallErr(err)
|
||||||
}
|
}
|
||||||
name := info.Name()
|
name := info.Name()
|
||||||
|
|
||||||
@@ -180,7 +180,7 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
|
|||||||
switch n.kind {
|
switch n.kind {
|
||||||
case 0:
|
case 0:
|
||||||
// root folder
|
// root folder
|
||||||
if name == "device" {
|
if name == "info" {
|
||||||
stable := fs.StableAttr{
|
stable := fs.StableAttr{
|
||||||
Mode: fuse.S_IFDIR,
|
Mode: fuse.S_IFDIR,
|
||||||
Ino: uint64(0),
|
Ino: uint64(0),
|
||||||
@@ -198,7 +198,7 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
|
|||||||
return child, 0
|
return child, 0
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
// device folder
|
// info folder
|
||||||
for _, value := range properties {
|
for _, value := range properties {
|
||||||
if value.name == name {
|
if value.name == name {
|
||||||
stable := fs.StableAttr{
|
stable := fs.StableAttr{
|
||||||
@@ -265,18 +265,20 @@ func (fh *bytesFileReadHandle) Read(ctx context.Context, dest []byte, off int64)
|
|||||||
}
|
}
|
||||||
|
|
||||||
type sensorFileReadHandle struct {
|
type sensorFileReadHandle struct {
|
||||||
ch <-chan []byte
|
content []byte
|
||||||
cancel context.CancelFunc
|
|
||||||
}
|
}
|
||||||
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) {
|
||||||
content := <-fh.ch
|
log.Info("Executing Read").Int("size", len(fh.content)).Send()
|
||||||
return fuse.ReadResultData(content), 0
|
end := off + int64(len(dest))
|
||||||
|
if end > int64(len(fh.content)) {
|
||||||
|
end = int64(len(fh.content))
|
||||||
|
}
|
||||||
|
return fuse.ReadResultData(fh.content[off:end]), 0
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
fh.cancel()
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,15 +301,22 @@ 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) {
|
||||||
if len(fh.content) == 0 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
||||||
log.Error("FUSE Flush failed: create").Str("path", fh.path).Err(err).Send()
|
log.Error("FUSE Flush failed: create").Str("path", fh.path).Err(err).Send()
|
||||||
return syscall.EROFS
|
return syscallErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(fh.content) == 0 {
|
||||||
|
log.Debug("FUSE Flush no data to write").Str("path", fh.path).Send()
|
||||||
|
err = fp.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("FUSE Flush failed during close").Str("path", fh.path).Err(err).Send()
|
||||||
|
return syscallErr(err)
|
||||||
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -322,7 +331,7 @@ func (fh *bytesFileWriteHandle) Flush(ctx context.Context) (errno syscall.Errno)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE Flush failed during write").Str("path", fh.path).Err(err).Send()
|
log.Error("FUSE Flush failed during write").Str("path", fh.path).Err(err).Send()
|
||||||
fp.Close()
|
fp.Close()
|
||||||
return syscall.EIO
|
return syscallErr(err)
|
||||||
}
|
}
|
||||||
if int(nread) != len(fh.content) {
|
if int(nread) != len(fh.content) {
|
||||||
log.Error("FUSE Flush failed during write").Str("path", fh.path).Int("expect", len(fh.content)).Int("got", int(nread)).Send()
|
log.Error("FUSE Flush failed during write").Str("path", fh.path).Int("expect", len(fh.content)).Int("got", int(nread)).Send()
|
||||||
@@ -332,7 +341,7 @@ func (fh *bytesFileWriteHandle) Flush(ctx context.Context) (errno syscall.Errno)
|
|||||||
err = fp.Close()
|
err = fp.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE Flush failed during close").Str("path", fh.path).Err(err).Send()
|
log.Error("FUSE Flush failed during close").Str("path", fh.path).Err(err).Send()
|
||||||
return syscall.EIO
|
return syscallErr(err)
|
||||||
}
|
}
|
||||||
log.Debug("FUSE Flush done").Str("path", fh.path).Int("size", len(fh.content)).Send()
|
log.Debug("FUSE Flush done").Str("path", fh.path).Int("size", len(fh.content)).Send()
|
||||||
|
|
||||||
@@ -383,9 +392,8 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
|||||||
log.Debug("FUSE Opening for read").Str("path", f.path).Send()
|
log.Debug("FUSE Opening for read").Str("path", f.path).Send()
|
||||||
fp, err := myfs.Open(f.path)
|
fp, err := myfs.Open(f.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO we probably should figure out why it failed
|
|
||||||
log.Error("FUSE: Opening failed").Str("path", f.path).Err(err).Send()
|
log.Error("FUSE: Opening failed").Str("path", f.path).Err(err).Send()
|
||||||
return nil, 0, syscall.EROFS
|
return nil, 0, syscallErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer fp.Close()
|
defer fp.Close()
|
||||||
@@ -403,7 +411,7 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE Read failed").Str("path", f.path).Err(err).Send()
|
log.Error("FUSE Read failed").Str("path", f.path).Err(err).Send()
|
||||||
fp.Close()
|
fp.Close()
|
||||||
return nil, 0, syscall.EIO
|
return nil, 0, syscallErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fh = &bytesFileReadHandle{
|
fh = &bytesFileReadHandle{
|
||||||
@@ -422,16 +430,13 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
|||||||
|
|
||||||
for _, value := range properties {
|
for _, value := range properties {
|
||||||
if value.Ino == f.Ino {
|
if value.Ino == f.Ino {
|
||||||
sub_ctx, cancel := context.WithCancel(ctx)
|
ans, err := value.gen()
|
||||||
ans, err := value.gen(sub_ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO we probably should figure out why it failed
|
return nil, 0, syscallErr(err)
|
||||||
return nil, 0, syscall.EIO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fh = &sensorFileReadHandle{
|
fh = &sensorFileReadHandle{
|
||||||
ch: ans,
|
content : ans,
|
||||||
cancel : cancel,
|
|
||||||
}
|
}
|
||||||
return fh, fuse.FOPEN_DIRECT_IO, 0
|
return fh, fuse.FOPEN_DIRECT_IO, 0
|
||||||
}
|
}
|
||||||
@@ -484,8 +489,7 @@ func (f *ITNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.
|
|||||||
Str("path", path).
|
Str("path", path).
|
||||||
Err(err).
|
Err(err).
|
||||||
Send()
|
Send()
|
||||||
// TODO we probably should figure out why it failed
|
return nil, syscallErr(err)
|
||||||
return nil, syscall.EROFS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ino := uint64(len(inodemap)) + 11
|
ino := uint64(len(inodemap)) + 11
|
||||||
@@ -525,8 +529,7 @@ func (f *ITNode) Rename(ctx context.Context, name string, newParent fs.InodeEmbe
|
|||||||
Err(err).
|
Err(err).
|
||||||
Send()
|
Send()
|
||||||
|
|
||||||
// TODO we probably should figure out why it failed
|
return syscallErr(err)
|
||||||
return syscall.EIO
|
|
||||||
}
|
}
|
||||||
log.Debug("FUSE Rename sucess").
|
log.Debug("FUSE Rename sucess").
|
||||||
Str("src", p1).
|
Str("src", p1).
|
||||||
@@ -554,8 +557,7 @@ func (f *ITNode) Unlink(ctx context.Context, name string) syscall.Errno {
|
|||||||
Err(err).
|
Err(err).
|
||||||
Send()
|
Send()
|
||||||
|
|
||||||
// TODO we probably should figure out why it failed
|
return syscallErr(err)
|
||||||
return syscall.EIO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("FUSE Unlink success").
|
log.Debug("FUSE Unlink success").
|
||||||
|
|||||||
67
internal/fusefs/syscallerr.go
Normal file
67
internal/fusefs/syscallerr.go
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package fusefs
|
||||||
|
import (
|
||||||
|
"go.arsenm.dev/infinitime/blefs"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func syscallErr(err error) syscall.Errno {
|
||||||
|
if err == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
switch err {
|
||||||
|
case blefs.FSError{0x02}: // filesystem error
|
||||||
|
return syscall.EIO // TODO
|
||||||
|
case blefs.FSError{0x05}: // read-only filesystem
|
||||||
|
return syscall.EROFS
|
||||||
|
case blefs.FSError{0x03}: // no such file
|
||||||
|
return syscall.ENOENT
|
||||||
|
case blefs.FSError{0x04}: // protocol error
|
||||||
|
return syscall.EPROTO
|
||||||
|
case blefs.FSError{-5}: // input/output error
|
||||||
|
return syscall.EIO
|
||||||
|
case blefs.FSError{-84}: // filesystem is corrupted
|
||||||
|
return syscall.ENOTRECOVERABLE // TODO
|
||||||
|
case blefs.FSError{-2}: // no such directory entry
|
||||||
|
return syscall.ENOENT
|
||||||
|
case blefs.FSError{-17}: // entry already exists
|
||||||
|
return syscall.EEXIST
|
||||||
|
case blefs.FSError{-20}: // entry is not a directory
|
||||||
|
return syscall.ENOTDIR
|
||||||
|
case blefs.FSError{-39}: // directory is not empty
|
||||||
|
return syscall.ENOTEMPTY
|
||||||
|
case blefs.FSError{-9}: // bad file number
|
||||||
|
return syscall.EBADF
|
||||||
|
case blefs.FSError{-27}: // file is too large
|
||||||
|
return syscall.EFBIG
|
||||||
|
case blefs.FSError{-22}: // invalid parameter
|
||||||
|
return syscall.EINVAL
|
||||||
|
case blefs.FSError{-28}: // no space left on device
|
||||||
|
return syscall.ENOSPC
|
||||||
|
case blefs.FSError{-12}: // no more memory available
|
||||||
|
return syscall.ENOMEM
|
||||||
|
case blefs.FSError{-61}: // no attr available
|
||||||
|
return syscall.ENODATA // TODO
|
||||||
|
case blefs.FSError{-36}: // file name is too long
|
||||||
|
return syscall.ENAMETOOLONG
|
||||||
|
case blefs.ErrFileNotExists: // file does not exist
|
||||||
|
return syscall.ENOENT
|
||||||
|
case blefs.ErrFileReadOnly: // file is read only
|
||||||
|
return syscall.EACCES
|
||||||
|
case blefs.ErrFileWriteOnly: // file is write only
|
||||||
|
return syscall.EACCES
|
||||||
|
case blefs.ErrInvalidOffset: // invalid file offset
|
||||||
|
return syscall.EFAULT // TODO
|
||||||
|
case blefs.ErrOffsetChanged: // offset has already been changed
|
||||||
|
return syscall.ESPIPE
|
||||||
|
case blefs.ErrReadOpen: // only one file can be opened for reading at a time
|
||||||
|
return syscall.ENFILE
|
||||||
|
case blefs.ErrWriteOpen: // only one file can be opened for writing at a time
|
||||||
|
return syscall.ENFILE
|
||||||
|
case blefs.ErrNoRemoveRoot: // refusing to remove root directory
|
||||||
|
return syscall.EPERM
|
||||||
|
}
|
||||||
|
|
||||||
|
return syscall.EIO // TODO
|
||||||
|
|
||||||
|
}
|
||||||
15
internal/fusefs/unmount.go
Normal file
15
internal/fusefs/unmount.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package fusefs
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "unsafe"
|
||||||
|
"github.com/hanwen/go-fuse/v2/fuse"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Unmount(mountPoint string) error {
|
||||||
|
return unmount(mountPoint, &fuse.MountOptions{DirectMount: false})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unfortunately, the FUSE library does not export its unmount function,
|
||||||
|
// so this is required until that changes
|
||||||
|
//go:linkname unmount github.com/hanwen/go-fuse/v2/fuse.unmount
|
||||||
|
func unmount(mountPoint string, opts *fuse.MountOptions) error
|
||||||
Reference in New Issue
Block a user