From 0e0bfdc1f4619270476a51479aed207a1f4538d3 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sun, 19 Feb 2023 12:08:56 +0000 Subject: [PATCH] Defined ITProperties --- fuse/main.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/fuse/main.go b/fuse/main.go index 371acd9..7d45c6e 100644 --- a/fuse/main.go +++ b/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 }