Defined ITProperties
This commit is contained in:
parent
b820d6a674
commit
0e0bfdc1f4
41
fuse/main.go
41
fuse/main.go
@ -9,11 +9,25 @@ import (
|
||||
"github.com/hanwen/go-fuse/v2/fuse"
|
||||
)
|
||||
|
||||
type ITProperty struct {
|
||||
name string
|
||||
Ino uint64
|
||||
}
|
||||
|
||||
type ITNode struct {
|
||||
fs.Inode
|
||||
kind int
|
||||
}
|
||||
|
||||
var properties = []ITProperty {
|
||||
ITProperty{"heartrate", 2},
|
||||
ITProperty{"battery", 3},
|
||||
ITProperty{"motion", 4},
|
||||
ITProperty{"stepcount", 5},
|
||||
ITProperty{"version", 6},
|
||||
ITProperty{"address", 7},
|
||||
}
|
||||
|
||||
var _ = (fs.NodeReaddirer)((*ITNode)(nil))
|
||||
|
||||
// Readdir is part of the NodeReaddirer interface
|
||||
@ -33,6 +47,19 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
||||
Mode: fuse.S_IFDIR,
|
||||
}
|
||||
return fs.NewListDirStream(r), 0
|
||||
|
||||
case 1:
|
||||
// device folder
|
||||
r := make([]fuse.DirEntry, 6)
|
||||
for ind, value := range properties {
|
||||
r[ind] = fuse.DirEntry{
|
||||
Name: value.name,
|
||||
Ino: value.Ino,
|
||||
Mode: fuse.S_IFREG,
|
||||
}
|
||||
}
|
||||
|
||||
return fs.NewListDirStream(r), 0
|
||||
}
|
||||
r := make([]fuse.DirEntry, 0)
|
||||
return fs.NewListDirStream(r), 0
|
||||
@ -60,6 +87,20 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
|
||||
child := n.NewInode(ctx, operations, stable)
|
||||
return child, 0
|
||||
}
|
||||
case 1:
|
||||
// device folder
|
||||
for _, value := range properties {
|
||||
if value.name == name {
|
||||
stable := fs.StableAttr{
|
||||
Mode: fuse.S_IFREG,
|
||||
Ino: uint64(value.Ino),
|
||||
}
|
||||
operations := &ITNode{kind: 3}
|
||||
child := n.NewInode(ctx, operations, stable)
|
||||
return child, 0
|
||||
}
|
||||
}
|
||||
return nil, syscall.ENOENT
|
||||
}
|
||||
return nil, syscall.ENOENT
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user