I play using FUSE with Go. However, I was faced with how to deal with struct fuse_operations. I cannot imagine the structure of operations by declaring type Operations C.struct_fuse_operationssince members are lower case, and my pure Go sources should use C-hackery to set members anyway. My first mistake in this case is โcannot install getattrโ in what looks like Go equivalent to the default copy constructor. My next attempt is to expose an interface that expects GetAttr, ReadLinketc., and then generate C.struct_fuse_operationsand bind pointers to locks that invoke that interface.
This is what I have (explanation continues after the code):
package fuse
import "C"
import (
"os"
"unsafe"
)
type Operations interface {
GetAttr(string, *os.FileInfo) int
}
func Main(args []string, ops Operations) int {
argv := make([]*C.char, len(args) + 1)
for i, s := range args {
p := C.CString(s)
defer C.free(unsafe.Pointer(p))
argv[i] = p
}
cop := new(C.struct_fuse_operations)
cop.getattr = func(*C.char, *C.struct_stat) int {}
argc := C.int(len(args))
return int(C.fuse_main_real(argc, &argv[0], cop, C.size_t(unsafe.Sizeof(cop)), nil))
}
package main
import (
"fmt"
"fuse"
"os"
)
type CpfsOps struct {
a int
}
func (me *CpfsOps) GetAttr(string, *os.FileInfo) int {
return -1;
}
func main() {
fmt.Println(os.Args)
ops := &CpfsOps{}
fmt.Println("fuse main returned", fuse.Main(os.Args, ops))
}
This results in the following error:
fuse.go:21[fuse.cgo1.go:23]: cannot use func literal (type func(*_Ctype_char, *_Ctype_struct_stat) int) as type *[0]uint8 in assignment
, C.struct_fuse_operations, , C Go.
, ? , , C.struct_fuse_operations NULL?