Initial commit
This commit is contained in:
133
ffs/furresdir.go
Normal file
133
ffs/furresdir.go
Normal file
@@ -0,0 +1,133 @@
|
||||
package ffs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"fusetest/furcadia"
|
||||
"os"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"bazil.org/fuse"
|
||||
"bazil.org/fuse/fs"
|
||||
)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// CONSTANTS //////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const (
|
||||
FURRES_DIR_INODE_BASE = 0x1000
|
||||
FURRES_DIR_MAX_INODES = 0x1000
|
||||
)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// TYPE: DreamsDir ////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
type FurresDir struct {
|
||||
_attr fuse.Attr
|
||||
_entries []fuse.Dirent
|
||||
_index map[string]int
|
||||
}
|
||||
|
||||
func NewFurresDir(inodeBase uint64, rootUID, rootGID uint32) *FurresDir {
|
||||
now := time.Now()
|
||||
dir := &FurresDir{
|
||||
_attr: fuse.Attr{
|
||||
Inode: inodeBase,
|
||||
Nlink: 1,
|
||||
Mode: os.ModeDir | 0500,
|
||||
Uid: rootUID,
|
||||
Gid: rootGID,
|
||||
Atime: now,
|
||||
Ctime: now,
|
||||
Mtime: now,
|
||||
},
|
||||
_index: make(map[string]int),
|
||||
}
|
||||
|
||||
// add basic entries
|
||||
dir._entries = append(
|
||||
dir._entries,
|
||||
fuse.Dirent{Inode: dir._attr.Inode, Name: ".", Type: fuse.DT_Dir},
|
||||
fuse.Dirent{Inode: ROOT_INODE, Name: "..", Type: fuse.DT_Dir},
|
||||
)
|
||||
|
||||
// add basic entries to the index
|
||||
for i := range dir._entries {
|
||||
dirent := &dir._entries[i]
|
||||
dir._index[dirent.Name] = i
|
||||
}
|
||||
|
||||
return dir
|
||||
}
|
||||
|
||||
func (d *FurresDir) GetAttr() *fuse.Attr {
|
||||
return &d._attr
|
||||
}
|
||||
|
||||
func (d *FurresDir) Attr(ctx context.Context, a *fuse.Attr) error {
|
||||
*a = d._attr
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *FurresDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
|
||||
return d._entries, nil
|
||||
// pounce := G_FS._pounce
|
||||
// furres := pounce.Furres
|
||||
// items := make([]fuse.Dirent, len(furres)+2)
|
||||
|
||||
// items[0] = fuse.Dirent{Inode: d._attr.Inode, Name: ".", Type: fuse.DT_Dir}
|
||||
// items[1] = fuse.Dirent{Inode: ROOT_INODE, Name: "..", Type: fuse.DT_Dir}
|
||||
|
||||
// var i uint64 = 2
|
||||
// for _, furre := range furres {
|
||||
// items[i] = fuse.Dirent{
|
||||
// Inode: d._attr.Inode + i - 1,
|
||||
// Name: furre.DisplayName,
|
||||
// Type: fuse.DT_File,
|
||||
// }
|
||||
// i++
|
||||
// }
|
||||
|
||||
// return items, nil
|
||||
}
|
||||
|
||||
func (d *FurresDir) Lookup(ctx context.Context, name string) (fs.Node, error) {
|
||||
if name == "." {
|
||||
return d, nil
|
||||
}
|
||||
|
||||
// find dirent for the given name
|
||||
|
||||
direntIndex, exists = d._index[name]
|
||||
if !exists {
|
||||
return nil, syscall.ENOENT
|
||||
}
|
||||
|
||||
furres := G_FS._pounce.Furres
|
||||
shortname := furcadia.GetShortName(name)
|
||||
furre, exists := furres[shortname]
|
||||
if !exists {
|
||||
fmt.Printf("[F] FurresDir().Lookup('%v' -> %v): ENOENT\n", name, shortname)
|
||||
return nil, syscall.ENOENT
|
||||
}
|
||||
|
||||
fmt.Printf("[F] FurresDir().Lookup('%v'): OK\n", name)
|
||||
now := time.Now()
|
||||
return &FurreFile{
|
||||
Furre: furre,
|
||||
_attr: fuse.Attr{
|
||||
Inode: 0,
|
||||
Nlink: 1,
|
||||
Mode: 0400,
|
||||
Size: 0,
|
||||
Ctime: now,
|
||||
Atime: now,
|
||||
Mtime: now,
|
||||
Uid: d._attr.Uid,
|
||||
Gid: d._attr.Gid,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user