Initial commit
This commit is contained in:
117
main.go
Normal file
117
main.go
Normal file
@@ -0,0 +1,117 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"fusetest/ffs"
|
||||
"fusetest/furcadia"
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"bazil.org/fuse"
|
||||
"bazil.org/fuse/fs"
|
||||
)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// TYPE: File /////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
type File struct {
|
||||
mu sync.Mutex
|
||||
name string
|
||||
data []byte
|
||||
}
|
||||
|
||||
func (f *File) Access(ctx context.Context, req *fuse.AccessRequest) error {
|
||||
fmt.Printf("[D] File[%v].Attr() <- %v\n", f.name, req.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *File) Attr(ctx context.Context, a *fuse.Attr) error {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
|
||||
a.Inode = 12345
|
||||
a.Mode = 0755
|
||||
a.Size = uint64(len(f.data))
|
||||
a.Gid = 999
|
||||
a.Uid = 999
|
||||
a.Atime = time.Now()
|
||||
a.Mtime = time.Now()
|
||||
fmt.Printf("[D] File[%v].Attr() <- %v\n", f.name, a.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *File) ReadAll(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) ([]byte, error) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
fmt.Printf("[D] File[%v].ReadAll(%v) <- %v\n", f.name, req.String(), resp.String())
|
||||
return append([]byte(nil), f.data...), nil
|
||||
}
|
||||
|
||||
func (f *File) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
|
||||
end := int(req.Offset) + len(req.Data)
|
||||
if end > len(f.data) {
|
||||
newData := make([]byte, end)
|
||||
copy(newData, f.data)
|
||||
f.data = newData
|
||||
}
|
||||
copy(f.data[req.Offset:], req.Data)
|
||||
resp.Size = len(req.Data)
|
||||
|
||||
fmt.Printf("[D] File[%v].Write(%v) <- %v\n", f.name, req.String(), resp.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) {
|
||||
fmt.Printf("[D] File[%v].Open(%v) <- %v\n", f.name, req.String(), resp.String())
|
||||
return f, nil
|
||||
}
|
||||
|
||||
func (f *File) Release(ctx context.Context, req *fuse.ReleaseRequest) error {
|
||||
fmt.Printf("[D] File[%v].Release(%v)\n", f.name, req.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *File) Forget() {
|
||||
fmt.Printf("[D] File[%v].Forget()\n", f.name)
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 2 {
|
||||
fmt.Printf("Usage: %v <mountpoint>\n", os.Args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
mountpoint := os.Args[1]
|
||||
|
||||
c, err := fuse.Mount(
|
||||
mountpoint,
|
||||
fuse.FSName("rawrfs"),
|
||||
fuse.Subtype("rawrfs"),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer fuse.Unmount(mountpoint)
|
||||
defer c.Close()
|
||||
|
||||
uid := uint32(os.Getuid())
|
||||
gid := uint32(os.Getgid())
|
||||
|
||||
pounce := furcadia.NewPounceList()
|
||||
pounce.AddDream("Artex", "Some dream name")
|
||||
pounce.AddDream("Ice Dragon", "")
|
||||
pounce.AddDream("Albert Quirky", "Welcome!")
|
||||
|
||||
pfs := ffs.InitFS(uid, gid, pounce)
|
||||
if err := fs.Serve(c, pfs); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user