62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package ffs
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"syscall"
|
|
|
|
"bazil.org/fuse"
|
|
"bazil.org/fuse/fs"
|
|
)
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// CONSTANTS //////////////////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
const ROOT_INODE = 1
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// TYPE: RootDir //////////////////////////////////////////////////////////////////////////////////
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
type RootDir struct {
|
|
_attr fuse.Attr
|
|
_nodes map[string]TopLevelDir
|
|
}
|
|
|
|
func (d *RootDir) Attr(ctx context.Context, a *fuse.Attr) error {
|
|
*a = d._attr
|
|
return nil
|
|
}
|
|
|
|
func (d *RootDir) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
|
if name == "." {
|
|
return d, nil
|
|
}
|
|
|
|
node, exists := d._nodes[name]
|
|
if exists {
|
|
fmt.Printf("[D] RootDir.Lookup('%v'): OK\n", name)
|
|
return node, nil
|
|
}
|
|
|
|
fmt.Printf("[D] RootDir.Lookup('%v'): ENOENT\n", name)
|
|
return nil, syscall.ENOENT
|
|
}
|
|
|
|
func (d *RootDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
|
fmt.Printf("[D] RootDir.ReadDirAll()\n")
|
|
items := make([]fuse.Dirent, len(d._nodes))
|
|
i := 0
|
|
for name, node := range d._nodes {
|
|
items[i] = fuse.Dirent{
|
|
Inode: node.GetAttr().Inode,
|
|
Name: name,
|
|
Type: fuse.DT_Dir,
|
|
}
|
|
i++
|
|
}
|
|
|
|
return items, nil
|
|
}
|