forked from Elara6331/itd
Improved logging
This commit is contained in:
parent
5d71ae245c
commit
1a5970a041
63
fuse/main.go
63
fuse/main.go
@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"go.arsenm.dev/logger/log"
|
||||||
"os"
|
"os"
|
||||||
"context"
|
"context"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -100,6 +100,7 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
|||||||
case 2:
|
case 2:
|
||||||
// on device
|
// on device
|
||||||
files, _ := myfs.ReadDir(n.path)
|
files, _ := myfs.ReadDir(n.path)
|
||||||
|
log.Info("readdir").Str("path", n.path).Int("objects", len(files)).Send()
|
||||||
r := make([]fuse.DirEntry, len(files))
|
r := make([]fuse.DirEntry, len(files))
|
||||||
n.lst = files
|
n.lst = files
|
||||||
for ind, file := range files {
|
for ind, file := range files {
|
||||||
@ -174,7 +175,7 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
|
|||||||
if file.path != n.path + "/" + name {
|
if file.path != n.path + "/" + name {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
log.Println("matched", name)
|
log.Info("LookUp successful").Str("path", file.path).Send()
|
||||||
|
|
||||||
if file.flags & 0b1 == 1 {
|
if file.flags & 0b1 == 1 {
|
||||||
stable := fs.StableAttr{
|
stable := fs.StableAttr{
|
||||||
@ -198,6 +199,7 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
log.Warn("LookUp failed").Str("path", n.path + "/" + name).Send()
|
||||||
}
|
}
|
||||||
return nil, syscall.ENOENT
|
return nil, syscall.ENOENT
|
||||||
}
|
}
|
||||||
@ -208,6 +210,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.Info("Executing Read").Int("size", len(fh.content)).Send()
|
||||||
end := off + int64(len(dest))
|
end := off + int64(len(dest))
|
||||||
if end > int64(len(fh.content)) {
|
if end > int64(len(fh.content)) {
|
||||||
end = int64(len(fh.content))
|
end = int64(len(fh.content))
|
||||||
@ -222,6 +225,7 @@ type bytesFileWriteHandle struct {
|
|||||||
|
|
||||||
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("size", len(fh.content)).Send()
|
||||||
if off != int64(len(fh.content)) {
|
if off != int64(len(fh.content)) {
|
||||||
}
|
}
|
||||||
fh.content = append(fh.content[:], data[:]...)
|
fh.content = append(fh.content[:], data[:]...)
|
||||||
@ -230,14 +234,19 @@ 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.Info("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("Flush failed: create").Str("path", fh.path).Err(err).Send()
|
||||||
return syscall.EROFS
|
return syscall.EROFS
|
||||||
}
|
}
|
||||||
nread, err := fp.Write(fh.content)
|
nread, err := fp.Write(fh.content)
|
||||||
if err != nil || nread != len(fh.content) {
|
if err != nil || nread != len(fh.content) {
|
||||||
|
log.Error("Flush failed: write").Str("path", fh.path).Err(err).Send()
|
||||||
|
fp.Close()
|
||||||
return syscall.EROFS
|
return syscall.EROFS
|
||||||
}
|
}
|
||||||
|
log.Info("Flush done").Str("path", fh.path).Int("size", len(fh.content)).Send()
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -248,6 +257,7 @@ func (fh *bytesFileWriteHandle) Fsync(ctx context.Context, flags uint32) (errno
|
|||||||
|
|
||||||
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.Info("getattr").Str("path", bn.path).Send();
|
||||||
out.Ino = bn.Ino
|
out.Ino = bn.Ino
|
||||||
out.Mtime = bn.self.modtime
|
out.Mtime = bn.self.modtime
|
||||||
out.Ctime = bn.self.modtime
|
out.Ctime = bn.self.modtime
|
||||||
@ -258,6 +268,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.Info("setattr").Str("path", bn.path).Send()
|
||||||
out.Size = 0;
|
out.Size = 0;
|
||||||
out.Mtime = 0;
|
out.Mtime = 0;
|
||||||
return 0
|
return 0
|
||||||
@ -269,24 +280,29 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
|||||||
case 2:
|
case 2:
|
||||||
// FS file
|
// FS file
|
||||||
if openFlags&syscall.O_RDWR != 0 {
|
if openFlags&syscall.O_RDWR != 0 {
|
||||||
|
log.Warn("open: failed RDWR").Str("path", f.path).Send()
|
||||||
return nil, 0, syscall.EROFS
|
return nil, 0, syscall.EROFS
|
||||||
}
|
}
|
||||||
|
|
||||||
if openFlags & syscall.O_WRONLY != 0 {
|
if openFlags & syscall.O_WRONLY != 0 {
|
||||||
|
log.Info("Opening file: 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 {
|
||||||
|
log.Info("Opening file: read").Str("path", f.path).Send();
|
||||||
fp, err := myfs.Open(f.path)
|
fp, err := myfs.Open(f.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Error("Opening file failed").Str("path", f.path).Err(err).Send();
|
||||||
return nil, 0, syscall.EROFS
|
return nil, 0, syscall.EROFS
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := make([]byte, f.self.size);
|
buf := make([]byte, f.self.size);
|
||||||
nread, err := fp.Read(buf)
|
nread, err := fp.Read(buf)
|
||||||
if err != nil || nread != int(f.self.size) {
|
if err != nil || nread != int(f.self.size) {
|
||||||
|
log.Error("Reading file failed").Str("path", f.path).Err(err).Send();
|
||||||
return nil, 0, syscall.EROFS
|
return nil, 0, syscall.EROFS
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,6 +362,8 @@ func (f *ITNode) Create(ctx context.Context, name string, flags uint32, mode uin
|
|||||||
content : make([]byte, 0),
|
content : make([]byte, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Info("Creating file").Str("path", path).Send()
|
||||||
|
|
||||||
errno = 0
|
errno = 0
|
||||||
return node, fh, fuseFlags, 0
|
return node, fh, fuseFlags, 0
|
||||||
}
|
}
|
||||||
@ -359,6 +377,10 @@ func (f *ITNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.
|
|||||||
path := f.path + "/" + name
|
path := f.path + "/" + name
|
||||||
err := myfs.Mkdir(path)
|
err := myfs.Mkdir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Info("Mkdir failed").
|
||||||
|
Str("path", path).
|
||||||
|
Err(err).
|
||||||
|
Send()
|
||||||
return nil, syscall.EROFS
|
return nil, syscall.EROFS
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,6 +396,11 @@ func (f *ITNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.
|
|||||||
path : path,
|
path : path,
|
||||||
}
|
}
|
||||||
node := f.NewInode(ctx, operations, stable)
|
node := f.NewInode(ctx, operations, stable)
|
||||||
|
|
||||||
|
log.Info("Mkdir sucess").
|
||||||
|
Str("path", path).
|
||||||
|
Int("ino", int(ino)).
|
||||||
|
Send()
|
||||||
return node, 0
|
return node, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,8 +411,18 @@ func (f *ITNode) Rename(ctx context.Context, name string, newParent fs.InodeEmbe
|
|||||||
|
|
||||||
err := myfs.Rename(p1, p2)
|
err := myfs.Rename(p1, p2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Error("Rename failed").
|
||||||
|
Str("src", p1).
|
||||||
|
Str("dest", p2).
|
||||||
|
Err(err).
|
||||||
|
Send()
|
||||||
|
|
||||||
return syscall.EROFS
|
return syscall.EROFS
|
||||||
}
|
}
|
||||||
|
log.Info("Rename sucess").
|
||||||
|
Str("src", p1).
|
||||||
|
Str("dest", p2).
|
||||||
|
Send()
|
||||||
|
|
||||||
ino := inodemap[p1]
|
ino := inodemap[p1]
|
||||||
delete(inodemap, p1)
|
delete(inodemap, p1)
|
||||||
@ -399,8 +436,18 @@ func (f *ITNode) Unlink(ctx context.Context, name string) syscall.Errno {
|
|||||||
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("Unlink failed").
|
||||||
|
Str("file", f.path + "/" + name).
|
||||||
|
Err(err).
|
||||||
|
Send()
|
||||||
|
|
||||||
return syscall.EROFS
|
return syscall.EROFS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Info("Unlink success").
|
||||||
|
Str("file", f.path + "/" + name).
|
||||||
|
Err(err).
|
||||||
|
Send()
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,10 +468,17 @@ func main() {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Error("Mounting failed").
|
||||||
|
Str("target", mntDir).
|
||||||
|
Err(err).
|
||||||
|
Send()
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
dev := Device{};
|
dev := Device{};
|
||||||
|
log.Info("Mounted on target").
|
||||||
|
Str("target", mntDir).
|
||||||
|
Send()
|
||||||
|
|
||||||
properties[0].f = dev.HeartRateBytes;
|
properties[0].f = dev.HeartRateBytes;
|
||||||
properties[1].f = dev.BatteryLevelBytes;
|
properties[1].f = dev.BatteryLevelBytes;
|
||||||
@ -433,9 +487,6 @@ func main() {
|
|||||||
properties[4].f = dev.VersionBytes;
|
properties[4].f = dev.VersionBytes;
|
||||||
properties[5].f = dev.AddressBytes;
|
properties[5].f = dev.AddressBytes;
|
||||||
|
|
||||||
log.Printf("Mounted on %s", mntDir)
|
|
||||||
log.Printf("Unmount by calling 'fusermount -u %s'", mntDir)
|
|
||||||
|
|
||||||
myfs = &FS{};
|
myfs = &FS{};
|
||||||
inodemap = make(map[string]uint64)
|
inodemap = make(map[string]uint64)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user